mirror of
https://github.com/docmost/docmost.git
synced 2026-08-21 11:31:05 +08:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d5f7bf4d4 | ||
|
|
ab43031375 | ||
|
|
8c2c49ea6d | ||
|
|
8913d20aa0 | ||
|
|
232beda471 |
@@ -4,7 +4,7 @@
|
||||
"version": "0.95.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"build": "tsc && vite build && node scripts/compress-dist.mjs",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"format": "prettier --write \"src/**/*.tsx\" \"src/**/*.ts\"",
|
||||
@@ -52,7 +52,7 @@
|
||||
"mantine-form-zod-resolver": "1.3.0",
|
||||
"mermaid": "11.16.1",
|
||||
"mitt": "3.0.1",
|
||||
"nanoid": "3.3.17",
|
||||
"nanoid": "3.3.18",
|
||||
"posthog-js": "1.391.2",
|
||||
"react": "19.2.7",
|
||||
"react-clear-modal": "^2.0.18",
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { promises as fs } from "node:fs";
|
||||
import { join, extname } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
const gzip = promisify(zlib.gzip);
|
||||
const brotli = promisify(zlib.brotliCompress);
|
||||
|
||||
const DIST = new URL("../dist", import.meta.url).pathname;
|
||||
// index.html is rewritten by the server at boot, so html must not be precompressed
|
||||
const COMPRESSIBLE = new Set([".js", ".css", ".svg", ".json", ".txt", ".map"]);
|
||||
const MIN_SIZE = 1024;
|
||||
|
||||
async function* walk(dir) {
|
||||
for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
|
||||
const path = join(dir, entry.name);
|
||||
if (entry.isDirectory()) yield* walk(path);
|
||||
else yield path;
|
||||
}
|
||||
}
|
||||
|
||||
const files = [];
|
||||
for await (const file of walk(DIST)) {
|
||||
if (!COMPRESSIBLE.has(extname(file))) continue;
|
||||
const { size } = await fs.stat(file);
|
||||
if (size >= MIN_SIZE) files.push(file);
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const content = await fs.readFile(file);
|
||||
const [gz, br] = await Promise.all([
|
||||
gzip(content, { level: 9 }),
|
||||
brotli(content, {
|
||||
params: {
|
||||
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
|
||||
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: content.length,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
await Promise.all([
|
||||
fs.writeFile(`${file}.gz`, gz),
|
||||
fs.writeFile(`${file}.br`, br),
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
console.log(`precompressed ${files.length} assets (.gz/.br)`);
|
||||
+77
-45
@@ -1,60 +1,92 @@
|
||||
import { lazy, Suspense, useEffect } from "react";
|
||||
import { Navigate, Route, Routes } from "react-router-dom";
|
||||
import SetupWorkspace from "@/pages/auth/setup-workspace.tsx";
|
||||
import LoginPage from "@/pages/auth/login";
|
||||
import Home from "@/pages/dashboard/home";
|
||||
import Page from "@/pages/page/page";
|
||||
import AccountSettings from "@/pages/settings/account/account-settings";
|
||||
import WorkspaceMembers from "@/pages/settings/workspace/workspace-members";
|
||||
import WorkspaceSettings from "@/pages/settings/workspace/workspace-settings";
|
||||
import Groups from "@/pages/settings/group/groups";
|
||||
import GroupInfo from "./pages/settings/group/group-info";
|
||||
import Spaces from "@/pages/settings/space/spaces.tsx";
|
||||
import { Error404 } from "@/components/ui/error-404.tsx";
|
||||
import AccountPreferences from "@/pages/settings/account/account-preferences.tsx";
|
||||
import SpaceHome from "@/pages/space/space-home.tsx";
|
||||
import PageRedirect from "@/pages/page/page-redirect.tsx";
|
||||
import Layout from "@/components/layouts/global/layout.tsx";
|
||||
import InviteSignup from "@/pages/auth/invite-signup.tsx";
|
||||
import ForgotPassword from "@/pages/auth/forgot-password.tsx";
|
||||
import PasswordReset from "./pages/auth/password-reset";
|
||||
import Billing from "@/ee/billing/pages/billing.tsx";
|
||||
import CloudLogin from "@/ee/pages/cloud-login.tsx";
|
||||
import CreateWorkspace from "@/ee/pages/create-workspace.tsx";
|
||||
import { Error404 } from "@/components/ui/error-404.tsx";
|
||||
import { isCloud } from "@/lib/config.ts";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Security from "@/ee/security/pages/security.tsx";
|
||||
import License from "@/ee/licence/pages/license.tsx";
|
||||
import { useRedirectToCloudSelect } from "@/ee/hooks/use-redirect-to-cloud-select.tsx";
|
||||
import SharedPage from "@/pages/share/shared-page.tsx";
|
||||
import PdfRenderPage from "@/ee/pdf-export/pdf-render-page.tsx";
|
||||
import Shares from "@/pages/settings/shares/shares.tsx";
|
||||
import ShareLayout from "@/features/share/components/share-layout.tsx";
|
||||
import ShareRedirect from "@/pages/share/share-redirect.tsx";
|
||||
import { useTrackOrigin } from "@/hooks/use-track-origin";
|
||||
import SpacesPage from "@/pages/spaces/spaces.tsx";
|
||||
import { MfaChallengePage } from "@/ee/mfa/pages/mfa-challenge-page";
|
||||
import { MfaSetupRequiredPage } from "@/ee/mfa/pages/mfa-setup-required-page";
|
||||
import SpaceTrash from "@/pages/space/space-trash.tsx";
|
||||
import UserApiKeys from "@/ee/api-key/pages/user-api-keys";
|
||||
import WorkspaceApiKeys from "@/ee/api-key/pages/workspace-api-keys";
|
||||
import AiSettings from "@/ee/ai/pages/ai-settings.tsx";
|
||||
import BasePage from "@/ee/base/pages/base-page.tsx";
|
||||
import AuditLogs from "@/ee/audit/pages/audit-logs.tsx";
|
||||
import VerifiedPages from "@/ee/page-verification/pages/verified-pages.tsx";
|
||||
import TemplateList from "@/ee/template/pages/template-list";
|
||||
import TemplateEditor from "@/ee/template/pages/template-editor";
|
||||
import FavoritesPage from "@/pages/favorites/favorites-page";
|
||||
import AiChat from "@/ee/ai-chat/pages/ai-chat.tsx";
|
||||
import VerifyEmail from "@/ee/pages/verify-email.tsx";
|
||||
import LabelPage from "@/pages/label/label-page";
|
||||
|
||||
const SetupWorkspace = lazy(() => import("@/pages/auth/setup-workspace.tsx"));
|
||||
const LoginPage = lazy(() => import("@/pages/auth/login"));
|
||||
const Home = lazy(() => import("@/pages/dashboard/home"));
|
||||
const Page = lazy(() => import("@/pages/page/page"));
|
||||
const AccountSettings = lazy(
|
||||
() => import("@/pages/settings/account/account-settings"),
|
||||
);
|
||||
const WorkspaceMembers = lazy(
|
||||
() => import("@/pages/settings/workspace/workspace-members"),
|
||||
);
|
||||
const WorkspaceSettings = lazy(
|
||||
() => import("@/pages/settings/workspace/workspace-settings"),
|
||||
);
|
||||
const Groups = lazy(() => import("@/pages/settings/group/groups"));
|
||||
const GroupInfo = lazy(() => import("./pages/settings/group/group-info"));
|
||||
const Spaces = lazy(() => import("@/pages/settings/space/spaces.tsx"));
|
||||
const AccountPreferences = lazy(
|
||||
() => import("@/pages/settings/account/account-preferences.tsx"),
|
||||
);
|
||||
const SpaceHome = lazy(() => import("@/pages/space/space-home.tsx"));
|
||||
const PageRedirect = lazy(() => import("@/pages/page/page-redirect.tsx"));
|
||||
const InviteSignup = lazy(() => import("@/pages/auth/invite-signup.tsx"));
|
||||
const ForgotPassword = lazy(() => import("@/pages/auth/forgot-password.tsx"));
|
||||
const PasswordReset = lazy(() => import("./pages/auth/password-reset"));
|
||||
const Billing = lazy(() => import("@/ee/billing/pages/billing.tsx"));
|
||||
const CloudLogin = lazy(() => import("@/ee/pages/cloud-login.tsx"));
|
||||
const CreateWorkspace = lazy(() => import("@/ee/pages/create-workspace.tsx"));
|
||||
const Security = lazy(() => import("@/ee/security/pages/security.tsx"));
|
||||
const License = lazy(() => import("@/ee/licence/pages/license.tsx"));
|
||||
const SharedPage = lazy(() => import("@/pages/share/shared-page.tsx"));
|
||||
const PdfRenderPage = lazy(() => import("@/ee/pdf-export/pdf-render-page.tsx"));
|
||||
const Shares = lazy(() => import("@/pages/settings/shares/shares.tsx"));
|
||||
const ShareLayout = lazy(
|
||||
() => import("@/features/share/components/share-layout.tsx"),
|
||||
);
|
||||
const ShareRedirect = lazy(() => import("@/pages/share/share-redirect.tsx"));
|
||||
const SpacesPage = lazy(() => import("@/pages/spaces/spaces.tsx"));
|
||||
const MfaChallengePage = lazy(() =>
|
||||
import("@/ee/mfa/pages/mfa-challenge-page").then((m) => ({
|
||||
default: m.MfaChallengePage,
|
||||
})),
|
||||
);
|
||||
const MfaSetupRequiredPage = lazy(() =>
|
||||
import("@/ee/mfa/pages/mfa-setup-required-page").then((m) => ({
|
||||
default: m.MfaSetupRequiredPage,
|
||||
})),
|
||||
);
|
||||
const SpaceTrash = lazy(() => import("@/pages/space/space-trash.tsx"));
|
||||
const UserApiKeys = lazy(() => import("@/ee/api-key/pages/user-api-keys"));
|
||||
const WorkspaceApiKeys = lazy(
|
||||
() => import("@/ee/api-key/pages/workspace-api-keys"),
|
||||
);
|
||||
const AiSettings = lazy(() => import("@/ee/ai/pages/ai-settings.tsx"));
|
||||
const BasePage = lazy(() => import("@/ee/base/pages/base-page.tsx"));
|
||||
const AuditLogs = lazy(() => import("@/ee/audit/pages/audit-logs.tsx"));
|
||||
const VerifiedPages = lazy(
|
||||
() => import("@/ee/page-verification/pages/verified-pages.tsx"),
|
||||
);
|
||||
const TemplateList = lazy(() => import("@/ee/template/pages/template-list"));
|
||||
const TemplateEditor = lazy(
|
||||
() => import("@/ee/template/pages/template-editor"),
|
||||
);
|
||||
const FavoritesPage = lazy(() => import("@/pages/favorites/favorites-page"));
|
||||
const AiChat = lazy(() => import("@/ee/ai-chat/pages/ai-chat.tsx"));
|
||||
const VerifyEmail = lazy(() => import("@/ee/pages/verify-email.tsx"));
|
||||
const LabelPage = lazy(() => import("@/pages/label/label-page"));
|
||||
|
||||
export default function App() {
|
||||
const { t } = useTranslation();
|
||||
useRedirectToCloudSelect();
|
||||
useTrackOrigin();
|
||||
|
||||
useEffect(() => {
|
||||
// warm the editor chunk so opening a page doesn't wait on the network
|
||||
const timer = setTimeout(() => import("@/pages/page/page"), 3000);
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Suspense fallback={null}>
|
||||
<Routes>
|
||||
<Route index element={<Navigate to="/home" />} />
|
||||
<Route path={"/login"} element={<LoginPage />} />
|
||||
@@ -135,6 +167,6 @@ export default function App() {
|
||||
|
||||
<Route path="*" element={<Error404 />} />
|
||||
</Routes>
|
||||
</>
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
import { ActionIcon, Box, Group, ScrollArea, Title, Tooltip } from "@mantine/core";
|
||||
import { IconX } from "@tabler/icons-react";
|
||||
import CommentListWithTabs from "@/features/comment/components/comment-list-with-tabs.tsx";
|
||||
import { useAtom } from "jotai";
|
||||
import { asideStateAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts";
|
||||
import React, { ReactNode, useEffect } from "react";
|
||||
import React, { lazy, ReactNode, Suspense, useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { TableOfContents } from "@/features/editor/components/table-of-contents/table-of-contents.tsx";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { pageEditorAtom } from "@/features/editor/atoms/editor-atoms.ts";
|
||||
import AsideChatPanel from "@/ee/ai-chat/components/aside-chat-panel";
|
||||
import { PageDetailsAside } from "@/features/page-details/components/page-details-aside.tsx";
|
||||
import { ASIDE_PANEL_ID } from "@/hooks/use-toggle-aside.tsx";
|
||||
|
||||
const CommentListWithTabs = lazy(
|
||||
() => import("@/features/comment/components/comment-list-with-tabs.tsx"),
|
||||
);
|
||||
const TableOfContents = lazy(() =>
|
||||
import(
|
||||
"@/features/editor/components/table-of-contents/table-of-contents.tsx"
|
||||
).then((m) => ({ default: m.TableOfContents })),
|
||||
);
|
||||
const AsideChatPanel = lazy(
|
||||
() => import("@/ee/ai-chat/components/aside-chat-panel"),
|
||||
);
|
||||
const PageDetailsAside = lazy(() =>
|
||||
import("@/features/page-details/components/page-details-aside.tsx").then(
|
||||
(m) => ({ default: m.PageDetailsAside }),
|
||||
),
|
||||
);
|
||||
|
||||
export default function Aside() {
|
||||
const [{ tab, isAsideOpen }, setAsideState] = useAtom(asideStateAtom);
|
||||
const { t } = useTranslation();
|
||||
@@ -68,17 +81,19 @@ export default function Aside() {
|
||||
</Group>
|
||||
)}
|
||||
|
||||
{tab === "comments" || tab === "chat" ? (
|
||||
component
|
||||
) : (
|
||||
<ScrollArea
|
||||
style={{ height: "85vh" }}
|
||||
scrollbarSize={5}
|
||||
type="scroll"
|
||||
>
|
||||
<div style={{ paddingBottom: "200px" }}>{component}</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
<Suspense fallback={null}>
|
||||
{tab === "comments" || tab === "chat" ? (
|
||||
component
|
||||
) : (
|
||||
<ScrollArea
|
||||
style={{ height: "85vh" }}
|
||||
scrollbarSize={5}
|
||||
type="scroll"
|
||||
>
|
||||
<div style={{ paddingBottom: "200px" }}>{component}</div>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</Suspense>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
@@ -11,7 +11,10 @@ import {
|
||||
sidebarWidthAtom,
|
||||
} from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts";
|
||||
import { SpaceSidebar } from "@/features/space/components/sidebar/space-sidebar.tsx";
|
||||
import AiChatSidebar from "@/ee/ai-chat/components/ai-chat-sidebar.tsx";
|
||||
|
||||
const AiChatSidebar = React.lazy(
|
||||
() => import("@/ee/ai-chat/components/ai-chat-sidebar.tsx"),
|
||||
);
|
||||
import { AppHeader } from "@/components/layouts/global/app-header.tsx";
|
||||
import Aside from "@/components/layouts/global/aside.tsx";
|
||||
import classes from "./app-shell.module.css";
|
||||
@@ -126,7 +129,11 @@ export default function GlobalAppShell({
|
||||
)}
|
||||
{isSpaceRoute && <SpaceSidebar />}
|
||||
{isSettingsRoute && <SettingsSidebar />}
|
||||
{isAiRoute && <AiChatSidebar />}
|
||||
{isAiRoute && (
|
||||
<React.Suspense fallback={null}>
|
||||
<AiChatSidebar />
|
||||
</React.Suspense>
|
||||
)}
|
||||
{showGlobalSidebar && <GlobalSidebar />}
|
||||
</AppShell.Navbar>
|
||||
<AppShell.Main id={MAIN_CONTENT_ID} tabIndex={-1}>
|
||||
|
||||
@@ -54,7 +54,9 @@ import {
|
||||
import { mobileSidebarAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts";
|
||||
import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts";
|
||||
import { searchSpotlight } from "@/features/search/constants";
|
||||
import TemplatePickerModal from "@/ee/template/components/template-picker-modal";
|
||||
const TemplatePickerModal = React.lazy(
|
||||
() => import("@/ee/template/components/template-picker-modal"),
|
||||
);
|
||||
import { useHasFeature } from "@/ee/hooks/use-feature";
|
||||
import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label";
|
||||
import { Feature } from "@/ee/features";
|
||||
@@ -406,11 +408,13 @@ function SpaceMenu({
|
||||
|
||||
{hasTemplates && templatePickerOpened && (
|
||||
<ErrorBoundary fallbackRender={() => null}>
|
||||
<TemplatePickerModal
|
||||
opened={templatePickerOpened}
|
||||
onClose={closeTemplatePicker}
|
||||
initialSpaceId={spaceId}
|
||||
/>
|
||||
<React.Suspense fallback={null}>
|
||||
<TemplatePickerModal
|
||||
opened={templatePickerOpened}
|
||||
onClose={closeTemplatePicker}
|
||||
initialSpaceId={spaceId}
|
||||
/>
|
||||
</React.Suspense>
|
||||
</ErrorBoundary>
|
||||
)}
|
||||
</>
|
||||
|
||||
+10
-10
@@ -40,30 +40,30 @@
|
||||
"@clickhouse/client": "1.18.2",
|
||||
"@docmost/base-formula": "workspace:*",
|
||||
"@docmost/pdf-inspector": "1.9.6",
|
||||
"@fastify/cookie": "11.0.2",
|
||||
"@fastify/multipart": "10.0.0",
|
||||
"@fastify/static": "10.1.2",
|
||||
"@fastify/cookie": "11.1.2",
|
||||
"@fastify/multipart": "10.1.1",
|
||||
"@fastify/static": "10.1.3",
|
||||
"@keyv/redis": "5.1.6",
|
||||
"@langchain/core": "1.1.46",
|
||||
"@langchain/textsplitters": "1.0.1",
|
||||
"@modelcontextprotocol/sdk": "1.30.0",
|
||||
"@nest-lab/throttler-storage-redis": "1.2.0",
|
||||
"@nestjs-labs/nestjs-ioredis": "11.0.4",
|
||||
"@nestjs/bullmq": "11.0.4",
|
||||
"@nestjs/bullmq": "11.0.5",
|
||||
"@nestjs/cache-manager": "3.1.3",
|
||||
"@nestjs/common": "11.1.28",
|
||||
"@nestjs/common": "11.2.1",
|
||||
"@nestjs/config": "4.0.4",
|
||||
"@nestjs/core": "11.1.27",
|
||||
"@nestjs/core": "11.2.1",
|
||||
"@nestjs/event-emitter": "3.1.0",
|
||||
"@nestjs/jwt": "11.0.2",
|
||||
"@nestjs/mapped-types": "2.1.1",
|
||||
"@nestjs/passport": "11.0.5",
|
||||
"@nestjs/platform-fastify": "11.1.28",
|
||||
"@nestjs/platform-socket.io": "11.1.28",
|
||||
"@nestjs/platform-fastify": "11.2.1",
|
||||
"@nestjs/platform-socket.io": "11.2.1",
|
||||
"@nestjs/schedule": "6.1.3",
|
||||
"@nestjs/terminus": "11.1.1",
|
||||
"@nestjs/throttler": "6.5.0",
|
||||
"@nestjs/websockets": "11.1.28",
|
||||
"@nestjs/websockets": "11.2.1",
|
||||
"@node-saml/passport-saml": "5.1.0",
|
||||
"@socket.io/redis-adapter": "8.3.0",
|
||||
"@turbopuffer/turbopuffer": "^2.8.0",
|
||||
@@ -120,7 +120,7 @@
|
||||
"tmp-promise": "3.0.3",
|
||||
"typesense": "3.0.5",
|
||||
"undici": "7.29.0",
|
||||
"ws": "8.21.0",
|
||||
"ws": "8.21.3",
|
||||
"yauzl": "3.4.0",
|
||||
"zod": "4.3.6"
|
||||
},
|
||||
|
||||
@@ -22,7 +22,8 @@ import { TelemetryModule } from './integrations/telemetry/telemetry.module';
|
||||
import { RedisModule } from '@nestjs-labs/nestjs-ioredis';
|
||||
import { RedisConfigService } from './integrations/redis/redis-config.service';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import KeyvRedis from '@keyv/redis';
|
||||
import KeyvRedis, { defaultReconnectStrategy } from '@keyv/redis';
|
||||
import { parseRedisUrl } from './common/helpers';
|
||||
import { LoggerModule } from './common/logger/logger.module';
|
||||
import { ClsModule } from 'nestjs-cls';
|
||||
import { NoopAuditModule } from './integrations/audit/audit.module';
|
||||
@@ -62,10 +63,20 @@ try {
|
||||
isGlobal: true,
|
||||
useFactory: async (environmentService: EnvironmentService) => {
|
||||
const redisUrl = environmentService.getRedisUrl();
|
||||
const { family, tls } = parseRedisUrl(redisUrl);
|
||||
|
||||
return {
|
||||
ttl: 5 * 1000,
|
||||
stores: [new KeyvRedis(redisUrl)],
|
||||
stores: [
|
||||
new KeyvRedis({
|
||||
url: redisUrl,
|
||||
socket: {
|
||||
family,
|
||||
reconnectStrategy: defaultReconnectStrategy,
|
||||
...tls,
|
||||
},
|
||||
}),
|
||||
],
|
||||
};
|
||||
},
|
||||
inject: [EnvironmentService],
|
||||
|
||||
@@ -66,6 +66,7 @@ export class CollaborationGateway {
|
||||
password: this.redisConfig.password,
|
||||
db: this.redisConfig.db,
|
||||
family: this.redisConfig.family,
|
||||
tls: this.redisConfig.tls,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
}),
|
||||
serverId: `collab-${os?.hostname()}-${nanoid(10)}`,
|
||||
|
||||
@@ -30,13 +30,14 @@ export type RedisConfig = {
|
||||
db: number;
|
||||
password?: string;
|
||||
family?: number;
|
||||
tls?: { rejectUnauthorized?: boolean };
|
||||
};
|
||||
|
||||
export function parseRedisUrl(redisUrl: string): RedisConfig {
|
||||
// format - redis[s]://[[username][:password]@][host][:port][/db-number][?family=4|6]
|
||||
// format - redis[s]://[[username][:password]@][host][:port][/db-number][?family=4|6][&rejectUnauthorized=false]
|
||||
const url = new URL(redisUrl);
|
||||
const { hostname, port, password, pathname, searchParams } = url;
|
||||
const portInt = parseInt(port, 10);
|
||||
const { hostname, port, password, pathname, protocol, searchParams } = url;
|
||||
const portInt = port ? parseInt(port, 10) : 6379;
|
||||
|
||||
let db: number = 0;
|
||||
// extract db value if present
|
||||
@@ -54,7 +55,14 @@ export function parseRedisUrl(redisUrl: string): RedisConfig {
|
||||
family = parseInt(familyParam, 10);
|
||||
}
|
||||
|
||||
return { host: hostname, port: portInt, password, db, family };
|
||||
const tls =
|
||||
protocol === 'rediss:'
|
||||
? searchParams.get('rejectUnauthorized') === 'false'
|
||||
? { rejectUnauthorized: false }
|
||||
: {}
|
||||
: undefined;
|
||||
|
||||
return { host: hostname, port: portInt, password: password || undefined, db, family, tls };
|
||||
}
|
||||
|
||||
export function createRetryStrategy() {
|
||||
|
||||
@@ -339,15 +339,25 @@ export class SpaceMemberService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spaceMember.role === SpaceRole.ADMIN) {
|
||||
await this.validateLastAdmin(dto.spaceId);
|
||||
}
|
||||
await executeTx(this.db, async (trx) => {
|
||||
await trx
|
||||
.selectFrom('spaces')
|
||||
.select('id')
|
||||
.where('id', '=', dto.spaceId)
|
||||
.forUpdate()
|
||||
.executeTakeFirst();
|
||||
|
||||
await this.spaceMemberRepo.updateSpaceMember(
|
||||
{ role: dto.role },
|
||||
spaceMember.id,
|
||||
dto.spaceId,
|
||||
);
|
||||
if (spaceMember.role === SpaceRole.ADMIN) {
|
||||
await this.validateLastAdmin(dto.spaceId, trx);
|
||||
}
|
||||
|
||||
await this.spaceMemberRepo.updateSpaceMember(
|
||||
{ role: dto.role },
|
||||
spaceMember.id,
|
||||
dto.spaceId,
|
||||
trx,
|
||||
);
|
||||
});
|
||||
|
||||
this.auditService.log({
|
||||
event: AuditEvent.SPACE_MEMBER_ROLE_CHANGED,
|
||||
@@ -368,10 +378,14 @@ export class SpaceMemberService {
|
||||
});
|
||||
}
|
||||
|
||||
async validateLastAdmin(spaceId: string): Promise<void> {
|
||||
async validateLastAdmin(
|
||||
spaceId: string,
|
||||
trx?: KyselyTransaction,
|
||||
): Promise<void> {
|
||||
const spaceOwnerCount = await this.spaceMemberRepo.roleCountBySpaceId(
|
||||
SpaceRole.ADMIN,
|
||||
spaceId,
|
||||
trx,
|
||||
);
|
||||
if (spaceOwnerCount === 1) {
|
||||
throw new BadRequestException(
|
||||
|
||||
@@ -46,8 +46,10 @@ export class SpaceMemberRepo {
|
||||
updatableSpaceMember: UpdatableSpaceMember,
|
||||
spaceMemberId: string,
|
||||
spaceId: string,
|
||||
trx?: KyselyTransaction,
|
||||
): Promise<void> {
|
||||
await this.db
|
||||
const db = dbOrTx(this.db, trx);
|
||||
await db
|
||||
.updateTable('spaceMembers')
|
||||
.set(updatableSpaceMember)
|
||||
.where('id', '=', spaceMemberId)
|
||||
@@ -92,8 +94,13 @@ export class SpaceMemberRepo {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async roleCountBySpaceId(role: string, spaceId: string): Promise<number> {
|
||||
const { count } = await this.db
|
||||
async roleCountBySpaceId(
|
||||
role: string,
|
||||
spaceId: string,
|
||||
trx?: KyselyTransaction,
|
||||
): Promise<number> {
|
||||
const db = dbOrTx(this.db, trx);
|
||||
const { count } = await db
|
||||
.selectFrom('spaceMembers')
|
||||
.select((eb) => eb.fn.count('role').as('count'))
|
||||
.where('role', '=', role)
|
||||
|
||||
+1
-1
Submodule apps/server/src/ee updated: 660418ac2c...e13af0ce05
@@ -5,6 +5,7 @@ import {
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { EnvironmentService } from '../environment/environment.service';
|
||||
import { Redis } from 'ioredis';
|
||||
import { parseRedisUrl } from '../../common/helpers';
|
||||
|
||||
@Injectable()
|
||||
export class RedisHealthIndicator {
|
||||
@@ -19,8 +20,10 @@ export class RedisHealthIndicator {
|
||||
const indicator = this.healthIndicatorService.check(key);
|
||||
|
||||
try {
|
||||
const redis = new Redis(this.environmentService.getRedisUrl(), {
|
||||
const redisUrl = this.environmentService.getRedisUrl();
|
||||
const redis = new Redis(redisUrl, {
|
||||
maxRetriesPerRequest: 15,
|
||||
tls: parseRedisUrl(redisUrl).tls,
|
||||
});
|
||||
|
||||
await redis.ping();
|
||||
|
||||
@@ -18,6 +18,7 @@ import { GeneralQueueProcessor } from './processors/general-queue.processor';
|
||||
password: redisConfig.password,
|
||||
db: redisConfig.db,
|
||||
family: redisConfig.family,
|
||||
tls: redisConfig.tls,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
},
|
||||
defaultJobOptions: {
|
||||
|
||||
@@ -19,6 +19,7 @@ export class RedisConfigService implements RedisOptionsFactory {
|
||||
password: redisConfig.password,
|
||||
db: redisConfig.db,
|
||||
family: redisConfig.family,
|
||||
tls: redisConfig.tls,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -71,6 +71,16 @@ export class StaticModule implements OnModuleInit {
|
||||
await app.register(fastifyStatic, {
|
||||
root: clientDistPath,
|
||||
wildcard: false,
|
||||
preCompressed: true,
|
||||
setHeaders: (reply: any, pathName: string) => {
|
||||
// Vite content-hashes everything under /assets, so they can be cached forever
|
||||
if (/[\\/]assets[\\/]/.test(pathName)) {
|
||||
reply.header(
|
||||
'Cache-Control',
|
||||
'public, max-age=31536000, immutable',
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
app.get(RENDER_PATH, (req: any, res: any) => {
|
||||
|
||||
@@ -17,6 +17,7 @@ export class WsRedisIoAdapter extends IoAdapter {
|
||||
|
||||
const options: RedisOptions = {
|
||||
family: this.redisConfig.family,
|
||||
tls: this.redisConfig.tls,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
};
|
||||
|
||||
|
||||
Generated
+183
-285
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -6,12 +6,12 @@ patchedDependencies:
|
||||
overrides:
|
||||
prosemirror-changeset: 2.4.0
|
||||
glob: 13.0.6
|
||||
ws: 8.21.0
|
||||
ws: 8.21.3
|
||||
dompurify: 3.4.13
|
||||
mermaid: 11.16.1
|
||||
undici: 7.29.0
|
||||
tmp: 0.2.7
|
||||
nanoid@^3: 3.3.17
|
||||
nanoid@^3: 3.3.18
|
||||
lodash-es: 4.18.1
|
||||
express-rate-limit: 8.2.2
|
||||
flatted: 3.4.2
|
||||
|
||||
Reference in New Issue
Block a user