mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 04:42:37 +10:00
Compare commits
23 Commits
v0.20.3
...
e2b8899569
| Author | SHA1 | Date | |
|---|---|---|---|
| e2b8899569 | |||
| f6e3230eec | |||
| 625bdc7024 | |||
| 69447fc375 | |||
| 858ff9da06 | |||
| 343b2976c2 | |||
| 7491224d0f | |||
| 4a0b4040ed | |||
| e3ba817723 | |||
| b0491d5da4 | |||
| 1c200dbd0f | |||
| fb7e4a7956 | |||
| 1413033568 | |||
| 00f4588c21 | |||
| 3a75251e75 | |||
| c6bca6a602 | |||
| 55d1a2c932 | |||
| bc3cb2d63f | |||
| 7adbf85030 | |||
| de7982fe30 | |||
| 0402f7efb5 | |||
| 8327251ab6 | |||
| e8847bd9cd |
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.20.3",
|
"version": "0.20.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
@ -29,6 +29,7 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"emoji-mart": "^5.6.0",
|
"emoji-mart": "^5.6.0",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
|
"highlightjs-sap-abap": "^0.3.0",
|
||||||
"i18next": "^23.14.0",
|
"i18next": "^23.14.0",
|
||||||
"i18next-http-backend": "^2.6.1",
|
"i18next-http-backend": "^2.6.1",
|
||||||
"jotai": "^2.12.1",
|
"jotai": "^2.12.1",
|
||||||
|
|||||||
@ -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"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export enum BillingPlan {
|
export enum BillingPlan {
|
||||||
STANDARD = "standard",
|
STANDARD = "standard",
|
||||||
|
BUSINESS = "business",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBilling {
|
export interface IBilling {
|
||||||
|
|||||||
@ -2,14 +2,18 @@ import { useAtom } from "jotai";
|
|||||||
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
import { BillingPlan } from "@/ee/billing/types/billing.types.ts";
|
import { BillingPlan } from "@/ee/billing/types/billing.types.ts";
|
||||||
|
|
||||||
export const usePlan = () => {
|
const usePlan = () => {
|
||||||
const [workspace] = useAtom(workspaceAtom);
|
const [workspace] = useAtom(workspaceAtom);
|
||||||
|
|
||||||
const isStandard =
|
const isStandard =
|
||||||
typeof workspace?.plan === "string" &&
|
typeof workspace?.plan === "string" &&
|
||||||
workspace?.plan.toLowerCase() === BillingPlan.STANDARD.toLowerCase();
|
workspace?.plan.toLowerCase() === BillingPlan.STANDARD.toLowerCase();
|
||||||
|
|
||||||
return { isStandard };
|
const isBusiness =
|
||||||
|
typeof workspace?.plan === "string" &&
|
||||||
|
workspace?.plan.toLowerCase() === BillingPlan.BUSINESS.toLowerCase();
|
||||||
|
|
||||||
|
return { isStandard, isBusiness };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default usePlan;
|
export default usePlan;
|
||||||
|
|||||||
@ -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 be able to login with email and password.",
|
||||||
)}
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -10,11 +10,13 @@ import EnforceSso from "@/ee/security/components/enforce-sso.tsx";
|
|||||||
import AllowedDomains from "@/ee/security/components/allowed-domains.tsx";
|
import AllowedDomains from "@/ee/security/components/allowed-domains.tsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useLicense from "@/ee/hooks/use-license.tsx";
|
import useLicense from "@/ee/hooks/use-license.tsx";
|
||||||
|
import usePlan from "@/ee/hooks/use-plan.tsx";
|
||||||
|
|
||||||
export default function Security() {
|
export default function Security() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isAdmin } = useUserRole();
|
const { isAdmin } = useUserRole();
|
||||||
const { hasLicenseKey } = useLicense();
|
const { hasLicenseKey } = useLicense();
|
||||||
|
const { isBusiness } = usePlan();
|
||||||
|
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
return null;
|
return null;
|
||||||
@ -35,8 +37,7 @@ export default function Security() {
|
|||||||
Single sign-on (SSO)
|
Single sign-on (SSO)
|
||||||
</Title>
|
</Title>
|
||||||
|
|
||||||
{/*TODO: revisit when we add a second plan */}
|
{(isCloud() && isBusiness) || (!isCloud() && hasLicenseKey) ? (
|
||||||
{!isCloud() && hasLicenseKey ? (
|
|
||||||
<>
|
<>
|
||||||
<EnforceSso />
|
<EnforceSso />
|
||||||
<Divider my="lg" />
|
<Divider my="lg" />
|
||||||
|
|||||||
@ -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 = {
|
||||||
@ -15,7 +15,7 @@ function CommentActions({
|
|||||||
isCommentEditor,
|
isCommentEditor,
|
||||||
}: CommentActionsProps) {
|
}: CommentActionsProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group justify="flex-end" pt="sm" wrap="nowrap">
|
<Group justify="flex-end" pt="sm" wrap="nowrap">
|
||||||
{isCommentEditor && (
|
{isCommentEditor && (
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { asideStateAtom } from "@/components/layouts/global/hooks/atoms/sidebar-
|
|||||||
import { useEditor } from "@tiptap/react";
|
import { useEditor } from "@tiptap/react";
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
||||||
|
|
||||||
interface CommentDialogProps {
|
interface CommentDialogProps {
|
||||||
editor: ReturnType<typeof useEditor>;
|
editor: ReturnType<typeof useEditor>;
|
||||||
@ -35,6 +36,8 @@ function CommentDialog({ editor, pageId }: CommentDialogProps) {
|
|||||||
const createCommentMutation = useCreateCommentMutation();
|
const createCommentMutation = useCreateCommentMutation();
|
||||||
const { isPending } = createCommentMutation;
|
const { isPending } = createCommentMutation;
|
||||||
|
|
||||||
|
const emit = useQueryEmit();
|
||||||
|
|
||||||
const handleDialogClose = () => {
|
const handleDialogClose = () => {
|
||||||
setShowCommentPopup(false);
|
setShowCommentPopup(false);
|
||||||
editor.chain().focus().unsetCommentDecoration().run();
|
editor.chain().focus().unsetCommentDecoration().run();
|
||||||
@ -63,11 +66,23 @@ function CommentDialog({ editor, pageId }: CommentDialogProps) {
|
|||||||
.run();
|
.run();
|
||||||
setActiveCommentId(createdComment.id);
|
setActiveCommentId(createdComment.id);
|
||||||
|
|
||||||
|
//unselect text to close bubble menu
|
||||||
|
editor.commands.setTextSelection({ from: editor.view.state.selection.from, to: editor.view.state.selection.from });
|
||||||
|
|
||||||
setAsideState({ tab: "comments", isAsideOpen: true });
|
setAsideState({ tab: "comments", isAsideOpen: true });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const selector = `div[data-comment-id="${createdComment.id}"]`;
|
const selector = `div[data-comment-id="${createdComment.id}"]`;
|
||||||
const commentElement = document.querySelector(selector);
|
const commentElement = document.querySelector(selector);
|
||||||
commentElement?.scrollIntoView();
|
commentElement?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
|
||||||
|
editor.view.dispatch(
|
||||||
|
editor.state.tr.scrollIntoView()
|
||||||
|
);
|
||||||
|
}, 400);
|
||||||
|
|
||||||
|
emit({
|
||||||
|
operation: "invalidateComment",
|
||||||
|
pageId: pageId,
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setShowCommentPopup(false);
|
setShowCommentPopup(false);
|
||||||
@ -109,6 +124,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());
|
||||||
},
|
},
|
||||||
@ -53,6 +84,10 @@ const CommentEditor = forwardRef(
|
|||||||
autofocus: (autofocus && "end") || false,
|
autofocus: (autofocus && "end") || false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
commentEditor.commands.setContent(defaultContent);
|
||||||
|
}, [defaultContent]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (autofocus) {
|
if (autofocus) {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Group, Text, Box } from "@mantine/core";
|
import { Group, Text, Box } from "@mantine/core";
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import classes from "./comment.module.css";
|
import classes from "./comment.module.css";
|
||||||
import { useAtom, useAtomValue } from "jotai";
|
import { useAtom, useAtomValue } from "jotai";
|
||||||
import { timeAgo } from "@/lib/time";
|
import { timeAgo } from "@/lib/time";
|
||||||
@ -15,12 +15,14 @@ import {
|
|||||||
import { IComment } from "@/features/comment/types/comment.types";
|
import { IComment } from "@/features/comment/types/comment.types";
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
import { currentUserAtom } from "@/features/user/atoms/current-user-atom.ts";
|
import { currentUserAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
||||||
|
|
||||||
interface CommentListItemProps {
|
interface CommentListItemProps {
|
||||||
comment: IComment;
|
comment: IComment;
|
||||||
|
pageId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function CommentListItem({ comment }: CommentListItemProps) {
|
function CommentListItem({ comment, pageId }: CommentListItemProps) {
|
||||||
const { hovered, ref } = useHover();
|
const { hovered, ref } = useHover();
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@ -29,6 +31,11 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
const updateCommentMutation = useUpdateCommentMutation();
|
const updateCommentMutation = useUpdateCommentMutation();
|
||||||
const deleteCommentMutation = useDeleteCommentMutation(comment.pageId);
|
const deleteCommentMutation = useDeleteCommentMutation(comment.pageId);
|
||||||
const [currentUser] = useAtom(currentUserAtom);
|
const [currentUser] = useAtom(currentUserAtom);
|
||||||
|
const emit = useQueryEmit();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setContent(comment.content)
|
||||||
|
}, [comment]);
|
||||||
|
|
||||||
async function handleUpdateComment() {
|
async function handleUpdateComment() {
|
||||||
try {
|
try {
|
||||||
@ -39,6 +46,11 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
};
|
};
|
||||||
await updateCommentMutation.mutateAsync(commentToUpdate);
|
await updateCommentMutation.mutateAsync(commentToUpdate);
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
|
|
||||||
|
emit({
|
||||||
|
operation: "invalidateComment",
|
||||||
|
pageId: pageId,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update comment:", error);
|
console.error("Failed to update comment:", error);
|
||||||
} finally {
|
} finally {
|
||||||
@ -50,11 +62,27 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
try {
|
try {
|
||||||
await deleteCommentMutation.mutateAsync(comment.id);
|
await deleteCommentMutation.mutateAsync(comment.id);
|
||||||
editor?.commands.unsetComment(comment.id);
|
editor?.commands.unsetComment(comment.id);
|
||||||
|
|
||||||
|
emit({
|
||||||
|
operation: "invalidateComment",
|
||||||
|
pageId: pageId,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to delete comment:", error);
|
console.error("Failed to delete comment:", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleCommentClick(comment: IComment) {
|
||||||
|
const el = document.querySelector(`.comment-mark[data-comment-id="${comment.id}"]`);
|
||||||
|
if (el) {
|
||||||
|
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
el.classList.add("comment-highlight");
|
||||||
|
setTimeout(() => {
|
||||||
|
el.classList.remove("comment-highlight");
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleEditToggle() {
|
function handleEditToggle() {
|
||||||
setIsEditing(true);
|
setIsEditing(true);
|
||||||
}
|
}
|
||||||
@ -99,7 +127,7 @@ function CommentListItem({ comment }: CommentListItemProps) {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
{!comment.parentCommentId && comment?.selection && (
|
{!comment.parentCommentId && comment?.selection && (
|
||||||
<Box className={classes.textSelection}>
|
<Box className={classes.textSelection} onClick={() => handleCommentClick(comment)}>
|
||||||
<Text size="sm">{comment?.selection}</Text>
|
<Text size="sm">{comment?.selection}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
@ -112,6 +140,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}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { usePageQuery } from "@/features/page/queries/page-query.ts";
|
|||||||
import { IPagination } from "@/lib/types.ts";
|
import { IPagination } from "@/lib/types.ts";
|
||||||
import { extractPageSlugId } from "@/lib";
|
import { extractPageSlugId } from "@/lib";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
||||||
|
|
||||||
function CommentList() {
|
function CommentList() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -26,6 +27,7 @@ function CommentList() {
|
|||||||
} = useCommentsQuery({ pageId: page?.id, limit: 100 });
|
} = useCommentsQuery({ pageId: page?.id, limit: 100 });
|
||||||
const createCommentMutation = useCreateCommentMutation();
|
const createCommentMutation = useCreateCommentMutation();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const emit = useQueryEmit();
|
||||||
|
|
||||||
const handleAddReply = useCallback(
|
const handleAddReply = useCallback(
|
||||||
async (commentId: string, content: string) => {
|
async (commentId: string, content: string) => {
|
||||||
@ -38,6 +40,11 @@ function CommentList() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await createCommentMutation.mutateAsync(commentData);
|
await createCommentMutation.mutateAsync(commentData);
|
||||||
|
|
||||||
|
emit({
|
||||||
|
operation: "invalidateComment",
|
||||||
|
pageId: page?.id,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to post comment:", error);
|
console.error("Failed to post comment:", error);
|
||||||
} finally {
|
} finally {
|
||||||
@ -59,8 +66,8 @@ function CommentList() {
|
|||||||
data-comment-id={comment.id}
|
data-comment-id={comment.id}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<CommentListItem comment={comment} />
|
<CommentListItem comment={comment} pageId={page?.id} />
|
||||||
<MemoizedChildComments comments={comments} parentId={comment.id} />
|
<MemoizedChildComments comments={comments} parentId={comment.id} pageId={page?.id} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Divider my={4} />
|
<Divider my={4} />
|
||||||
@ -99,8 +106,9 @@ function CommentList() {
|
|||||||
interface ChildCommentsProps {
|
interface ChildCommentsProps {
|
||||||
comments: IPagination<IComment>;
|
comments: IPagination<IComment>;
|
||||||
parentId: string;
|
parentId: string;
|
||||||
|
pageId: string;
|
||||||
}
|
}
|
||||||
const ChildComments = ({ comments, parentId }: ChildCommentsProps) => {
|
const ChildComments = ({ comments, parentId, pageId }: ChildCommentsProps) => {
|
||||||
const getChildComments = useCallback(
|
const getChildComments = useCallback(
|
||||||
(parentId: string) =>
|
(parentId: string) =>
|
||||||
comments.items.filter(
|
comments.items.filter(
|
||||||
@ -113,10 +121,11 @@ const ChildComments = ({ comments, parentId }: ChildCommentsProps) => {
|
|||||||
<div>
|
<div>
|
||||||
{getChildComments(parentId).map((childComment) => (
|
{getChildComments(parentId).map((childComment) => (
|
||||||
<div key={childComment.id}>
|
<div key={childComment.id}>
|
||||||
<CommentListItem comment={childComment} />
|
<CommentListItem comment={childComment} pageId={pageId} />
|
||||||
<MemoizedChildComments
|
<MemoizedChildComments
|
||||||
comments={comments}
|
comments={comments}
|
||||||
parentId={childComment.id}
|
parentId={childComment.id}
|
||||||
|
pageId={pageId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@ -142,6 +151,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} />}
|
||||||
|
|||||||
@ -11,22 +11,25 @@
|
|||||||
border-left: 2px solid var(--mantine-color-gray-6);
|
border-left: 2px solid var(--mantine-color-gray-6);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
background: var(--mantine-color-gray-light);
|
background: var(--mantine-color-gray-light);
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.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: {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
@ -18,7 +19,7 @@ import {
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import classes from "./mention.module.css";
|
import classes from "./mention.module.css";
|
||||||
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
import { IconFileDescription } from "@tabler/icons-react";
|
import { IconFileDescription, IconPlus } from "@tabler/icons-react";
|
||||||
import { useSpaceQuery } from "@/features/space/queries/space-query.ts";
|
import { useSpaceQuery } from "@/features/space/queries/space-query.ts";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { v7 as uuid7 } from "uuid";
|
import { v7 as uuid7 } from "uuid";
|
||||||
@ -28,14 +29,28 @@ import {
|
|||||||
MentionListProps,
|
MentionListProps,
|
||||||
MentionSuggestionItem,
|
MentionSuggestionItem,
|
||||||
} from "@/features/editor/components/mention/mention.type.ts";
|
} from "@/features/editor/components/mention/mention.type.ts";
|
||||||
|
import { IPage } from "@/features/page/types/page.types";
|
||||||
|
import { useCreatePageMutation, usePageQuery } from "@/features/page/queries/page-query";
|
||||||
|
import { treeDataAtom } from "@/features/page/tree/atoms/tree-data-atom";
|
||||||
|
import { SimpleTree } from "react-arborist";
|
||||||
|
import { SpaceTreeNode } from "@/features/page/tree/types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useQueryEmit } from "@/features/websocket/use-query-emit";
|
||||||
|
import { extractPageSlugId } from "@/lib";
|
||||||
|
|
||||||
const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
||||||
const [selectedIndex, setSelectedIndex] = useState(1);
|
const [selectedIndex, setSelectedIndex] = useState(1);
|
||||||
const viewportRef = useRef<HTMLDivElement>(null);
|
const viewportRef = useRef<HTMLDivElement>(null);
|
||||||
const { spaceSlug } = useParams();
|
const { pageSlug, spaceSlug } = useParams();
|
||||||
|
const { data: page } = usePageQuery({ pageId: extractPageSlugId(pageSlug) });
|
||||||
const { data: space } = useSpaceQuery(spaceSlug);
|
const { data: space } = useSpaceQuery(spaceSlug);
|
||||||
const [currentUser] = useAtom(currentUserAtom);
|
const [currentUser] = useAtom(currentUserAtom);
|
||||||
const [renderItems, setRenderItems] = useState<MentionSuggestionItem[]>([]);
|
const [renderItems, setRenderItems] = useState<MentionSuggestionItem[]>([]);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [data, setData] = useAtom(treeDataAtom);
|
||||||
|
const tree = useMemo(() => new SimpleTree<SpaceTreeNode>(data), [data]);
|
||||||
|
const createPageMutation = useCreatePageMutation();
|
||||||
|
const emit = useQueryEmit();
|
||||||
|
|
||||||
const { data: suggestion, isLoading } = useSearchSuggestionsQuery({
|
const { data: suggestion, isLoading } = useSearchSuggestionsQuery({
|
||||||
query: props.query,
|
query: props.query,
|
||||||
@ -45,12 +60,23 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
limit: 10,
|
limit: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const createPageItem = (label: string) : MentionSuggestionItem => {
|
||||||
|
return {
|
||||||
|
id: null,
|
||||||
|
label: label,
|
||||||
|
entityType: "page",
|
||||||
|
entityId: null,
|
||||||
|
slugId: null,
|
||||||
|
icon: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (suggestion && !isLoading) {
|
if (suggestion && !isLoading) {
|
||||||
let items: MentionSuggestionItem[] = [];
|
let items: MentionSuggestionItem[] = [];
|
||||||
|
|
||||||
if (suggestion?.users?.length > 0) {
|
if (suggestion?.users?.length > 0) {
|
||||||
items.push({ entityType: "header", label: "Users" });
|
items.push({ entityType: "header", label: t("Users") });
|
||||||
|
|
||||||
items = items.concat(
|
items = items.concat(
|
||||||
suggestion.users.map((user) => ({
|
suggestion.users.map((user) => ({
|
||||||
@ -64,7 +90,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (suggestion?.pages?.length > 0) {
|
if (suggestion?.pages?.length > 0) {
|
||||||
items.push({ entityType: "header", label: "Pages" });
|
items.push({ entityType: "header", label: t("Pages") });
|
||||||
items = items.concat(
|
items = items.concat(
|
||||||
suggestion.pages.map((page) => ({
|
suggestion.pages.map((page) => ({
|
||||||
id: uuid7(),
|
id: uuid7(),
|
||||||
@ -76,6 +102,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
items.push(createPageItem(props.query));
|
||||||
|
|
||||||
setRenderItems(items);
|
setRenderItems(items);
|
||||||
// update editor storage
|
// update editor storage
|
||||||
@ -96,7 +123,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
creatorId: currentUser?.user.id,
|
creatorId: currentUser?.user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (item.entityType === "page") {
|
if (item.entityType === "page" && item.id!==null) {
|
||||||
props.command({
|
props.command({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
label: item.label || "Untitled",
|
label: item.label || "Untitled",
|
||||||
@ -106,6 +133,9 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
creatorId: currentUser?.user.id,
|
creatorId: currentUser?.user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (item.entityType === "page" && item.id===null) {
|
||||||
|
createPage(item.label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[renderItems],
|
[renderItems],
|
||||||
@ -167,6 +197,58 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const createPage = async (title: string) => {
|
||||||
|
const payload: { spaceId: string; parentPageId?: string; title: string } = {
|
||||||
|
spaceId: space.id,
|
||||||
|
parentPageId: page.id || null,
|
||||||
|
title: title
|
||||||
|
};
|
||||||
|
|
||||||
|
let createdPage: IPage;
|
||||||
|
try {
|
||||||
|
createdPage = await createPageMutation.mutateAsync(payload);
|
||||||
|
const parentId = page.id || null;
|
||||||
|
const data = {
|
||||||
|
id: createdPage.id,
|
||||||
|
slugId: createdPage.slugId,
|
||||||
|
name: createdPage.title,
|
||||||
|
position: createdPage.position,
|
||||||
|
spaceId: createdPage.spaceId,
|
||||||
|
parentPageId: createdPage.parentPageId,
|
||||||
|
children: [],
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
const lastIndex = tree.data.length;
|
||||||
|
|
||||||
|
tree.create({ parentId, index: lastIndex, data });
|
||||||
|
setData(tree.data);
|
||||||
|
|
||||||
|
props.command({
|
||||||
|
id: uuid7(),
|
||||||
|
label: createdPage.title || "Untitled",
|
||||||
|
entityType: "page",
|
||||||
|
entityId: createdPage.id,
|
||||||
|
slugId: createdPage.slugId,
|
||||||
|
creatorId: currentUser?.user.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
emit({
|
||||||
|
operation: "addTreeNode",
|
||||||
|
spaceId: space.id,
|
||||||
|
payload: {
|
||||||
|
parentId,
|
||||||
|
index: lastIndex,
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error("Failed to create page");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if no results and enter what to do?
|
// if no results and enter what to do?
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -178,7 +260,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
if (renderItems.length === 0) {
|
if (renderItems.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Paper shadow="md" p="xs" withBorder>
|
<Paper shadow="md" p="xs" withBorder>
|
||||||
No results
|
{ t("No results") }
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -248,14 +330,14 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
color="gray"
|
color="gray"
|
||||||
size={18}
|
size={18}
|
||||||
>
|
>
|
||||||
<IconFileDescription size={18} />
|
{ (item.id) ? <IconFileDescription size={18} /> : <IconPlus size={18} /> }
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
)}
|
)}
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
|
|
||||||
<div style={{ flex: 1 }}>
|
<div style={{ flex: 1 }}>
|
||||||
<Text size="sm" fw={500}>
|
<Text size="sm" fw={500}>
|
||||||
{item.label}
|
{ (item.id) ? item.label : t("Create page") + ': ' + item.label }
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@ -58,6 +58,7 @@ import ExcalidrawView from "@/features/editor/components/excalidraw/excalidraw-v
|
|||||||
import EmbedView from "@/features/editor/components/embed/embed-view.tsx";
|
import EmbedView from "@/features/editor/components/embed/embed-view.tsx";
|
||||||
import plaintext from "highlight.js/lib/languages/plaintext";
|
import plaintext from "highlight.js/lib/languages/plaintext";
|
||||||
import powershell from "highlight.js/lib/languages/powershell";
|
import powershell from "highlight.js/lib/languages/powershell";
|
||||||
|
import abap from "highlightjs-sap-abap";
|
||||||
import elixir from "highlight.js/lib/languages/elixir";
|
import elixir from "highlight.js/lib/languages/elixir";
|
||||||
import erlang from "highlight.js/lib/languages/erlang";
|
import erlang from "highlight.js/lib/languages/erlang";
|
||||||
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
||||||
@ -76,7 +77,7 @@ import { CharacterCount } from "@tiptap/extension-character-count";
|
|||||||
const lowlight = createLowlight(common);
|
const lowlight = createLowlight(common);
|
||||||
lowlight.register("mermaid", plaintext);
|
lowlight.register("mermaid", plaintext);
|
||||||
lowlight.register("powershell", powershell);
|
lowlight.register("powershell", powershell);
|
||||||
lowlight.register("powershell", powershell);
|
lowlight.register("abap", abap);
|
||||||
lowlight.register("erlang", erlang);
|
lowlight.register("erlang", erlang);
|
||||||
lowlight.register("elixir", elixir);
|
lowlight.register("elixir", elixir);
|
||||||
lowlight.register("dockerfile", dockerfile);
|
lowlight.register("dockerfile", dockerfile);
|
||||||
|
|||||||
@ -219,9 +219,12 @@ export default function PageEditor({
|
|||||||
setActiveCommentId(commentId);
|
setActiveCommentId(commentId);
|
||||||
setAsideState({ tab: "comments", isAsideOpen: true });
|
setAsideState({ tab: "comments", isAsideOpen: true });
|
||||||
|
|
||||||
const selector = `div[data-comment-id="${commentId}"]`;
|
//wait if aside is closed
|
||||||
const commentElement = document.querySelector(selector);
|
setTimeout(() => {
|
||||||
commentElement?.scrollIntoView();
|
const selector = `div[data-comment-id="${commentId}"]`;
|
||||||
|
const commentElement = document.querySelector(selector);
|
||||||
|
commentElement?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
|
}, 400);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -144,6 +144,19 @@
|
|||||||
border-bottom: 2px solid rgb(166, 158, 12);
|
border-bottom: 2px solid rgb(166, 158, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.comment-highlight {
|
||||||
|
animation: flash-highlight 3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes flash-highlight {
|
||||||
|
0% {
|
||||||
|
background-color: #ff4d4d;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background-color: rgba(255, 215, 0, 0.14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.resize-cursor {
|
.resize-cursor {
|
||||||
cursor: ew-resize;
|
cursor: ew-resize;
|
||||||
cursor: col-resize;
|
cursor: col-resize;
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
.column-resize-handle {
|
.column-resize-handle {
|
||||||
background-color: #adf;
|
background-color: #adf;
|
||||||
bottom: -2px;
|
bottom: -1px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: -2px;
|
right: -2px;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import {
|
|||||||
pageEditorAtom,
|
pageEditorAtom,
|
||||||
titleEditorAtom,
|
titleEditorAtom,
|
||||||
} from "@/features/editor/atoms/editor-atoms";
|
} from "@/features/editor/atoms/editor-atoms";
|
||||||
import { useUpdatePageMutation } from "@/features/page/queries/page-query";
|
import { updatePageData, useUpdateTitlePageMutation } from "@/features/page/queries/page-query";
|
||||||
import { useDebouncedCallback } from "@mantine/hooks";
|
import { useDebouncedCallback } from "@mantine/hooks";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
|
import { useQueryEmit } from "@/features/websocket/use-query-emit.ts";
|
||||||
@ -38,7 +38,7 @@ export function TitleEditor({
|
|||||||
editable,
|
editable,
|
||||||
}: TitleEditorProps) {
|
}: TitleEditorProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { mutateAsync: updatePageMutationAsync } = useUpdatePageMutation();
|
const { mutateAsync: updateTitlePageMutationAsync } = useUpdateTitlePageMutation();
|
||||||
const pageEditor = useAtomValue(pageEditorAtom);
|
const pageEditor = useAtomValue(pageEditorAtom);
|
||||||
const [, setTitleEditor] = useAtom(titleEditorAtom);
|
const [, setTitleEditor] = useAtom(titleEditorAtom);
|
||||||
const emit = useQueryEmit();
|
const emit = useQueryEmit();
|
||||||
@ -94,7 +94,7 @@ export function TitleEditor({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePageMutationAsync({
|
updateTitlePageMutationAsync({
|
||||||
pageId: pageId,
|
pageId: pageId,
|
||||||
title: titleEditor.getText(),
|
title: titleEditor.getText(),
|
||||||
}).then((page) => {
|
}).then((page) => {
|
||||||
@ -106,6 +106,10 @@ export function TitleEditor({
|
|||||||
payload: { title: page.title, slugId: page.slugId },
|
payload: { title: page.title, slugId: page.slugId },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (page.title !== titleEditor.getText()) return;
|
||||||
|
|
||||||
|
updatePageData(page);
|
||||||
|
|
||||||
localEmitter.emit("message", event);
|
localEmitter.emit("message", event);
|
||||||
emit(event);
|
emit(event);
|
||||||
});
|
});
|
||||||
|
|||||||
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;
|
||||||
@ -59,7 +59,7 @@ export default function PageHeaderMenu({ readOnly }: PageHeaderMenuProps) {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ShareModal readOnly={readOnly}/>
|
<ShareModal readOnly={readOnly} />
|
||||||
|
|
||||||
<Tooltip label={t("Comments")} openDelay={250} withArrow>
|
<Tooltip label={t("Comments")} openDelay={250} withArrow>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
@ -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}
|
||||||
|
|||||||
@ -63,28 +63,36 @@ export function useCreatePageMutation() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUpdatePageMutation() {
|
export function updatePageData(data: IPage) {
|
||||||
const queryClient = useQueryClient();
|
const pageBySlug = queryClient.getQueryData<IPage>([
|
||||||
|
"pages",
|
||||||
|
data.slugId,
|
||||||
|
]);
|
||||||
|
const pageById = queryClient.getQueryData<IPage>(["pages", data.id]);
|
||||||
|
|
||||||
|
if (pageBySlug) {
|
||||||
|
queryClient.setQueryData(["pages", data.slugId], {
|
||||||
|
...pageBySlug,
|
||||||
|
...data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageById) {
|
||||||
|
queryClient.setQueryData(["pages", data.id], { ...pageById, ...data });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpdateTitlePageMutation() {
|
||||||
|
return useMutation<IPage, Error, Partial<IPageInput>>({
|
||||||
|
mutationFn: (data) => updatePage(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUpdatePageMutation() {
|
||||||
return useMutation<IPage, Error, Partial<IPageInput>>({
|
return useMutation<IPage, Error, Partial<IPageInput>>({
|
||||||
mutationFn: (data) => updatePage(data),
|
mutationFn: (data) => updatePage(data),
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
const pageBySlug = queryClient.getQueryData<IPage>([
|
updatePage(data);
|
||||||
"pages",
|
|
||||||
data.slugId,
|
|
||||||
]);
|
|
||||||
const pageById = queryClient.getQueryData<IPage>(["pages", data.id]);
|
|
||||||
|
|
||||||
if (pageBySlug) {
|
|
||||||
queryClient.setQueryData(["pages", data.slugId], {
|
|
||||||
...pageBySlug,
|
|
||||||
...data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pageById) {
|
|
||||||
queryClient.setQueryData(["pages", data.id], { ...pageById, ...data });
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
16
apps/client/src/features/share/components/share-branding.tsx
Normal file
16
apps/client/src/features/share/components/share-branding.tsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { Affix, Button } from "@mantine/core";
|
||||||
|
|
||||||
|
export default function ShareBranding() {
|
||||||
|
return (
|
||||||
|
<Affix position={{ bottom: 20, right: 20 }}>
|
||||||
|
<Button
|
||||||
|
variant="default"
|
||||||
|
component="a"
|
||||||
|
target="_blank"
|
||||||
|
href="https://docmost.com?ref=public-share"
|
||||||
|
>
|
||||||
|
Powered by Docmost
|
||||||
|
</Button>
|
||||||
|
</Affix>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -36,6 +36,7 @@ import {
|
|||||||
} from "@/features/search/components/search-control.tsx";
|
} from "@/features/search/components/search-control.tsx";
|
||||||
import { ShareSearchSpotlight } from "@/features/search/share-search-spotlight";
|
import { ShareSearchSpotlight } from "@/features/search/share-search-spotlight";
|
||||||
import { shareSearchSpotlight } from "@/features/search/constants";
|
import { shareSearchSpotlight } from "@/features/search/constants";
|
||||||
|
import ShareBranding from '@/features/share/components/share-branding.tsx';
|
||||||
|
|
||||||
const MemoizedSharedTree = React.memo(SharedTree);
|
const MemoizedSharedTree = React.memo(SharedTree);
|
||||||
|
|
||||||
@ -163,16 +164,7 @@ export default function ShareShell({
|
|||||||
<AppShell.Main>
|
<AppShell.Main>
|
||||||
{children}
|
{children}
|
||||||
|
|
||||||
<Affix position={{ bottom: 20, right: 20 }}>
|
{data && shareId && !data.hasLicenseKey && <ShareBranding />}
|
||||||
<Button
|
|
||||||
variant="default"
|
|
||||||
component="a"
|
|
||||||
target="_blank"
|
|
||||||
href="https://docmost.com?ref=public-share"
|
|
||||||
>
|
|
||||||
Powered by Docmost
|
|
||||||
</Button>
|
|
||||||
</Affix>
|
|
||||||
</AppShell.Main>
|
</AppShell.Main>
|
||||||
|
|
||||||
<AppShell.Aside
|
<AppShell.Aside
|
||||||
|
|||||||
@ -41,6 +41,7 @@ export interface ISharedPage extends IShare {
|
|||||||
level: number;
|
level: number;
|
||||||
sharedPage: { id: string; slugId: string; title: string; icon: string };
|
sharedPage: { id: string; slugId: string; title: string; icon: string };
|
||||||
};
|
};
|
||||||
|
hasLicenseKey: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IShareForPage extends IShare {
|
export interface IShareForPage extends IShare {
|
||||||
@ -70,4 +71,5 @@ export interface IShareInfoInput {
|
|||||||
export interface ISharedPageTree {
|
export interface ISharedPageTree {
|
||||||
share: IShare;
|
share: IShare;
|
||||||
pageTree: Partial<IPage[]>;
|
pageTree: Partial<IPage[]>;
|
||||||
|
hasLicenseKey: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,7 +81,7 @@ export function SpaceSelect({
|
|||||||
nothingFoundMessage={t("No space found")}
|
nothingFoundMessage={t("No space found")}
|
||||||
limit={50}
|
limit={50}
|
||||||
checkIconPosition="right"
|
checkIconPosition="right"
|
||||||
comboboxProps={{ width, withinPortal: false }}
|
comboboxProps={{ width, withinPortal: true, position: "bottom" }}
|
||||||
dropdownOpened={opened}
|
dropdownOpened={opened}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -7,6 +7,11 @@ export type InvalidateEvent = {
|
|||||||
id?: string;
|
id?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type InvalidateCommentsEvent = {
|
||||||
|
operation: "invalidateComment";
|
||||||
|
pageId: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type UpdateEvent = {
|
export type UpdateEvent = {
|
||||||
operation: "updateOne";
|
operation: "updateOne";
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
@ -52,4 +57,4 @@ export type DeleteTreeNodeEvent = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WebSocketEvent = InvalidateEvent | UpdateEvent | DeleteEvent | AddTreeNodeEvent | MoveTreeNodeEvent | DeleteTreeNodeEvent;
|
export type WebSocketEvent = InvalidateEvent | InvalidateCommentsEvent | UpdateEvent | DeleteEvent | AddTreeNodeEvent | MoveTreeNodeEvent | DeleteTreeNodeEvent;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { socketAtom } from "@/features/websocket/atoms/socket-atom.ts";
|
|||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { WebSocketEvent } from "@/features/websocket/types";
|
import { WebSocketEvent } from "@/features/websocket/types";
|
||||||
|
import { RQ_KEY } from "../comment/queries/comment-query";
|
||||||
|
|
||||||
export const useQuerySubscription = () => {
|
export const useQuerySubscription = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
@ -21,6 +22,11 @@ export const useQuerySubscription = () => {
|
|||||||
queryKey: [...data.entity, data.id].filter(Boolean),
|
queryKey: [...data.entity, data.id].filter(Boolean),
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "invalidateComment":
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: RQ_KEY(data.pageId),
|
||||||
|
});
|
||||||
|
break;
|
||||||
case "updateOne":
|
case "updateOne":
|
||||||
entity = data.entity[0];
|
entity = data.entity[0];
|
||||||
if (entity === "pages") {
|
if (entity === "pages") {
|
||||||
|
|||||||
@ -7,8 +7,9 @@ import React, { useEffect } from "react";
|
|||||||
import ReadonlyPageEditor from "@/features/editor/readonly-page-editor.tsx";
|
import ReadonlyPageEditor from "@/features/editor/readonly-page-editor.tsx";
|
||||||
import { extractPageSlugId } from "@/lib";
|
import { extractPageSlugId } from "@/lib";
|
||||||
import { Error404 } from "@/components/ui/error-404.tsx";
|
import { Error404 } from "@/components/ui/error-404.tsx";
|
||||||
|
import ShareBranding from "@/features/share/components/share-branding.tsx";
|
||||||
|
|
||||||
export default function SingleSharedPage() {
|
export default function SharedPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { pageSlug } = useParams();
|
const { pageSlug } = useParams();
|
||||||
const { shareId } = useParams();
|
const { shareId } = useParams();
|
||||||
@ -53,6 +54,8 @@ export default function SingleSharedPage() {
|
|||||||
content={data.page.content}
|
content={data.page.content}
|
||||||
/>
|
/>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
|
{data && !shareId && !data.hasLicenseKey && <ShareBranding />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
"version": "0.20.3",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
@ -80,7 +80,9 @@
|
|||||||
"sanitize-filename-ts": "^1.0.2",
|
"sanitize-filename-ts": "^1.0.2",
|
||||||
"socket.io": "^4.8.1",
|
"socket.io": "^4.8.1",
|
||||||
"stripe": "^17.5.0",
|
"stripe": "^17.5.0",
|
||||||
"ws": "^8.18.0"
|
"tmp-promise": "^3.0.3",
|
||||||
|
"ws": "^8.18.0",
|
||||||
|
"yauzl": "^3.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.20.0",
|
"@eslint/js": "^9.20.0",
|
||||||
@ -99,6 +101,7 @@
|
|||||||
"@types/pg": "^8.11.11",
|
"@types/pg": "^8.11.11",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
"@types/ws": "^8.5.14",
|
"@types/ws": "^8.5.14",
|
||||||
|
"@types/yauzl": "^2.10.3",
|
||||||
"eslint": "^9.20.1",
|
"eslint": "^9.20.1",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-config-prettier": "^10.0.1",
|
||||||
"globals": "^15.15.0",
|
"globals": "^15.15.0",
|
||||||
|
|||||||
@ -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> {
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export const tiptapExtensions = [
|
|||||||
codeBlock: false,
|
codeBlock: false,
|
||||||
}),
|
}),
|
||||||
Comment,
|
Comment,
|
||||||
TextAlign,
|
TextAlign.configure({ types: ["heading", "paragraph"] }),
|
||||||
TaskList,
|
TaskList,
|
||||||
TaskItem,
|
TaskItem,
|
||||||
Underline,
|
Underline,
|
||||||
|
|||||||
@ -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 ?? {
|
||||||
@ -107,4 +111,19 @@ 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 {
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|||||||
import { Public } from '../../common/decorators/public.decorator';
|
import { Public } from '../../common/decorators/public.decorator';
|
||||||
import { ShareRepo } from '@docmost/db/repos/share/share.repo';
|
import { ShareRepo } from '@docmost/db/repos/share/share.repo';
|
||||||
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
||||||
|
import { EnvironmentService } from '../../integrations/environment/environment.service';
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('shares')
|
@Controller('shares')
|
||||||
@ -39,6 +40,7 @@ export class ShareController {
|
|||||||
private readonly spaceAbility: SpaceAbilityFactory,
|
private readonly spaceAbility: SpaceAbilityFactory,
|
||||||
private readonly shareRepo: ShareRepo,
|
private readonly shareRepo: ShareRepo,
|
||||||
private readonly pageRepo: PageRepo,
|
private readonly pageRepo: PageRepo,
|
||||||
|
private readonly environmentService: EnvironmentService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@ -61,7 +63,12 @@ export class ShareController {
|
|||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.shareService.getSharedPage(dto, workspace.id);
|
return {
|
||||||
|
...(await this.shareService.getSharedPage(dto, workspace.id)),
|
||||||
|
hasLicenseKey:
|
||||||
|
Boolean(workspace.licenseKey) ||
|
||||||
|
(this.environmentService.isCloud() && workspace.plan === 'business'),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
@ -166,6 +173,11 @@ export class ShareController {
|
|||||||
@Body() dto: ShareIdDto,
|
@Body() dto: ShareIdDto,
|
||||||
@AuthWorkspace() workspace: Workspace,
|
@AuthWorkspace() workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
return this.shareService.getShareTree(dto.shareId, workspace.id);
|
return {
|
||||||
|
...(await this.shareService.getShareTree(dto.shareId, workspace.id)),
|
||||||
|
hasLicenseKey:
|
||||||
|
Boolean(workspace.licenseKey) ||
|
||||||
|
(this.environmentService.isCloud() && workspace.plan === 'business'),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -387,14 +387,14 @@ export class WorkspaceService {
|
|||||||
.replace(/[^a-z0-9]/g, '')
|
.replace(/[^a-z0-9]/g, '')
|
||||||
.substring(0, 20);
|
.substring(0, 20);
|
||||||
// Ensure we leave room for a random suffix.
|
// Ensure we leave room for a random suffix.
|
||||||
const maxSuffixLength = 3;
|
const maxSuffixLength = 6;
|
||||||
|
|
||||||
if (subdomain.length < 4) {
|
if (subdomain.length < 4) {
|
||||||
subdomain = `${subdomain}-${generateRandomSuffix(maxSuffixLength)}`;
|
subdomain = `${subdomain}-${generateRandomSuffix(maxSuffixLength)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DISALLOWED_HOSTNAMES.includes(subdomain)) {
|
if (DISALLOWED_HOSTNAMES.includes(subdomain)) {
|
||||||
subdomain = `myworkspace-${generateRandomSuffix(maxSuffixLength)}`;
|
subdomain = `workspace-${generateRandomSuffix(maxSuffixLength)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uniqueHostname = subdomain;
|
let uniqueHostname = subdomain;
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
await db.schema
|
||||||
|
.createTable('file_tasks')
|
||||||
|
.addColumn('id', 'uuid', (col) =>
|
||||||
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
|
)
|
||||||
|
//type: import or export
|
||||||
|
.addColumn('type', 'varchar', (col) => col)
|
||||||
|
// source - generic, notion, confluence
|
||||||
|
// type or provider?
|
||||||
|
.addColumn('source', 'varchar', (col) => col)
|
||||||
|
// status (enum: PENDING|PROCESSING|SUCCESS|FAILED),
|
||||||
|
.addColumn('status', 'varchar', (col) => col)
|
||||||
|
// file name
|
||||||
|
// file path
|
||||||
|
// file size
|
||||||
|
|
||||||
|
.addColumn('file_name', 'varchar', (col) => col.notNull())
|
||||||
|
.addColumn('file_path', 'varchar', (col) => col.notNull())
|
||||||
|
.addColumn('file_size', 'int8', (col) => col)
|
||||||
|
.addColumn('file_ext', 'varchar', (col) => col)
|
||||||
|
|
||||||
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
|
.addColumn('space_id', 'uuid', (col) =>
|
||||||
|
col.references('spaces.id').onDelete('cascade'),
|
||||||
|
)
|
||||||
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
|
)
|
||||||
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addColumn('completed_at', 'timestamptz', (col) => col)
|
||||||
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
|
await db.schema.dropTable('file_tasks').execute();
|
||||||
|
}
|
||||||
@ -70,7 +70,7 @@ export class UserTokenRepo {
|
|||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
.where('workspaceId', '=', workspaceId)
|
.where('workspaceId', '=', workspaceId)
|
||||||
.where('type', '=', tokenType)
|
.where('type', '=', tokenType)
|
||||||
.orderBy('expiresAt desc')
|
.orderBy('expiresAt', 'desc')
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ export class WorkspaceRepo {
|
|||||||
return await this.db
|
return await this.db
|
||||||
.selectFrom('workspaces')
|
.selectFrom('workspaces')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.orderBy('createdAt asc')
|
.orderBy('createdAt', 'asc')
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
}
|
}
|
||||||
|
|||||||
19
apps/server/src/database/types/db.d.ts
vendored
19
apps/server/src/database/types/db.d.ts
vendored
@ -122,6 +122,24 @@ export interface Comments {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FileTasks {
|
||||||
|
completedAt: Timestamp | null;
|
||||||
|
createdAt: Generated<Timestamp>;
|
||||||
|
creatorId: string | null;
|
||||||
|
deletedAt: Timestamp | null;
|
||||||
|
fileExt: string | null;
|
||||||
|
fileName: string;
|
||||||
|
filePath: string;
|
||||||
|
fileSize: Int8 | null;
|
||||||
|
id: Generated<string>;
|
||||||
|
source: string | null;
|
||||||
|
spaceId: string | null;
|
||||||
|
status: string | null;
|
||||||
|
type: string | null;
|
||||||
|
updatedAt: Generated<Timestamp>;
|
||||||
|
workspaceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Groups {
|
export interface Groups {
|
||||||
createdAt: Generated<Timestamp>;
|
createdAt: Generated<Timestamp>;
|
||||||
creatorId: string | null;
|
creatorId: string | null;
|
||||||
@ -298,6 +316,7 @@ export interface DB {
|
|||||||
backlinks: Backlinks;
|
backlinks: Backlinks;
|
||||||
billing: Billing;
|
billing: Billing;
|
||||||
comments: Comments;
|
comments: Comments;
|
||||||
|
fileTasks: FileTasks;
|
||||||
groups: Groups;
|
groups: Groups;
|
||||||
groupUsers: GroupUsers;
|
groupUsers: GroupUsers;
|
||||||
pageHistory: PageHistory;
|
pageHistory: PageHistory;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
AuthProviders,
|
AuthProviders,
|
||||||
AuthAccounts,
|
AuthAccounts,
|
||||||
Shares,
|
Shares,
|
||||||
|
FileTasks,
|
||||||
} from './db';
|
} from './db';
|
||||||
|
|
||||||
// Workspace
|
// Workspace
|
||||||
@ -107,3 +108,8 @@ export type UpdatableAuthAccount = Updateable<Omit<AuthAccounts, 'id'>>;
|
|||||||
export type Share = Selectable<Shares>;
|
export type Share = Selectable<Shares>;
|
||||||
export type InsertableShare = Insertable<Shares>;
|
export type InsertableShare = Insertable<Shares>;
|
||||||
export type UpdatableShare = Updateable<Omit<Shares, 'id'>>;
|
export type UpdatableShare = Updateable<Omit<Shares, 'id'>>;
|
||||||
|
|
||||||
|
// File Task
|
||||||
|
export type FileTask = Selectable<FileTasks>;
|
||||||
|
export type InsertableFileTask = Insertable<FileTasks>;
|
||||||
|
export type UpdatableFileTask = Updateable<Omit<FileTasks, 'id'>>;
|
||||||
|
|||||||
Submodule apps/server/src/ee updated: 4e7319ab01...b312008b4b
225
apps/server/src/integrations/import/file-task.service.ts
Normal file
225
apps/server/src/integrations/import/file-task.service.ts
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { jsonToText } from '../../collaboration/collaboration.util';
|
||||||
|
import { InjectKysely } from 'nestjs-kysely';
|
||||||
|
import { KyselyDB } from '@docmost/db/types/kysely.types';
|
||||||
|
import { extractZip, FileTaskStatus } from './file.utils';
|
||||||
|
import { StorageService } from '../storage/storage.service';
|
||||||
|
import * as tmp from 'tmp-promise';
|
||||||
|
import { pipeline } from 'node:stream/promises';
|
||||||
|
import { createWriteStream } from 'node:fs';
|
||||||
|
import { ImportService } from './import.service';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import { generateSlugId } from '../../common/helpers';
|
||||||
|
import { v7 } from 'uuid';
|
||||||
|
import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
|
||||||
|
import { FileTask, InsertablePage } from '@docmost/db/types/entity.types';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class FileTaskService {
|
||||||
|
private readonly logger = new Logger(FileTaskService.name);
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly storageService: StorageService,
|
||||||
|
private readonly importService: ImportService,
|
||||||
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async processZIpImport(fileTaskId: string): Promise<void> {
|
||||||
|
const fileTask = await this.db
|
||||||
|
.selectFrom('fileTasks')
|
||||||
|
.selectAll()
|
||||||
|
.where('id', '=', fileTaskId)
|
||||||
|
.executeTakeFirst();
|
||||||
|
|
||||||
|
if (!fileTask) {
|
||||||
|
this.logger.log(`File task with ID ${fileTaskId} not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { path: tmpZipPath, cleanup: cleanupTmpFile } = await tmp.file({
|
||||||
|
prefix: 'docmost-import',
|
||||||
|
postfix: '.zip',
|
||||||
|
discardDescriptor: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { path: tmpExtractDir, cleanup: cleanupTmpDir } = await tmp.dir({
|
||||||
|
prefix: 'docmost-extract-',
|
||||||
|
unsafeCleanup: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileStream = await this.storageService.readStream(fileTask.filePath);
|
||||||
|
await pipeline(fileStream, createWriteStream(tmpZipPath));
|
||||||
|
|
||||||
|
await extractZip(tmpZipPath, tmpExtractDir);
|
||||||
|
|
||||||
|
// TODO: internal link mentions, backlinks, attachments
|
||||||
|
try {
|
||||||
|
await this.updateTaskStatus(fileTaskId, FileTaskStatus.Processing);
|
||||||
|
|
||||||
|
await this.processGenericImport({ extractDir: tmpExtractDir, fileTask });
|
||||||
|
await this.updateTaskStatus(fileTaskId, FileTaskStatus.Success);
|
||||||
|
} catch (error) {
|
||||||
|
await this.updateTaskStatus(fileTaskId, FileTaskStatus.Failed);
|
||||||
|
} finally {
|
||||||
|
await cleanupTmpFile();
|
||||||
|
await cleanupTmpDir();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async processGenericImport(opts: {
|
||||||
|
extractDir: string;
|
||||||
|
fileTask: FileTask;
|
||||||
|
}): Promise<void> {
|
||||||
|
const { extractDir, fileTask } = opts;
|
||||||
|
|
||||||
|
const allFiles = await this.collectMarkdownAndHtmlFiles(extractDir);
|
||||||
|
|
||||||
|
const pagesMap = new Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
slugId: string;
|
||||||
|
name: string;
|
||||||
|
content: string;
|
||||||
|
position?: string | null;
|
||||||
|
parentPageId: string | null;
|
||||||
|
fileExtension: string;
|
||||||
|
filePath: string;
|
||||||
|
}
|
||||||
|
>();
|
||||||
|
|
||||||
|
for (const absPath of allFiles) {
|
||||||
|
const relPath = path
|
||||||
|
.relative(extractDir, absPath)
|
||||||
|
.split(path.sep)
|
||||||
|
.join('/'); // normalize to forward-slashes
|
||||||
|
const ext = path.extname(relPath).toLowerCase();
|
||||||
|
const content = await fs.readFile(absPath, 'utf-8');
|
||||||
|
|
||||||
|
pagesMap.set(relPath, {
|
||||||
|
id: v7(),
|
||||||
|
slugId: generateSlugId(),
|
||||||
|
name: path.basename(relPath, ext),
|
||||||
|
content,
|
||||||
|
parentPageId: null,
|
||||||
|
fileExtension: ext,
|
||||||
|
filePath: relPath,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// parent/child linking
|
||||||
|
pagesMap.forEach((page, filePath) => {
|
||||||
|
const segments = filePath.split('/');
|
||||||
|
segments.pop();
|
||||||
|
let parentPage = null;
|
||||||
|
while (segments.length) {
|
||||||
|
const tryMd = segments.join('/') + '.md';
|
||||||
|
const tryHtml = segments.join('/') + '.html';
|
||||||
|
if (pagesMap.has(tryMd)) {
|
||||||
|
parentPage = pagesMap.get(tryMd)!;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pagesMap.has(tryHtml)) {
|
||||||
|
parentPage = pagesMap.get(tryHtml)!;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
segments.pop();
|
||||||
|
}
|
||||||
|
if (parentPage) page.parentPageId = parentPage.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
// generate position keys
|
||||||
|
const siblingsMap = new Map<string | null, typeof Array.prototype>();
|
||||||
|
pagesMap.forEach((page) => {
|
||||||
|
const sibs = siblingsMap.get(page.parentPageId) || [];
|
||||||
|
sibs.push(page);
|
||||||
|
siblingsMap.set(page.parentPageId, sibs);
|
||||||
|
});
|
||||||
|
siblingsMap.forEach((sibs) => {
|
||||||
|
sibs.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
let prevPos: string | null = null;
|
||||||
|
for (const page of sibs) {
|
||||||
|
page.position = generateJitteredKeyBetween(prevPos, null);
|
||||||
|
prevPos = page.position;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const filePathToPageMetaMap = new Map<
|
||||||
|
string,
|
||||||
|
{ id: string; title: string; slugId: string }
|
||||||
|
>();
|
||||||
|
pagesMap.forEach((page) => {
|
||||||
|
filePathToPageMetaMap.set(page.filePath, {
|
||||||
|
id: page.id,
|
||||||
|
title: page.name,
|
||||||
|
slugId: page.slugId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const insertablePages: InsertablePage[] = await Promise.all(
|
||||||
|
Array.from(pagesMap.values()).map(async (page) => {
|
||||||
|
const pmState = await this.importService.markdownOrHtmlToProsemirror(
|
||||||
|
page.content,
|
||||||
|
page.fileExtension,
|
||||||
|
);
|
||||||
|
const { title, prosemirrorJson } =
|
||||||
|
this.importService.extractTitleAndRemoveHeading(pmState);
|
||||||
|
|
||||||
|
/*const rewDoc =
|
||||||
|
await this.importService.convertInternalLinksToMentionsPM(
|
||||||
|
jsonToNode(prosemirrorJson),
|
||||||
|
page.filePath,
|
||||||
|
filePathToPageMetaMap,
|
||||||
|
);*/
|
||||||
|
const proseJson = prosemirrorJson; //rewDoc.toJSON();
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: page.id,
|
||||||
|
slugId: page.slugId,
|
||||||
|
title: title || page.name,
|
||||||
|
content: proseJson,
|
||||||
|
textContent: jsonToText(proseJson),
|
||||||
|
ydoc: await this.importService.createYdoc(proseJson),
|
||||||
|
position: page.position!,
|
||||||
|
spaceId: fileTask.spaceId,
|
||||||
|
workspaceId: fileTask.workspaceId,
|
||||||
|
creatorId: fileTask.creatorId,
|
||||||
|
lastUpdatedById: fileTask.creatorId,
|
||||||
|
parentPageId: page.parentPageId,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.db.insertInto('pages').values(insertablePages).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
async collectMarkdownAndHtmlFiles(dir: string): Promise<string[]> {
|
||||||
|
const results: string[] = [];
|
||||||
|
|
||||||
|
async function walk(current: string) {
|
||||||
|
const entries = await fs.readdir(current, { withFileTypes: true });
|
||||||
|
for (const ent of entries) {
|
||||||
|
const fullPath = path.join(current, ent.name);
|
||||||
|
if (ent.isDirectory()) {
|
||||||
|
await walk(fullPath);
|
||||||
|
} else if (
|
||||||
|
['.md', '.html'].includes(path.extname(ent.name).toLowerCase())
|
||||||
|
) {
|
||||||
|
results.push(fullPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await walk(dir);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateTaskStatus(fileTaskId: string, status: FileTaskStatus) {
|
||||||
|
await this.db
|
||||||
|
.updateTable('fileTasks')
|
||||||
|
.set({ status: status })
|
||||||
|
.where('id', '=', fileTaskId)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
77
apps/server/src/integrations/import/file.utils.ts
Normal file
77
apps/server/src/integrations/import/file.utils.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import * as yauzl from 'yauzl';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'node:fs';
|
||||||
|
|
||||||
|
export enum FileTaskType {
|
||||||
|
Import = 'import',
|
||||||
|
Export = 'export',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum FileImportType {
|
||||||
|
Generic = 'generic',
|
||||||
|
Notion = 'notion',
|
||||||
|
Confluence = 'confluence',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum FileTaskStatus {
|
||||||
|
Pending = 'pending',
|
||||||
|
Processing = 'processing',
|
||||||
|
Success = 'success',
|
||||||
|
Failed = 'failed',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFileTaskFolderPath(
|
||||||
|
type: FileTaskType,
|
||||||
|
workspaceId: string,
|
||||||
|
): string {
|
||||||
|
switch (type) {
|
||||||
|
case FileTaskType.Import:
|
||||||
|
return `${workspaceId}/imports`;
|
||||||
|
case FileTaskType.Export:
|
||||||
|
return `${workspaceId}/exports`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractZip(source: string, target: string) {
|
||||||
|
//https://github.com/Surfer-Org
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
yauzl.open(source, { lazyEntries: true }, (err, zipfile) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
|
||||||
|
zipfile.readEntry();
|
||||||
|
zipfile.on('entry', (entry) => {
|
||||||
|
const fullPath = path.join(target, entry.fileName);
|
||||||
|
const directory = path.dirname(fullPath);
|
||||||
|
|
||||||
|
if (/\/$/.test(entry.fileName)) {
|
||||||
|
// Directory entry
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(fullPath, { recursive: true });
|
||||||
|
zipfile.readEntry();
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// File entry
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(directory, { recursive: true });
|
||||||
|
zipfile.openReadStream(entry, (err, readStream) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
const writeStream = fs.createWriteStream(fullPath);
|
||||||
|
readStream.on('end', () => {
|
||||||
|
writeStream.end();
|
||||||
|
zipfile.readEntry();
|
||||||
|
});
|
||||||
|
readStream.pipe(writeStream);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
zipfile.on('end', resolve);
|
||||||
|
zipfile.on('error', reject);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -83,4 +83,57 @@ export class ImportController {
|
|||||||
|
|
||||||
return this.importService.importPage(file, user.id, spaceId, workspace.id);
|
return this.importService.importPage(file, user.id, spaceId, workspace.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseInterceptors(FileInterceptor)
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
// temporary naming
|
||||||
|
@Post('pages/import-zip')
|
||||||
|
async importZip(
|
||||||
|
@Req() req: any,
|
||||||
|
@AuthUser() user: User,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
|
) {
|
||||||
|
const validFileExtensions = ['.zip'];
|
||||||
|
|
||||||
|
const maxFileSize = bytes('100mb');
|
||||||
|
|
||||||
|
let file = null;
|
||||||
|
try {
|
||||||
|
file = await req.file({
|
||||||
|
limits: { fileSize: maxFileSize, fields: 3, files: 1 },
|
||||||
|
});
|
||||||
|
} catch (err: any) {
|
||||||
|
this.logger.error(err.message);
|
||||||
|
if (err?.statusCode === 413) {
|
||||||
|
throw new BadRequestException(
|
||||||
|
`File too large. Exceeds the 100mb import limit`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
throw new BadRequestException('Failed to upload file');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!validFileExtensions.includes(path.extname(file.filename).toLowerCase())
|
||||||
|
) {
|
||||||
|
throw new BadRequestException('Invalid import file type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const spaceId = file.fields?.spaceId?.value;
|
||||||
|
const source = file.fields?.source?.value;
|
||||||
|
|
||||||
|
if (!spaceId) {
|
||||||
|
throw new BadRequestException('spaceId or format not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const ability = await this.spaceAbility.createForUser(user, spaceId);
|
||||||
|
if (ability.cannot(SpaceCaslAction.Edit, SpaceCaslSubject.Page)) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.importService.importZip(file, source, user.id, spaceId, workspace.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ImportService } from './import.service';
|
import { ImportService } from './import.service';
|
||||||
import { ImportController } from './import.controller';
|
import { ImportController } from './import.controller';
|
||||||
|
import { StorageModule } from '../storage/storage.module';
|
||||||
|
import { FileTaskService } from './file-task.service';
|
||||||
|
import { FileTaskProcessor } from './processors/file-task.processor';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [ImportService],
|
providers: [ImportService, FileTaskService, FileTaskProcessor],
|
||||||
controllers: [ImportController],
|
controllers: [ImportController],
|
||||||
|
imports: [StorageModule],
|
||||||
})
|
})
|
||||||
export class ImportModule {}
|
export class ImportModule {}
|
||||||
|
|||||||
@ -4,7 +4,8 @@ import { MultipartFile } from '@fastify/multipart';
|
|||||||
import { sanitize } from 'sanitize-filename-ts';
|
import { sanitize } from 'sanitize-filename-ts';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {
|
import {
|
||||||
htmlToJson, jsonToText,
|
htmlToJson,
|
||||||
|
jsonToText,
|
||||||
tiptapExtensions,
|
tiptapExtensions,
|
||||||
} from '../../collaboration/collaboration.util';
|
} from '../../collaboration/collaboration.util';
|
||||||
import { InjectKysely } from 'nestjs-kysely';
|
import { InjectKysely } from 'nestjs-kysely';
|
||||||
@ -13,7 +14,20 @@ import { generateSlugId } from '../../common/helpers';
|
|||||||
import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
|
import { generateJitteredKeyBetween } from 'fractional-indexing-jittered';
|
||||||
import { TiptapTransformer } from '@hocuspocus/transformer';
|
import { TiptapTransformer } from '@hocuspocus/transformer';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
import { markdownToHtml } from "@docmost/editor-ext";
|
import { markdownToHtml } from '@docmost/editor-ext';
|
||||||
|
import {
|
||||||
|
FileTaskStatus,
|
||||||
|
FileTaskType,
|
||||||
|
getFileTaskFolderPath,
|
||||||
|
} from './file.utils';
|
||||||
|
import { v7, v7 as uuid7 } from 'uuid';
|
||||||
|
import { StorageService } from '../storage/storage.service';
|
||||||
|
import { InjectQueue } from '@nestjs/bullmq';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import { QueueJob, QueueName } from '../queue/constants';
|
||||||
|
import { Node as PMNode } from '@tiptap/pm/model';
|
||||||
|
import { EditorState, Transaction } from '@tiptap/pm/state';
|
||||||
|
import { getSchema } from '@tiptap/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ImportService {
|
export class ImportService {
|
||||||
@ -21,7 +35,10 @@ export class ImportService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly pageRepo: PageRepo,
|
private readonly pageRepo: PageRepo,
|
||||||
|
private readonly storageService: StorageService,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
|
@InjectQueue(QueueName.FILE_TASK_QUEUE)
|
||||||
|
private readonly fileTaskQueue: Queue,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async importPage(
|
async importPage(
|
||||||
@ -113,7 +130,7 @@ export class ImportService {
|
|||||||
|
|
||||||
async createYdoc(prosemirrorJson: any): Promise<Buffer | null> {
|
async createYdoc(prosemirrorJson: any): Promise<Buffer | null> {
|
||||||
if (prosemirrorJson) {
|
if (prosemirrorJson) {
|
||||||
this.logger.debug(`Converting prosemirror json state to ydoc`);
|
// this.logger.debug(`Converting prosemirror json state to ydoc`);
|
||||||
|
|
||||||
const ydoc = TiptapTransformer.toYdoc(
|
const ydoc = TiptapTransformer.toYdoc(
|
||||||
prosemirrorJson,
|
prosemirrorJson,
|
||||||
@ -161,4 +178,141 @@ export class ImportService {
|
|||||||
return generateJitteredKeyBetween(null, null);
|
return generateJitteredKeyBetween(null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async importZip(
|
||||||
|
filePromise: Promise<MultipartFile>,
|
||||||
|
source: string,
|
||||||
|
userId: string,
|
||||||
|
spaceId: string,
|
||||||
|
workspaceId: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const file = await filePromise;
|
||||||
|
const fileBuffer = await file.toBuffer();
|
||||||
|
const fileExtension = path.extname(file.filename).toLowerCase();
|
||||||
|
const fileName = sanitize(
|
||||||
|
path.basename(file.filename, fileExtension).slice(0, 255),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fileTaskId = uuid7();
|
||||||
|
const filePath = `${getFileTaskFolderPath(FileTaskType.Import, workspaceId)}/${fileTaskId}/${fileName}`;
|
||||||
|
|
||||||
|
// upload file
|
||||||
|
await this.storageService.upload(filePath, fileBuffer);
|
||||||
|
|
||||||
|
// store in fileTasks table
|
||||||
|
await this.db
|
||||||
|
.insertInto('fileTasks')
|
||||||
|
.values({
|
||||||
|
id: fileTaskId,
|
||||||
|
type: FileTaskType.Import,
|
||||||
|
source: source,
|
||||||
|
status: FileTaskStatus.Pending,
|
||||||
|
fileName: fileName,
|
||||||
|
filePath: filePath,
|
||||||
|
fileSize: 0,
|
||||||
|
fileExt: 'zip',
|
||||||
|
creatorId: userId,
|
||||||
|
spaceId: spaceId,
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
// what to send to queue
|
||||||
|
// pass the task ID
|
||||||
|
await this.fileTaskQueue.add(QueueJob.IMPORT_TASK, {
|
||||||
|
fileTaskId: fileTaskId,
|
||||||
|
});
|
||||||
|
// return tasks info
|
||||||
|
|
||||||
|
// when the processor picks it up
|
||||||
|
// we change the status to processing
|
||||||
|
// if it gets processed successfully,
|
||||||
|
// we change the status to success
|
||||||
|
// else failed
|
||||||
|
}
|
||||||
|
|
||||||
|
async markdownOrHtmlToProsemirror(
|
||||||
|
fileContent: string,
|
||||||
|
fileExtension: string,
|
||||||
|
): Promise<any> {
|
||||||
|
let prosemirrorState = '';
|
||||||
|
if (fileExtension === '.md') {
|
||||||
|
prosemirrorState = await this.processMarkdown(fileContent);
|
||||||
|
} else if (fileExtension.endsWith('.html')) {
|
||||||
|
prosemirrorState = await this.processHTML(fileContent);
|
||||||
|
}
|
||||||
|
return prosemirrorState;
|
||||||
|
}
|
||||||
|
|
||||||
|
async convertInternalLinksToMentionsPM(
|
||||||
|
doc: PMNode,
|
||||||
|
currentFilePath: string,
|
||||||
|
filePathToPageMetaMap: Map<
|
||||||
|
string,
|
||||||
|
{ id: string; title: string; slugId: string }
|
||||||
|
>,
|
||||||
|
): Promise<PMNode> {
|
||||||
|
const schema = getSchema(tiptapExtensions);
|
||||||
|
const state = EditorState.create({ doc, schema });
|
||||||
|
let tr: Transaction = state.tr;
|
||||||
|
|
||||||
|
const normalizePath = (p: string) => p.replace(/\\/g, '/');
|
||||||
|
|
||||||
|
// Collect replacements from the original doc.
|
||||||
|
const replacements: Array<{
|
||||||
|
from: number;
|
||||||
|
to: number;
|
||||||
|
mentionNode: PMNode;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
doc.descendants((node, pos) => {
|
||||||
|
if (!node.isText || !node.marks?.length) return;
|
||||||
|
|
||||||
|
// Look for the link mark
|
||||||
|
const linkMark = node.marks.find(
|
||||||
|
(mark) => mark.type.name === 'link' && mark.attrs?.href,
|
||||||
|
);
|
||||||
|
if (!linkMark) return;
|
||||||
|
|
||||||
|
// Compute the range for the entire text node.
|
||||||
|
const from = pos;
|
||||||
|
const to = pos + node.nodeSize;
|
||||||
|
|
||||||
|
// Resolve the path and get page meta.
|
||||||
|
const resolvedPath = normalizePath(
|
||||||
|
path.join(path.dirname(currentFilePath), linkMark.attrs.href),
|
||||||
|
);
|
||||||
|
const pageMeta = filePathToPageMetaMap.get(resolvedPath);
|
||||||
|
if (!pageMeta) return;
|
||||||
|
|
||||||
|
// Create the mention node with all required attributes.
|
||||||
|
const mentionNode = schema.nodes.mention.create({
|
||||||
|
id: v7(),
|
||||||
|
entityType: 'page',
|
||||||
|
entityId: pageMeta.id,
|
||||||
|
label: node.text || pageMeta.title,
|
||||||
|
slugId: pageMeta.slugId,
|
||||||
|
creatorId: 'not available', // This is required per your schema.
|
||||||
|
});
|
||||||
|
|
||||||
|
replacements.push({ from, to, mentionNode });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply replacements in reverse order.
|
||||||
|
for (let i = replacements.length - 1; i >= 0; i--) {
|
||||||
|
const { from, to, mentionNode } = replacements[i];
|
||||||
|
try {
|
||||||
|
tr = tr.replaceWith(from, to, mentionNode);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('❌ Failed to insert mention:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tr.docChanged) {
|
||||||
|
console.log('doc changed');
|
||||||
|
console.log(JSON.stringify(state.apply(tr).doc.toJSON()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the updated document if any change was made.
|
||||||
|
return tr.docChanged ? state.apply(tr).doc : doc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,51 @@
|
|||||||
|
import { Logger, OnModuleDestroy } from '@nestjs/common';
|
||||||
|
import { OnWorkerEvent, Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
|
import { Job } from 'bullmq';
|
||||||
|
import { QueueJob, QueueName } from 'src/integrations/queue/constants';
|
||||||
|
import { FileTaskService } from '../file-task.service';
|
||||||
|
|
||||||
|
@Processor(QueueName.FILE_TASK_QUEUE)
|
||||||
|
export class FileTaskProcessor extends WorkerHost implements OnModuleDestroy {
|
||||||
|
private readonly logger = new Logger(FileTaskProcessor.name);
|
||||||
|
constructor(private readonly fileTaskService: FileTaskService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async process(job: Job<any, void>): Promise<void> {
|
||||||
|
try {
|
||||||
|
switch (job.name) {
|
||||||
|
case QueueJob.IMPORT_TASK:
|
||||||
|
console.log('import task', job.data.fileTaskId);
|
||||||
|
await this.fileTaskService.processZIpImport(job.data.fileTaskId);
|
||||||
|
break;
|
||||||
|
case QueueJob.EXPORT_TASK:
|
||||||
|
console.log('export task', job.data.fileTaskId);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnWorkerEvent('active')
|
||||||
|
onActive(job: Job) {
|
||||||
|
this.logger.debug(`Processing ${job.name} job`);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnWorkerEvent('failed')
|
||||||
|
onError(job: Job) {
|
||||||
|
this.logger.error(
|
||||||
|
`Error processing ${job.name} job. Reason: ${job.failedReason}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnWorkerEvent('completed')
|
||||||
|
onCompleted(job: Job) {
|
||||||
|
this.logger.debug(`Completed ${job.name} job`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onModuleDestroy(): Promise<void> {
|
||||||
|
if (this.worker) {
|
||||||
|
await this.worker.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@ export enum QueueName {
|
|||||||
ATTACHMENT_QUEUE = '{attachment-queue}',
|
ATTACHMENT_QUEUE = '{attachment-queue}',
|
||||||
GENERAL_QUEUE = '{general-queue}',
|
GENERAL_QUEUE = '{general-queue}',
|
||||||
BILLING_QUEUE = '{billing-queue}',
|
BILLING_QUEUE = '{billing-queue}',
|
||||||
|
FILE_TASK_QUEUE = '{file-task-queue}',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum QueueJob {
|
export enum QueueJob {
|
||||||
@ -19,4 +20,7 @@ export enum QueueJob {
|
|||||||
TRIAL_ENDED = 'trial-ended',
|
TRIAL_ENDED = 'trial-ended',
|
||||||
WELCOME_EMAIL = 'welcome-email',
|
WELCOME_EMAIL = 'welcome-email',
|
||||||
FIRST_PAYMENT_EMAIL = 'first-payment-email',
|
FIRST_PAYMENT_EMAIL = 'first-payment-email',
|
||||||
|
|
||||||
|
IMPORT_TASK = 'import-task',
|
||||||
|
EXPORT_TASK = 'export-task',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,6 +49,9 @@ import { BacklinksProcessor } from './processors/backlinks.processor';
|
|||||||
BullModule.registerQueue({
|
BullModule.registerQueue({
|
||||||
name: QueueName.BILLING_QUEUE,
|
name: QueueName.BILLING_QUEUE,
|
||||||
}),
|
}),
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: QueueName.FILE_TASK_QUEUE,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
exports: [BullModule],
|
exports: [BullModule],
|
||||||
providers: [BacklinksProcessor],
|
providers: [BacklinksProcessor],
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import {
|
|||||||
} from '../interfaces';
|
} from '../interfaces';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
import { createReadStream } from 'node:fs';
|
||||||
|
|
||||||
export class LocalDriver implements StorageDriver {
|
export class LocalDriver implements StorageDriver {
|
||||||
private readonly config: LocalStorageConfig;
|
private readonly config: LocalStorageConfig;
|
||||||
@ -25,6 +27,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));
|
||||||
@ -33,6 +45,14 @@ export class LocalDriver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readStream(filePath: string): Promise<Readable> {
|
||||||
|
try {
|
||||||
|
return createReadStream(this._fullPath(filePath));
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to read file: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async exists(filePath: string): Promise<boolean> {
|
async exists(filePath: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
return await fs.pathExists(this._fullPath(filePath));
|
return await fs.pathExists(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({
|
||||||
@ -54,6 +71,21 @@ export class S3Driver implements StorageDriver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readStream(filePath: string): Promise<Readable> {
|
||||||
|
try {
|
||||||
|
const command = new GetObjectCommand({
|
||||||
|
Bucket: this.config.bucket,
|
||||||
|
Key: filePath,
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await this.s3Client.send(command);
|
||||||
|
|
||||||
|
return response.Body as Readable;
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to read file from S3: ${(err as Error).message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async exists(filePath: string): Promise<boolean> {
|
async exists(filePath: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const command = new HeadObjectCommand({
|
const command = new HeadObjectCommand({
|
||||||
|
|||||||
@ -1,8 +1,15 @@
|
|||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
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>;
|
||||||
|
|
||||||
|
readStream(filePath: string): Promise<Readable>;
|
||||||
|
|
||||||
|
|
||||||
exists(filePath: string): Promise<boolean>;
|
exists(filePath: string): Promise<boolean>;
|
||||||
|
|
||||||
getUrl(filePath: string): string;
|
getUrl(filePath: string): string;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||||
import { STORAGE_DRIVER_TOKEN } from './constants/storage.constants';
|
import { STORAGE_DRIVER_TOKEN } from './constants/storage.constants';
|
||||||
import { StorageDriver } from './interfaces';
|
import { StorageDriver } from './interfaces';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class StorageService {
|
export class StorageService {
|
||||||
@ -14,10 +15,19 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readStream(filePath: string): Promise<Readable> {
|
||||||
|
return this.storageDriver.readStream(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
async exists(filePath: string): Promise<boolean> {
|
async exists(filePath: string): Promise<boolean> {
|
||||||
return this.storageDriver.exists(filePath);
|
return this.storageDriver.exists(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.3",
|
"version": "0.20.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nx run-many -t build",
|
"build": "nx run-many -t build",
|
||||||
|
|||||||
50
pnpm-lock.yaml
generated
50
pnpm-lock.yaml
generated
@ -257,6 +257,9 @@ importers:
|
|||||||
file-saver:
|
file-saver:
|
||||||
specifier: ^2.0.5
|
specifier: ^2.0.5
|
||||||
version: 2.0.5
|
version: 2.0.5
|
||||||
|
highlightjs-sap-abap:
|
||||||
|
specifier: ^0.3.0
|
||||||
|
version: 0.3.0
|
||||||
i18next:
|
i18next:
|
||||||
specifier: ^23.14.0
|
specifier: ^23.14.0
|
||||||
version: 23.14.0
|
version: 23.14.0
|
||||||
@ -549,9 +552,15 @@ importers:
|
|||||||
stripe:
|
stripe:
|
||||||
specifier: ^17.5.0
|
specifier: ^17.5.0
|
||||||
version: 17.5.0
|
version: 17.5.0
|
||||||
|
tmp-promise:
|
||||||
|
specifier: ^3.0.3
|
||||||
|
version: 3.0.3
|
||||||
ws:
|
ws:
|
||||||
specifier: ^8.18.0
|
specifier: ^8.18.0
|
||||||
version: 8.18.0
|
version: 8.18.0
|
||||||
|
yauzl:
|
||||||
|
specifier: ^3.2.0
|
||||||
|
version: 3.2.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@eslint/js':
|
'@eslint/js':
|
||||||
specifier: ^9.20.0
|
specifier: ^9.20.0
|
||||||
@ -601,6 +610,9 @@ importers:
|
|||||||
'@types/ws':
|
'@types/ws':
|
||||||
specifier: ^8.5.14
|
specifier: ^8.5.14
|
||||||
version: 8.5.14
|
version: 8.5.14
|
||||||
|
'@types/yauzl':
|
||||||
|
specifier: ^2.10.3
|
||||||
|
version: 2.10.3
|
||||||
eslint:
|
eslint:
|
||||||
specifier: ^9.20.1
|
specifier: ^9.20.1
|
||||||
version: 9.20.1(jiti@1.21.0)
|
version: 9.20.1(jiti@1.21.0)
|
||||||
@ -4090,6 +4102,9 @@ packages:
|
|||||||
'@types/yargs@17.0.32':
|
'@types/yargs@17.0.32':
|
||||||
resolution: {integrity: sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==}
|
resolution: {integrity: sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==}
|
||||||
|
|
||||||
|
'@types/yauzl@2.10.3':
|
||||||
|
resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==}
|
||||||
|
|
||||||
'@typescript-eslint/eslint-plugin@8.17.0':
|
'@typescript-eslint/eslint-plugin@8.17.0':
|
||||||
resolution: {integrity: sha512-HU1KAdW3Tt8zQkdvNoIijfWDMvdSweFYm4hWh+KwhPstv+sCmWb89hCIP8msFm9N1R/ooh9honpSuvqKWlYy3w==}
|
resolution: {integrity: sha512-HU1KAdW3Tt8zQkdvNoIijfWDMvdSweFYm4hWh+KwhPstv+sCmWb89hCIP8msFm9N1R/ooh9honpSuvqKWlYy3w==}
|
||||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||||
@ -4607,6 +4622,9 @@ packages:
|
|||||||
bser@2.1.1:
|
bser@2.1.1:
|
||||||
resolution: {integrity: sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==}
|
resolution: {integrity: sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==}
|
||||||
|
|
||||||
|
buffer-crc32@0.2.13:
|
||||||
|
resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==}
|
||||||
|
|
||||||
buffer-equal-constant-time@1.0.1:
|
buffer-equal-constant-time@1.0.1:
|
||||||
resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==}
|
resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==}
|
||||||
|
|
||||||
@ -5872,6 +5890,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-SYVnVFswQER+zu1laSya563s+F8VDGt7o35d4utbamowvUNLLMovFqwCLSocpZTz3MgaSRA1IbqRWZv97dtErQ==}
|
resolution: {integrity: sha512-SYVnVFswQER+zu1laSya563s+F8VDGt7o35d4utbamowvUNLLMovFqwCLSocpZTz3MgaSRA1IbqRWZv97dtErQ==}
|
||||||
engines: {node: '>=12.0.0'}
|
engines: {node: '>=12.0.0'}
|
||||||
|
|
||||||
|
highlightjs-sap-abap@0.3.0:
|
||||||
|
resolution: {integrity: sha512-nSiUvEOCycjtFA3pHaTowrbAAk5+lciBHyoVkDsd6FTRBtW9sT2dt42o2jAKbXjZVUidtacdk+j0Y2xnd233Mw==}
|
||||||
|
|
||||||
hoist-non-react-statics@3.3.2:
|
hoist-non-react-statics@3.3.2:
|
||||||
resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
|
resolution: {integrity: sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==}
|
||||||
|
|
||||||
@ -7190,6 +7211,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-nri2TO5JE3/mRryik9LlHFT53cgHfRK0Lt0BAZQXku/AW3E6XLt2GaY8siWi7dvW/m1z0ecn+J+bpDa9ZN3IsQ==}
|
resolution: {integrity: sha512-nri2TO5JE3/mRryik9LlHFT53cgHfRK0Lt0BAZQXku/AW3E6XLt2GaY8siWi7dvW/m1z0ecn+J+bpDa9ZN3IsQ==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
|
pend@1.2.0:
|
||||||
|
resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==}
|
||||||
|
|
||||||
pg-cloudflare@1.1.1:
|
pg-cloudflare@1.1.1:
|
||||||
resolution: {integrity: sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==}
|
resolution: {integrity: sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==}
|
||||||
|
|
||||||
@ -8242,6 +8266,9 @@ packages:
|
|||||||
resolution: {integrity: sha512-QNtgIqSUb9o2CoUjX9T5TwaIvUUJFU1+12PJkgt42DFV2yf9J6549yTF2uGloQsJ/JOC8X+gIB81ind97hRiIQ==}
|
resolution: {integrity: sha512-QNtgIqSUb9o2CoUjX9T5TwaIvUUJFU1+12PJkgt42DFV2yf9J6549yTF2uGloQsJ/JOC8X+gIB81ind97hRiIQ==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
tmp-promise@3.0.3:
|
||||||
|
resolution: {integrity: sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==}
|
||||||
|
|
||||||
tmp@0.0.33:
|
tmp@0.0.33:
|
||||||
resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==}
|
resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==}
|
||||||
engines: {node: '>=0.6.0'}
|
engines: {node: '>=0.6.0'}
|
||||||
@ -8898,6 +8925,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
|
resolution: {integrity: sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
|
yauzl@3.2.0:
|
||||||
|
resolution: {integrity: sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
yjs@13.6.20:
|
yjs@13.6.20:
|
||||||
resolution: {integrity: sha512-Z2YZI+SYqK7XdWlloI3lhMiKnCdFCVC4PchpdO+mCYwtiTwncjUbnRK9R1JmkNfdmHyDXuWN3ibJAt0wsqTbLQ==}
|
resolution: {integrity: sha512-Z2YZI+SYqK7XdWlloI3lhMiKnCdFCVC4PchpdO+mCYwtiTwncjUbnRK9R1JmkNfdmHyDXuWN3ibJAt0wsqTbLQ==}
|
||||||
engines: {node: '>=16.0.0', npm: '>=8.0.0'}
|
engines: {node: '>=16.0.0', npm: '>=8.0.0'}
|
||||||
@ -13255,6 +13286,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/yargs-parser': 21.0.3
|
'@types/yargs-parser': 21.0.3
|
||||||
|
|
||||||
|
'@types/yauzl@2.10.3':
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 22.13.4
|
||||||
|
|
||||||
'@typescript-eslint/eslint-plugin@8.17.0(@typescript-eslint/parser@8.17.0(eslint@9.15.0(jiti@1.21.0))(typescript@5.7.2))(eslint@9.15.0(jiti@1.21.0))(typescript@5.7.2)':
|
'@typescript-eslint/eslint-plugin@8.17.0(@typescript-eslint/parser@8.17.0(eslint@9.15.0(jiti@1.21.0))(typescript@5.7.2))(eslint@9.15.0(jiti@1.21.0))(typescript@5.7.2)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@eslint-community/regexpp': 4.12.1
|
'@eslint-community/regexpp': 4.12.1
|
||||||
@ -13953,6 +13988,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
node-int64: 0.4.0
|
node-int64: 0.4.0
|
||||||
|
|
||||||
|
buffer-crc32@0.2.13: {}
|
||||||
|
|
||||||
buffer-equal-constant-time@1.0.1: {}
|
buffer-equal-constant-time@1.0.1: {}
|
||||||
|
|
||||||
buffer-from@1.1.2: {}
|
buffer-from@1.1.2: {}
|
||||||
@ -15436,6 +15473,8 @@ snapshots:
|
|||||||
|
|
||||||
highlight.js@11.10.0: {}
|
highlight.js@11.10.0: {}
|
||||||
|
|
||||||
|
highlightjs-sap-abap@0.3.0: {}
|
||||||
|
|
||||||
hoist-non-react-statics@3.3.2:
|
hoist-non-react-statics@3.3.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
react-is: 16.13.1
|
react-is: 16.13.1
|
||||||
@ -16986,6 +17025,8 @@ snapshots:
|
|||||||
|
|
||||||
peek-readable@7.0.0: {}
|
peek-readable@7.0.0: {}
|
||||||
|
|
||||||
|
pend@1.2.0: {}
|
||||||
|
|
||||||
pg-cloudflare@1.1.1:
|
pg-cloudflare@1.1.1:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
@ -18155,6 +18196,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tldts-core: 6.1.72
|
tldts-core: 6.1.72
|
||||||
|
|
||||||
|
tmp-promise@3.0.3:
|
||||||
|
dependencies:
|
||||||
|
tmp: 0.2.1
|
||||||
|
|
||||||
tmp@0.0.33:
|
tmp@0.0.33:
|
||||||
dependencies:
|
dependencies:
|
||||||
os-tmpdir: 1.0.2
|
os-tmpdir: 1.0.2
|
||||||
@ -18751,6 +18796,11 @@ snapshots:
|
|||||||
y18n: 5.0.8
|
y18n: 5.0.8
|
||||||
yargs-parser: 21.1.1
|
yargs-parser: 21.1.1
|
||||||
|
|
||||||
|
yauzl@3.2.0:
|
||||||
|
dependencies:
|
||||||
|
buffer-crc32: 0.2.13
|
||||||
|
pend: 1.2.0
|
||||||
|
|
||||||
yjs@13.6.20:
|
yjs@13.6.20:
|
||||||
dependencies:
|
dependencies:
|
||||||
lib0: 0.2.98
|
lib0: 0.2.98
|
||||||
|
|||||||
Reference in New Issue
Block a user