mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 23:42:37 +10:00
Compare commits
13 Commits
v0.20.1
...
commentedi
| Author | SHA1 | Date | |
|---|---|---|---|
| 57cc41b2cf | |||
| 9ec688f679 | |||
| 7adbf85030 | |||
| de7982fe30 | |||
| 0402f7efb5 | |||
| 8327251ab6 | |||
| e8847bd9cd | |||
| 9bbd62e0f0 | |||
| 0289c5cb09 | |||
| 7993532111 | |||
| 31e5c0c660 | |||
| 33c314d4e8 | |||
| 08f223899a |
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.20.1",
|
"version": "0.20.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
|
|||||||
@ -383,5 +383,8 @@
|
|||||||
"Publicly shared pages from spaces you are a member of will appear here": "Publicly shared pages from spaces you are a member of will appear here",
|
"Publicly shared pages from spaces you are a member of will appear here": "Publicly shared pages from spaces you are a member of will appear here",
|
||||||
"Share deleted successfully": "Share deleted successfully",
|
"Share deleted successfully": "Share deleted successfully",
|
||||||
"Share not found": "Share not found",
|
"Share not found": "Share not found",
|
||||||
"Failed to share page": "Failed to share page"
|
"Failed to share page": "Failed to share page",
|
||||||
|
"Copy page": "Copy page",
|
||||||
|
"Copy page to a different space.": "Copy page to a different space.",
|
||||||
|
"Page copied successfully": "Page copied successfully"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import { AppHeader } from "@/components/layouts/global/app-header.tsx";
|
|||||||
import Aside from "@/components/layouts/global/aside.tsx";
|
import Aside from "@/components/layouts/global/aside.tsx";
|
||||||
import classes from "./app-shell.module.css";
|
import classes from "./app-shell.module.css";
|
||||||
import { useTrialEndAction } from "@/ee/hooks/use-trial-end-action.tsx";
|
import { useTrialEndAction } from "@/ee/hooks/use-trial-end-action.tsx";
|
||||||
import { useClickOutside, useMergedRef } from "@mantine/hooks";
|
|
||||||
import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts";
|
import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts";
|
||||||
|
|
||||||
export default function GlobalAppShell({
|
export default function GlobalAppShell({
|
||||||
@ -30,13 +29,6 @@ export default function GlobalAppShell({
|
|||||||
const [sidebarWidth, setSidebarWidth] = useAtom(sidebarWidthAtom);
|
const [sidebarWidth, setSidebarWidth] = useAtom(sidebarWidthAtom);
|
||||||
const [isResizing, setIsResizing] = useState(false);
|
const [isResizing, setIsResizing] = useState(false);
|
||||||
const sidebarRef = useRef(null);
|
const sidebarRef = useRef(null);
|
||||||
const navbarOutsideRef = useClickOutside(() => {
|
|
||||||
if (mobileOpened) {
|
|
||||||
toggleMobile();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const mergedRef = useMergedRef(sidebarRef, navbarOutsideRef);
|
|
||||||
|
|
||||||
const startResizing = React.useCallback((mouseDownEvent) => {
|
const startResizing = React.useCallback((mouseDownEvent) => {
|
||||||
mouseDownEvent.preventDefault();
|
mouseDownEvent.preventDefault();
|
||||||
@ -112,7 +104,7 @@ export default function GlobalAppShell({
|
|||||||
<AppShell.Navbar
|
<AppShell.Navbar
|
||||||
className={classes.navbar}
|
className={classes.navbar}
|
||||||
withBorder={false}
|
withBorder={false}
|
||||||
ref={mergedRef}
|
ref={sidebarRef}
|
||||||
>
|
>
|
||||||
<div className={classes.resizeHandle} onMouseDown={startResizing} />
|
<div className={classes.resizeHandle} onMouseDown={startResizing} />
|
||||||
{isSpaceRoute && <SpaceSidebar />}
|
{isSpaceRoute && <SpaceSidebar />}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Alert } from "@mantine/core";
|
import { Alert } from "@mantine/core";
|
||||||
import { useBillingQuery } from "@/ee/billing/queries/billing-query.ts";
|
import { useBillingQuery } from "@/ee/billing/queries/billing-query.ts";
|
||||||
import useTrial from "@/ee/hooks/use-trial.tsx";
|
import useTrial from "@/ee/hooks/use-trial.tsx";
|
||||||
|
import { getBillingTrialDays } from '@/lib/config.ts';
|
||||||
|
|
||||||
export default function BillingTrial() {
|
export default function BillingTrial() {
|
||||||
const { data: billing, isLoading } = useBillingQuery();
|
const { data: billing, isLoading } = useBillingQuery();
|
||||||
@ -15,14 +16,14 @@ export default function BillingTrial() {
|
|||||||
{trialDaysLeft > 0 && !billing && (
|
{trialDaysLeft > 0 && !billing && (
|
||||||
<Alert title="Your Trial is Active 🎉" color="blue" radius="md">
|
<Alert title="Your Trial is Active 🎉" color="blue" radius="md">
|
||||||
You have {trialDaysLeft} {trialDaysLeft === 1 ? "day" : "days"} left
|
You have {trialDaysLeft} {trialDaysLeft === 1 ? "day" : "days"} left
|
||||||
in your 7-day trial. Please subscribe to a plan before your trial
|
in your {getBillingTrialDays()}-day free trial. Please subscribe to a paid plan before your trial
|
||||||
ends.
|
ends.
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{trialDaysLeft === 0 && (
|
{trialDaysLeft === 0 && (
|
||||||
<Alert title="Your Trial has ended" color="red" radius="md">
|
<Alert title="Your Trial has ended" color="red" radius="md">
|
||||||
Your 7-day trial has come to an end. Please subscribe to a plan to
|
Your {getBillingTrialDays()}-day free trial has come to an end. Please subscribe to a paid plan to
|
||||||
continue using this service.
|
continue using this service.
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { isCloud } from "@/lib/config.ts";
|
import { getBillingTrialDays, isCloud } from "@/lib/config.ts";
|
||||||
import APP_ROUTE from "@/lib/app-route.ts";
|
import APP_ROUTE from "@/lib/app-route.ts";
|
||||||
import useUserRole from "@/hooks/use-user-role.tsx";
|
import useUserRole from "@/hooks/use-user-role.tsx";
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
@ -18,7 +18,7 @@ export const useTrialEndAction = () => {
|
|||||||
notifications.show({
|
notifications.show({
|
||||||
position: "top-right",
|
position: "top-right",
|
||||||
color: "red",
|
color: "red",
|
||||||
title: "Your 7-day trial has ended",
|
title: `Your ${getBillingTrialDays()}-day trial has ended`,
|
||||||
message:
|
message:
|
||||||
"Please upgrade to a paid plan or contact your workspace admin.",
|
"Please upgrade to a paid plan or contact your workspace admin.",
|
||||||
autoClose: false,
|
autoClose: false,
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export default function EnforceSso() {
|
|||||||
<Text size="md">{t("Enforce SSO")}</Text>
|
<Text size="md">{t("Enforce SSO")}</Text>
|
||||||
<Text size="sm" c="dimmed">
|
<Text size="sm" c="dimmed">
|
||||||
{t(
|
{t(
|
||||||
"Once enforced, members will not able able to login with email and password.",
|
"Once enforced, members will not able to login with email and password.",
|
||||||
)}
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Button, Group } from "@mantine/core";
|
import { Button, Group, Tooltip } from "@mantine/core";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
type CommentActionsProps = {
|
type CommentActionsProps = {
|
||||||
|
|||||||
@ -109,6 +109,7 @@ function CommentDialog({ editor, pageId }: CommentDialogProps) {
|
|||||||
|
|
||||||
<CommentEditor
|
<CommentEditor
|
||||||
onUpdate={handleCommentEditorChange}
|
onUpdate={handleCommentEditorChange}
|
||||||
|
onSave={handleAddComment}
|
||||||
placeholder={t("Write a comment")}
|
placeholder={t("Write a comment")}
|
||||||
editable={true}
|
editable={true}
|
||||||
autofocus={true}
|
autofocus={true}
|
||||||
|
|||||||
@ -8,10 +8,12 @@ import { useFocusWithin } from "@mantine/hooks";
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { forwardRef, useEffect, useImperativeHandle } from "react";
|
import { forwardRef, useEffect, useImperativeHandle } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import EmojiCommand from "@/features/editor/extensions/emoji-command";
|
||||||
|
|
||||||
interface CommentEditorProps {
|
interface CommentEditorProps {
|
||||||
defaultContent?: any;
|
defaultContent?: any;
|
||||||
onUpdate?: any;
|
onUpdate?: any;
|
||||||
|
onSave?: any;
|
||||||
editable: boolean;
|
editable: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
autofocus?: boolean;
|
autofocus?: boolean;
|
||||||
@ -22,6 +24,7 @@ const CommentEditor = forwardRef(
|
|||||||
{
|
{
|
||||||
defaultContent,
|
defaultContent,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
|
onSave,
|
||||||
editable,
|
editable,
|
||||||
placeholder,
|
placeholder,
|
||||||
autofocus,
|
autofocus,
|
||||||
@ -42,7 +45,35 @@ const CommentEditor = forwardRef(
|
|||||||
}),
|
}),
|
||||||
Underline,
|
Underline,
|
||||||
Link,
|
Link,
|
||||||
|
EmojiCommand,
|
||||||
],
|
],
|
||||||
|
editorProps: {
|
||||||
|
handleDOMEvents: {
|
||||||
|
keydown: (_view, event) => {
|
||||||
|
if (
|
||||||
|
[
|
||||||
|
"ArrowUp",
|
||||||
|
"ArrowDown",
|
||||||
|
"ArrowLeft",
|
||||||
|
"ArrowRight",
|
||||||
|
"Enter",
|
||||||
|
].includes(event.key)
|
||||||
|
) {
|
||||||
|
const emojiCommand = document.querySelector("#emoji-command");
|
||||||
|
if (emojiCommand) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === "Enter") {
|
||||||
|
event.preventDefault();
|
||||||
|
if (onSave) onSave();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
onUpdate({ editor }) {
|
onUpdate({ editor }) {
|
||||||
if (onUpdate) onUpdate(editor.getJSON());
|
if (onUpdate) onUpdate(editor.getJSON());
|
||||||
},
|
},
|
||||||
|
|||||||
@ -112,6 +112,7 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
defaultContent={content}
|
defaultContent={content}
|
||||||
editable={true}
|
editable={true}
|
||||||
onUpdate={(newContent: any) => setContent(newContent)}
|
onUpdate={(newContent: any) => setContent(newContent)}
|
||||||
|
onSave={handleUpdateComment}
|
||||||
autofocus={true}
|
autofocus={true}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@ -142,6 +142,7 @@ const CommentEditorWithActions = ({ commentId, onSave, isLoading }) => {
|
|||||||
<CommentEditor
|
<CommentEditor
|
||||||
ref={commentEditorRef}
|
ref={commentEditorRef}
|
||||||
onUpdate={setContent}
|
onUpdate={setContent}
|
||||||
|
onSave={handleSave}
|
||||||
editable={true}
|
editable={true}
|
||||||
/>
|
/>
|
||||||
{focused && <CommentActions onSave={handleSave} isLoading={isLoading} />}
|
{focused && <CommentActions onSave={handleSave} isLoading={isLoading} />}
|
||||||
|
|||||||
@ -16,17 +16,19 @@
|
|||||||
.commentEditor {
|
.commentEditor {
|
||||||
|
|
||||||
.focused {
|
.focused {
|
||||||
|
border-radius: var(--mantine-radius-sm);
|
||||||
box-shadow: 0 0 0 2px var(--mantine-color-blue-3);
|
box-shadow: 0 0 0 2px var(--mantine-color-blue-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ProseMirror :global(.ProseMirror){
|
.ProseMirror :global(.ProseMirror){
|
||||||
|
border-radius: var(--mantine-radius-sm);
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
max-height: 20vh;
|
max-height: 20vh;
|
||||||
padding-left: 6px;
|
padding-left: 6px;
|
||||||
padding-right: 6px;
|
padding-right: 6px;
|
||||||
margin-top: 2px;
|
margin-top: 10px;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
overflow: hidden auto;
|
overflow: hidden auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ const renderEmojiItems = () => {
|
|||||||
showOnCreate: true,
|
showOnCreate: true,
|
||||||
interactive: true,
|
interactive: true,
|
||||||
trigger: "manual",
|
trigger: "manual",
|
||||||
placement: "bottom-start",
|
placement: "bottom",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onStart: (props: {
|
onStart: (props: {
|
||||||
|
|||||||
105
apps/client/src/features/page/components/copy-page-modal.tsx
Normal file
105
apps/client/src/features/page/components/copy-page-modal.tsx
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
import { Modal, Button, Group, Text } from "@mantine/core";
|
||||||
|
import { copyPageToSpace } from "@/features/page/services/page-service.ts";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { notifications } from "@mantine/notifications";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { ISpace } from "@/features/space/types/space.types.ts";
|
||||||
|
import { queryClient } from "@/main.tsx";
|
||||||
|
import { SpaceSelect } from "@/features/space/components/sidebar/space-select.tsx";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { buildPageUrl } from "@/features/page/page.utils.ts";
|
||||||
|
|
||||||
|
interface CopyPageModalProps {
|
||||||
|
pageId: string;
|
||||||
|
currentSpaceSlug: string;
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CopyPageModal({
|
||||||
|
pageId,
|
||||||
|
currentSpaceSlug,
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
}: CopyPageModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [targetSpace, setTargetSpace] = useState<ISpace>(null);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const handleCopy = async () => {
|
||||||
|
if (!targetSpace) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const copiedPage = await copyPageToSpace({
|
||||||
|
pageId,
|
||||||
|
spaceId: targetSpace.id,
|
||||||
|
});
|
||||||
|
queryClient.removeQueries({
|
||||||
|
predicate: (item) =>
|
||||||
|
["pages", "sidebar-pages", "root-sidebar-pages"].includes(
|
||||||
|
item.queryKey[0] as string,
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const pageUrl = buildPageUrl(
|
||||||
|
copiedPage.space.slug,
|
||||||
|
copiedPage.slugId,
|
||||||
|
copiedPage.title,
|
||||||
|
);
|
||||||
|
navigate(pageUrl);
|
||||||
|
notifications.show({
|
||||||
|
message: t("Page copied successfully"),
|
||||||
|
});
|
||||||
|
onClose();
|
||||||
|
setTargetSpace(null);
|
||||||
|
} catch (err) {
|
||||||
|
notifications.show({
|
||||||
|
message: err.response?.data.message || "An error occurred",
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (space: ISpace) => {
|
||||||
|
setTargetSpace(space);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal.Root
|
||||||
|
opened={open}
|
||||||
|
onClose={onClose}
|
||||||
|
size={500}
|
||||||
|
padding="xl"
|
||||||
|
yOffset="10vh"
|
||||||
|
xOffset={0}
|
||||||
|
mah={400}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<Modal.Overlay />
|
||||||
|
<Modal.Content style={{ overflow: "hidden" }}>
|
||||||
|
<Modal.Header py={0}>
|
||||||
|
<Modal.Title fw={500}>{t("Copy page")}</Modal.Title>
|
||||||
|
<Modal.CloseButton />
|
||||||
|
</Modal.Header>
|
||||||
|
<Modal.Body>
|
||||||
|
<Text mb="xs" c="dimmed" size="sm">
|
||||||
|
{t("Copy page to a different space.")}
|
||||||
|
</Text>
|
||||||
|
|
||||||
|
<SpaceSelect
|
||||||
|
value={currentSpaceSlug}
|
||||||
|
clearable={false}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
<Group justify="end" mt="md">
|
||||||
|
<Button onClick={onClose} variant="default">
|
||||||
|
{t("Cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button onClick={handleCopy}>{t("Copy")}</Button>
|
||||||
|
</Group>
|
||||||
|
</Modal.Body>
|
||||||
|
</Modal.Content>
|
||||||
|
</Modal.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ import {
|
|||||||
IconTrash,
|
IconTrash,
|
||||||
IconWifiOff,
|
IconWifiOff,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
import useToggleAside from "@/hooks/use-toggle-aside.tsx";
|
import useToggleAside from "@/hooks/use-toggle-aside.tsx";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { historyAtoms } from "@/features/page-history/atoms/history-atoms.ts";
|
import { historyAtoms } from "@/features/page-history/atoms/history-atoms.ts";
|
||||||
@ -35,7 +35,7 @@ import {
|
|||||||
import { formattedDate, timeAgo } from "@/lib/time.ts";
|
import { formattedDate, timeAgo } from "@/lib/time.ts";
|
||||||
import MovePageModal from "@/features/page/components/move-page-modal.tsx";
|
import MovePageModal from "@/features/page/components/move-page-modal.tsx";
|
||||||
import { useTimeAgo } from "@/hooks/use-time-ago.tsx";
|
import { useTimeAgo } from "@/hooks/use-time-ago.tsx";
|
||||||
import ShareModal from '@/features/share/components/share-modal.tsx';
|
import ShareModal from "@/features/share/components/share-modal.tsx";
|
||||||
|
|
||||||
interface PageHeaderMenuProps {
|
interface PageHeaderMenuProps {
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
@ -106,7 +106,7 @@ function PageActionMenu({ readOnly }: PageActionMenuProps) {
|
|||||||
{ open: openMovePageModal, close: closeMoveSpaceModal },
|
{ open: openMovePageModal, close: closeMoveSpaceModal },
|
||||||
] = useDisclosure(false);
|
] = useDisclosure(false);
|
||||||
const [pageEditor] = useAtom(pageEditorAtom);
|
const [pageEditor] = useAtom(pageEditorAtom);
|
||||||
const pageUpdatedAt = useTimeAgo(page.updatedAt);
|
const pageUpdatedAt = useTimeAgo(page?.updatedAt);
|
||||||
|
|
||||||
const handleCopyLink = () => {
|
const handleCopyLink = () => {
|
||||||
const pageUrl =
|
const pageUrl =
|
||||||
|
|||||||
@ -46,6 +46,7 @@ export default function MovePageModal({
|
|||||||
message: t("Page moved successfully"),
|
message: t("Page moved successfully"),
|
||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
|
setTargetSpace(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
message: err.response?.data.message || "An error occurred",
|
message: err.response?.data.message || "An error occurred",
|
||||||
@ -53,7 +54,6 @@ export default function MovePageModal({
|
|||||||
});
|
});
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
setTargetSpace(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (space: ISpace) => {
|
const handleChange = (space: ISpace) => {
|
||||||
@ -69,7 +69,7 @@ export default function MovePageModal({
|
|||||||
yOffset="10vh"
|
yOffset="10vh"
|
||||||
xOffset={0}
|
xOffset={0}
|
||||||
mah={400}
|
mah={400}
|
||||||
onClick={e => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<Modal.Overlay />
|
<Modal.Overlay />
|
||||||
<Modal.Content style={{ overflow: "hidden" }}>
|
<Modal.Content style={{ overflow: "hidden" }}>
|
||||||
@ -78,7 +78,9 @@ export default function MovePageModal({
|
|||||||
<Modal.CloseButton />
|
<Modal.CloseButton />
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<Modal.Body>
|
<Modal.Body>
|
||||||
<Text mb="xs" c="dimmed" size="sm">{t("Move page to a different space.")}</Text>
|
<Text mb="xs" c="dimmed" size="sm">
|
||||||
|
{t("Move page to a different space.")}
|
||||||
|
</Text>
|
||||||
|
|
||||||
<SpaceSelect
|
<SpaceSelect
|
||||||
value={currentSpaceSlug}
|
value={currentSpaceSlug}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import api from "@/lib/api-client";
|
import api from "@/lib/api-client";
|
||||||
import {
|
import {
|
||||||
|
ICopyPageToSpace,
|
||||||
IExportPageParams,
|
IExportPageParams,
|
||||||
IMovePage,
|
IMovePage,
|
||||||
IMovePageToSpace,
|
IMovePageToSpace,
|
||||||
@ -39,6 +40,11 @@ export async function movePageToSpace(data: IMovePageToSpace): Promise<void> {
|
|||||||
await api.post<void>("/pages/move-to-space", data);
|
await api.post<void>("/pages/move-to-space", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function copyPageToSpace(data: ICopyPageToSpace): Promise<IPage> {
|
||||||
|
const req = await api.post<IPage>("/pages/copy-to-space", data);
|
||||||
|
return req.data;
|
||||||
|
}
|
||||||
|
|
||||||
export async function getSidebarPages(
|
export async function getSidebarPages(
|
||||||
params: SidebarPagesParams,
|
params: SidebarPagesParams,
|
||||||
): Promise<IPagination<IPage>> {
|
): Promise<IPagination<IPage>> {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
IconArrowRight,
|
IconArrowRight,
|
||||||
IconChevronDown,
|
IconChevronDown,
|
||||||
IconChevronRight,
|
IconChevronRight,
|
||||||
|
IconCopy,
|
||||||
IconDotsVertical,
|
IconDotsVertical,
|
||||||
IconFileDescription,
|
IconFileDescription,
|
||||||
IconFileExport,
|
IconFileExport,
|
||||||
@ -60,6 +61,7 @@ import ExportModal from "@/components/common/export-modal";
|
|||||||
import MovePageModal from "../../components/move-page-modal.tsx";
|
import MovePageModal from "../../components/move-page-modal.tsx";
|
||||||
import { mobileSidebarAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts";
|
import { mobileSidebarAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts";
|
||||||
import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts";
|
import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts";
|
||||||
|
import CopyPageModal from "../../components/copy-page-modal.tsx";
|
||||||
|
|
||||||
interface SpaceTreeProps {
|
interface SpaceTreeProps {
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
@ -448,6 +450,10 @@ function NodeMenu({ node, treeApi }: NodeMenuProps) {
|
|||||||
movePageModalOpened,
|
movePageModalOpened,
|
||||||
{ open: openMovePageModal, close: closeMoveSpaceModal },
|
{ open: openMovePageModal, close: closeMoveSpaceModal },
|
||||||
] = useDisclosure(false);
|
] = useDisclosure(false);
|
||||||
|
const [
|
||||||
|
copyPageModalOpened,
|
||||||
|
{ open: openCopyPageModal, close: closeCopySpaceModal },
|
||||||
|
] = useDisclosure(false);
|
||||||
|
|
||||||
const handleCopyLink = () => {
|
const handleCopyLink = () => {
|
||||||
const pageUrl =
|
const pageUrl =
|
||||||
@ -511,6 +517,17 @@ function NodeMenu({ node, treeApi }: NodeMenuProps) {
|
|||||||
{t("Move")}
|
{t("Move")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
|
||||||
|
<Menu.Item
|
||||||
|
leftSection={<IconCopy size={16} />}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
openCopyPageModal();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("Copy")}
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
c="red"
|
c="red"
|
||||||
@ -536,6 +553,13 @@ function NodeMenu({ node, treeApi }: NodeMenuProps) {
|
|||||||
open={movePageModalOpened}
|
open={movePageModalOpened}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<CopyPageModal
|
||||||
|
pageId={node.id}
|
||||||
|
currentSpaceSlug={spaceSlug}
|
||||||
|
onClose={closeCopySpaceModal}
|
||||||
|
open={copyPageModalOpened}
|
||||||
|
/>
|
||||||
|
|
||||||
<ExportModal
|
<ExportModal
|
||||||
type="page"
|
type="page"
|
||||||
id={node.id}
|
id={node.id}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export interface IPage {
|
|||||||
spaceId: string;
|
spaceId: string;
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
isLocked: boolean;
|
isLocked: boolean;
|
||||||
lastUpdatedById: Date;
|
lastUpdatedById: string;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
deletedAt: Date;
|
deletedAt: Date;
|
||||||
@ -47,6 +47,11 @@ export interface IMovePageToSpace {
|
|||||||
spaceId: string;
|
spaceId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICopyPageToSpace {
|
||||||
|
pageId: string;
|
||||||
|
spaceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SidebarPagesParams {
|
export interface SidebarPagesParams {
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
pageId?: string;
|
pageId?: string;
|
||||||
|
|||||||
@ -74,6 +74,10 @@ export function getDrawioUrl() {
|
|||||||
return getConfigValue("DRAWIO_URL", "https://embed.diagrams.net");
|
return getConfigValue("DRAWIO_URL", "https://embed.diagrams.net");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBillingTrialDays() {
|
||||||
|
return getConfigValue("BILLING_TRIAL_DAYS");
|
||||||
|
}
|
||||||
|
|
||||||
function getConfigValue(key: string, defaultValue: string = undefined): string {
|
function getConfigValue(key: string, defaultValue: string = undefined): string {
|
||||||
const rawValue = import.meta.env.DEV
|
const rawValue = import.meta.env.DEV
|
||||||
? process?.env?.[key]
|
? process?.env?.[key]
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
CLOUD,
|
CLOUD,
|
||||||
SUBDOMAIN_HOST,
|
SUBDOMAIN_HOST,
|
||||||
COLLAB_URL,
|
COLLAB_URL,
|
||||||
|
BILLING_TRIAL_DAYS,
|
||||||
} = loadEnv(mode, envPath, "");
|
} = loadEnv(mode, envPath, "");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -23,6 +24,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
CLOUD,
|
CLOUD,
|
||||||
SUBDOMAIN_HOST,
|
SUBDOMAIN_HOST,
|
||||||
COLLAB_URL,
|
COLLAB_URL,
|
||||||
|
BILLING_TRIAL_DAYS,
|
||||||
},
|
},
|
||||||
APP_VERSION: JSON.stringify(process.env.npm_package_version),
|
APP_VERSION: JSON.stringify(process.env.npm_package_version),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
"version": "0.20.1",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Module, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
import { Logger, Module, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||||
import { AuthenticationExtension } from './extensions/authentication.extension';
|
import { AuthenticationExtension } from './extensions/authentication.extension';
|
||||||
import { PersistenceExtension } from './extensions/persistence.extension';
|
import { PersistenceExtension } from './extensions/persistence.extension';
|
||||||
import { CollaborationGateway } from './collaboration.gateway';
|
import { CollaborationGateway } from './collaboration.gateway';
|
||||||
@ -22,6 +22,7 @@ import { LoggerExtension } from './extensions/logger.extension';
|
|||||||
imports: [TokenModule],
|
imports: [TokenModule],
|
||||||
})
|
})
|
||||||
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
||||||
|
private readonly logger = new Logger(CollaborationModule.name);
|
||||||
private collabWsAdapter: CollabWsAdapter;
|
private collabWsAdapter: CollabWsAdapter;
|
||||||
private path = '/collab';
|
private path = '/collab';
|
||||||
|
|
||||||
@ -38,7 +39,15 @@ export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
|||||||
|
|
||||||
wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
|
wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
|
||||||
this.collaborationGateway.handleConnection(client, request);
|
this.collaborationGateway.handleConnection(client, request);
|
||||||
|
|
||||||
|
client.on('error', (error) => {
|
||||||
|
this.logger.error('WebSocket client error:', error);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wss.on('error', (error) =>
|
||||||
|
this.logger.log('WebSocket server error:', error),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleDestroy(): Promise<void> {
|
async onModuleDestroy(): Promise<void> {
|
||||||
|
|||||||
@ -130,7 +130,7 @@ export class PersistenceExtension implements Extension {
|
|||||||
);
|
);
|
||||||
this.contributors.delete(documentName);
|
this.contributors.delete(documentName);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.log('Contributors error:' + err?.['message']);
|
this.logger.debug('Contributors error:' + err?.['message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.pageRepo.updatePage(
|
await this.pageRepo.updatePage(
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
import { Node } from '@tiptap/pm/model';
|
import { Node } from '@tiptap/pm/model';
|
||||||
import { jsonToNode } from '../../../collaboration/collaboration.util';
|
import {
|
||||||
|
jsonToNode,
|
||||||
|
tiptapExtensions,
|
||||||
|
} from '../../../collaboration/collaboration.util';
|
||||||
import { validate as isValidUUID } from 'uuid';
|
import { validate as isValidUUID } from 'uuid';
|
||||||
import { Transform } from '@tiptap/pm/transform';
|
import { Transform } from '@tiptap/pm/transform';
|
||||||
|
import { TiptapTransformer } from '@hocuspocus/transformer';
|
||||||
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
export interface MentionNode {
|
export interface MentionNode {
|
||||||
id: string;
|
id: string;
|
||||||
@ -59,7 +64,6 @@ export function extractPageMentions(mentionList: MentionNode[]): MentionNode[] {
|
|||||||
return pageMentionList as MentionNode[];
|
return pageMentionList as MentionNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getProsemirrorContent(content: any) {
|
export function getProsemirrorContent(content: any) {
|
||||||
return (
|
return (
|
||||||
content ?? {
|
content ?? {
|
||||||
@ -108,3 +112,18 @@ export function removeMarkTypeFromDoc(doc: Node, markName: string): Node {
|
|||||||
const tr = new Transform(doc).removeMark(0, doc.content.size, markType);
|
const tr = new Transform(doc).removeMark(0, doc.content.size, markType);
|
||||||
return tr.doc;
|
return tr.doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createYdocFromJson(prosemirrorJson: any): Buffer | null {
|
||||||
|
if (prosemirrorJson) {
|
||||||
|
const ydoc = TiptapTransformer.toYdoc(
|
||||||
|
prosemirrorJson,
|
||||||
|
'default',
|
||||||
|
tiptapExtensions,
|
||||||
|
);
|
||||||
|
|
||||||
|
Y.encodeStateAsUpdate(ydoc);
|
||||||
|
|
||||||
|
return Buffer.from(Y.encodeStateAsUpdate(ydoc));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|||||||
24
apps/server/src/core/page/dto/copy-page.dto.ts
Normal file
24
apps/server/src/core/page/dto/copy-page.dto.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { IsString, IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
|
export class CopyPageToSpaceDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
pageId: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsString()
|
||||||
|
spaceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CopyPageMapEntry = {
|
||||||
|
newPageId: string;
|
||||||
|
newSlugId: string;
|
||||||
|
oldSlugId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ICopyPageAttachment = {
|
||||||
|
newPageId: string,
|
||||||
|
oldPageId: string,
|
||||||
|
oldAttachmentId: string,
|
||||||
|
newAttachmentId: string,
|
||||||
|
};
|
||||||
@ -1,4 +1,10 @@
|
|||||||
import { IsString, IsOptional, MinLength, MaxLength } from 'class-validator';
|
import {
|
||||||
|
IsString,
|
||||||
|
IsOptional,
|
||||||
|
MinLength,
|
||||||
|
MaxLength,
|
||||||
|
IsNotEmpty,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class MovePageDto {
|
export class MovePageDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -15,9 +21,11 @@ export class MovePageDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MovePageToSpaceDto {
|
export class MovePageToSpaceDto {
|
||||||
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
pageId: string;
|
pageId: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import {
|
|||||||
import SpaceAbilityFactory from '../casl/abilities/space-ability.factory';
|
import SpaceAbilityFactory from '../casl/abilities/space-ability.factory';
|
||||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||||
import { RecentPageDto } from './dto/recent-page.dto';
|
import { RecentPageDto } from './dto/recent-page.dto';
|
||||||
|
import { CopyPageToSpaceDto } from './dto/copy-page.dto';
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('pages')
|
@Controller('pages')
|
||||||
@ -237,6 +238,36 @@ export class PageController {
|
|||||||
return this.pageService.movePageToSpace(movedPage, dto.spaceId);
|
return this.pageService.movePageToSpace(movedPage, dto.spaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
@Post('copy-to-space')
|
||||||
|
async copyPageToSpace(
|
||||||
|
@Body() dto: CopyPageToSpaceDto,
|
||||||
|
@AuthUser() user: User,
|
||||||
|
) {
|
||||||
|
const copiedPage = await this.pageRepo.findById(dto.pageId);
|
||||||
|
if (!copiedPage) {
|
||||||
|
throw new NotFoundException('Page to copy not found');
|
||||||
|
}
|
||||||
|
if (copiedPage.spaceId === dto.spaceId) {
|
||||||
|
throw new BadRequestException('Page is already in this space');
|
||||||
|
}
|
||||||
|
|
||||||
|
const abilities = await Promise.all([
|
||||||
|
this.spaceAbility.createForUser(user, copiedPage.spaceId),
|
||||||
|
this.spaceAbility.createForUser(user, dto.spaceId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (
|
||||||
|
abilities.some((ability) =>
|
||||||
|
ability.cannot(SpaceCaslAction.Edit, SpaceCaslSubject.Page),
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.pageService.copyPageToSpace(copiedPage, dto.spaceId, user);
|
||||||
|
}
|
||||||
|
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@Post('move')
|
@Post('move')
|
||||||
async movePage(@Body() dto: MovePageDto, @AuthUser() user: User) {
|
async movePage(@Body() dto: MovePageDto, @AuthUser() user: User) {
|
||||||
|
|||||||
@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
|
|||||||
import { PageService } from './services/page.service';
|
import { PageService } from './services/page.service';
|
||||||
import { PageController } from './page.controller';
|
import { PageController } from './page.controller';
|
||||||
import { PageHistoryService } from './services/page-history.service';
|
import { PageHistoryService } from './services/page-history.service';
|
||||||
|
import { StorageModule } from '../../integrations/storage/storage.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [PageController],
|
controllers: [PageController],
|
||||||
providers: [PageService, PageHistoryService],
|
providers: [PageService, PageHistoryService],
|
||||||
exports: [PageService, PageHistoryService],
|
exports: [PageService, PageHistoryService],
|
||||||
|
imports: [StorageModule]
|
||||||
})
|
})
|
||||||
export class PageModule {}
|
export class PageModule {}
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Injectable,
|
Injectable,
|
||||||
|
Logger,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { CreatePageDto } from '../dto/create-page.dto';
|
import { CreatePageDto } from '../dto/create-page.dto';
|
||||||
import { UpdatePageDto } from '../dto/update-page.dto';
|
import { UpdatePageDto } from '../dto/update-page.dto';
|
||||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||||
import { Page } from '@docmost/db/types/entity.types';
|
import { InsertablePage, Page, User } from '@docmost/db/types/entity.types';
|
||||||
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
||||||
import {
|
import {
|
||||||
executeWithPagination,
|
executeWithPagination,
|
||||||
@ -21,13 +22,28 @@ import { DB } from '@docmost/db/types/db';
|
|||||||
import { generateSlugId } from '../../../common/helpers';
|
import { generateSlugId } from '../../../common/helpers';
|
||||||
import { executeTx } from '@docmost/db/utils';
|
import { executeTx } from '@docmost/db/utils';
|
||||||
import { AttachmentRepo } from '@docmost/db/repos/attachment/attachment.repo';
|
import { AttachmentRepo } from '@docmost/db/repos/attachment/attachment.repo';
|
||||||
|
import { v7 as uuid7 } from 'uuid';
|
||||||
|
import {
|
||||||
|
createYdocFromJson,
|
||||||
|
getAttachmentIds,
|
||||||
|
getProsemirrorContent,
|
||||||
|
isAttachmentNode,
|
||||||
|
removeMarkTypeFromDoc,
|
||||||
|
} from '../../../common/helpers/prosemirror/utils';
|
||||||
|
import { jsonToNode, jsonToText } from 'src/collaboration/collaboration.util';
|
||||||
|
import { CopyPageMapEntry, ICopyPageAttachment } from '../dto/copy-page.dto';
|
||||||
|
import { Node as PMNode } from '@tiptap/pm/model';
|
||||||
|
import { StorageService } from '../../../integrations/storage/storage.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PageService {
|
export class PageService {
|
||||||
|
private readonly logger = new Logger(PageService.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private pageRepo: PageRepo,
|
private pageRepo: PageRepo,
|
||||||
private attachmentRepo: AttachmentRepo,
|
private attachmentRepo: AttachmentRepo,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
|
private readonly storageService: StorageService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findById(
|
async findById(
|
||||||
@ -242,6 +258,154 @@ export class PageService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copyPageToSpace(rootPage: Page, spaceId: string, authUser: User) {
|
||||||
|
//TODO:
|
||||||
|
// i. maintain internal links within copied pages
|
||||||
|
|
||||||
|
const nextPosition = await this.nextPagePosition(spaceId);
|
||||||
|
|
||||||
|
const pages = await this.pageRepo.getPageAndDescendants(rootPage.id, {
|
||||||
|
includeContent: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const pageMap = new Map<string, CopyPageMapEntry>();
|
||||||
|
pages.forEach((page) => {
|
||||||
|
pageMap.set(page.id, {
|
||||||
|
newPageId: uuid7(),
|
||||||
|
newSlugId: generateSlugId(),
|
||||||
|
oldSlugId: page.slugId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const attachmentMap = new Map<string, ICopyPageAttachment>();
|
||||||
|
|
||||||
|
const insertablePages: InsertablePage[] = await Promise.all(
|
||||||
|
pages.map(async (page) => {
|
||||||
|
const pageContent = getProsemirrorContent(page.content);
|
||||||
|
const pageFromMap = pageMap.get(page.id);
|
||||||
|
|
||||||
|
const doc = jsonToNode(pageContent);
|
||||||
|
const prosemirrorDoc = removeMarkTypeFromDoc(doc, 'comment');
|
||||||
|
|
||||||
|
const attachmentIds = getAttachmentIds(prosemirrorDoc.toJSON());
|
||||||
|
|
||||||
|
if (attachmentIds.length > 0) {
|
||||||
|
attachmentIds.forEach((attachmentId: string) => {
|
||||||
|
const newPageId = pageFromMap.newPageId;
|
||||||
|
const newAttachmentId = uuid7();
|
||||||
|
attachmentMap.set(attachmentId, {
|
||||||
|
newPageId: newPageId,
|
||||||
|
oldPageId: page.id,
|
||||||
|
oldAttachmentId: attachmentId,
|
||||||
|
newAttachmentId: newAttachmentId,
|
||||||
|
});
|
||||||
|
|
||||||
|
prosemirrorDoc.descendants((node: PMNode) => {
|
||||||
|
if (isAttachmentNode(node.type.name)) {
|
||||||
|
if (node.attrs.attachmentId === attachmentId) {
|
||||||
|
//@ts-ignore
|
||||||
|
node.attrs.attachmentId = newAttachmentId;
|
||||||
|
|
||||||
|
if (node.attrs.src) {
|
||||||
|
//@ts-ignore
|
||||||
|
node.attrs.src = node.attrs.src.replace(
|
||||||
|
attachmentId,
|
||||||
|
newAttachmentId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (node.attrs.src) {
|
||||||
|
//@ts-ignore
|
||||||
|
node.attrs.src = node.attrs.src.replace(
|
||||||
|
attachmentId,
|
||||||
|
newAttachmentId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const prosemirrorJson = prosemirrorDoc.toJSON();
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: pageFromMap.newPageId,
|
||||||
|
slugId: pageFromMap.newSlugId,
|
||||||
|
title: page.title,
|
||||||
|
icon: page.icon,
|
||||||
|
content: prosemirrorJson,
|
||||||
|
textContent: jsonToText(prosemirrorJson),
|
||||||
|
ydoc: createYdocFromJson(prosemirrorJson),
|
||||||
|
position: page.id === rootPage.id ? nextPosition : page.position,
|
||||||
|
spaceId: spaceId,
|
||||||
|
workspaceId: page.workspaceId,
|
||||||
|
creatorId: authUser.id,
|
||||||
|
lastUpdatedById: authUser.id,
|
||||||
|
parentPageId: page.parentPageId
|
||||||
|
? pageMap.get(page.parentPageId)?.newPageId
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.db.insertInto('pages').values(insertablePages).execute();
|
||||||
|
|
||||||
|
//TODO: best to handle this in a queue
|
||||||
|
const attachmentsIds = Array.from(attachmentMap.keys());
|
||||||
|
if (attachmentsIds.length > 0) {
|
||||||
|
const attachments = await this.db
|
||||||
|
.selectFrom('attachments')
|
||||||
|
.selectAll()
|
||||||
|
.where('id', 'in', attachmentsIds)
|
||||||
|
.where('workspaceId', '=', rootPage.workspaceId)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
for (const attachment of attachments) {
|
||||||
|
try {
|
||||||
|
const pageAttachment = attachmentMap.get(attachment.id);
|
||||||
|
|
||||||
|
// make sure the copied attachment belongs to the page it was copied from
|
||||||
|
if (attachment.pageId !== pageAttachment.oldPageId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newAttachmentId = pageAttachment.newAttachmentId;
|
||||||
|
|
||||||
|
const newPageId = pageAttachment.newPageId;
|
||||||
|
|
||||||
|
const newPathFile = attachment.filePath.replace(
|
||||||
|
attachment.id,
|
||||||
|
newAttachmentId,
|
||||||
|
);
|
||||||
|
await this.storageService.copy(attachment.filePath, newPathFile);
|
||||||
|
await this.db
|
||||||
|
.insertInto('attachments')
|
||||||
|
.values({
|
||||||
|
id: newAttachmentId,
|
||||||
|
type: attachment.type,
|
||||||
|
filePath: newPathFile,
|
||||||
|
fileName: attachment.fileName,
|
||||||
|
fileSize: attachment.fileSize,
|
||||||
|
mimeType: attachment.mimeType,
|
||||||
|
fileExt: attachment.fileExt,
|
||||||
|
creatorId: attachment.creatorId,
|
||||||
|
workspaceId: attachment.workspaceId,
|
||||||
|
pageId: newPageId,
|
||||||
|
spaceId: spaceId,
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newPageId = pageMap.get(rootPage.id).newPageId;
|
||||||
|
return await this.pageRepo.findById(newPageId, {
|
||||||
|
includeSpace: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async movePage(dto: MovePageDto, movedPage: Page) {
|
async movePage(dto: MovePageDto, movedPage: Page) {
|
||||||
// validate position value by attempting to generate a key
|
// validate position value by attempting to generate a key
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -244,7 +244,7 @@ export class PageRepo {
|
|||||||
'p.spaceId',
|
'p.spaceId',
|
||||||
'p.workspaceId',
|
'p.workspaceId',
|
||||||
])
|
])
|
||||||
.$if(opts?.includeContent, (qb) => qb.select('content'))
|
.$if(opts?.includeContent, (qb) => qb.select('p.content'))
|
||||||
.innerJoin('page_hierarchy as ph', 'p.parentPageId', 'ph.id'),
|
.innerJoin('page_hierarchy as ph', 'p.parentPageId', 'ph.id'),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Submodule apps/server/src/ee updated: d3095f2d8b...96404fc121
@ -42,6 +42,9 @@ export class StaticModule implements OnModuleInit {
|
|||||||
? this.environmentService.getSubdomainHost()
|
? this.environmentService.getSubdomainHost()
|
||||||
: undefined,
|
: undefined,
|
||||||
COLLAB_URL: this.environmentService.getCollabUrl(),
|
COLLAB_URL: this.environmentService.getCollabUrl(),
|
||||||
|
BILLING_TRIAL_DAYS: this.environmentService.isCloud()
|
||||||
|
? this.environmentService.getBillingTrialDays()
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
||||||
|
|||||||
@ -25,6 +25,16 @@ export class LocalDriver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copy(fromFilePath: string, toFilePath: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (await this.exists(fromFilePath)) {
|
||||||
|
await fs.copy(fromFilePath, toFilePath);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to copy file: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async read(filePath: string): Promise<Buffer> {
|
async read(filePath: string): Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
return await fs.readFile(this._fullPath(filePath));
|
return await fs.readFile(this._fullPath(filePath));
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { S3StorageConfig, StorageDriver, StorageOption } from '../interfaces';
|
import { S3StorageConfig, StorageDriver, StorageOption } from '../interfaces';
|
||||||
import {
|
import {
|
||||||
|
CopyObjectCommand,
|
||||||
DeleteObjectCommand,
|
DeleteObjectCommand,
|
||||||
GetObjectCommand,
|
GetObjectCommand,
|
||||||
HeadObjectCommand,
|
HeadObjectCommand,
|
||||||
@ -39,6 +40,22 @@ export class S3Driver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copy(fromFilePath: string, toFilePath: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (await this.exists(fromFilePath)) {
|
||||||
|
await this.s3Client.send(
|
||||||
|
new CopyObjectCommand({
|
||||||
|
Bucket: this.config.bucket,
|
||||||
|
CopySource: `${this.config.bucket}/${fromFilePath}`,
|
||||||
|
Key: toFilePath,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to copy file: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async read(filePath: string): Promise<Buffer> {
|
async read(filePath: string): Promise<Buffer> {
|
||||||
try {
|
try {
|
||||||
const command = new GetObjectCommand({
|
const command = new GetObjectCommand({
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
export interface StorageDriver {
|
export interface StorageDriver {
|
||||||
upload(filePath: string, file: Buffer): Promise<void>;
|
upload(filePath: string, file: Buffer): Promise<void>;
|
||||||
|
|
||||||
|
copy(fromFilePath: string, toFilePath: string): Promise<void>;
|
||||||
|
|
||||||
read(filePath: string): Promise<Buffer>;
|
read(filePath: string): Promise<Buffer>;
|
||||||
|
|
||||||
exists(filePath: string): Promise<boolean>;
|
exists(filePath: string): Promise<boolean>;
|
||||||
|
|||||||
@ -14,6 +14,11 @@ export class StorageService {
|
|||||||
this.logger.debug(`File uploaded successfully. Path: ${filePath}`);
|
this.logger.debug(`File uploaded successfully. Path: ${filePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async copy(fromFilePath: string, toFilePath: string) {
|
||||||
|
await this.storageDriver.copy(fromFilePath, toFilePath);
|
||||||
|
this.logger.debug(`File copied successfully. Path: ${toFilePath}`);
|
||||||
|
}
|
||||||
|
|
||||||
async read(filePath: string): Promise<Buffer> {
|
async read(filePath: string): Promise<Buffer> {
|
||||||
return this.storageDriver.read(filePath);
|
return this.storageDriver.read(filePath);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,7 @@ import {
|
|||||||
FastifyAdapter,
|
FastifyAdapter,
|
||||||
NestFastifyApplication,
|
NestFastifyApplication,
|
||||||
} from '@nestjs/platform-fastify';
|
} from '@nestjs/platform-fastify';
|
||||||
import {
|
import { Logger, NotFoundException, ValidationPipe } from '@nestjs/common';
|
||||||
Logger,
|
|
||||||
NotFoundException,
|
|
||||||
RequestMethod,
|
|
||||||
ValidationPipe,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
|
import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor';
|
||||||
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter';
|
||||||
import { InternalLogFilter } from './common/logger/internal-log-filter';
|
import { InternalLogFilter } from './common/logger/internal-log-filter';
|
||||||
@ -92,6 +87,14 @@ async function bootstrap() {
|
|||||||
|
|
||||||
const logger = new Logger('NestApplication');
|
const logger = new Logger('NestApplication');
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, promise) => {
|
||||||
|
logger.error(`UnhandledRejection: ${promise}, reason: ${reason}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('uncaughtException', (error) => {
|
||||||
|
logger.error('UncaughtException:', error);
|
||||||
|
});
|
||||||
|
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
await app.listen(port, '0.0.0.0', () => {
|
await app.listen(port, '0.0.0.0', () => {
|
||||||
logger.log(
|
logger.log(
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "docmost",
|
"name": "docmost",
|
||||||
"homepage": "https://docmost.com",
|
"homepage": "https://docmost.com",
|
||||||
"version": "0.20.1",
|
"version": "0.20.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nx run-many -t build",
|
"build": "nx run-many -t build",
|
||||||
|
|||||||
Reference in New Issue
Block a user