diff --git a/packages/client/src/components/data-render/constant.tsx b/packages/client/src/components/data-render/constant.tsx
new file mode 100644
index 0000000..3784785
--- /dev/null
+++ b/packages/client/src/components/data-render/constant.tsx
@@ -0,0 +1,41 @@
+import { Spin, Typography } from '@douyinfe/semi-ui';
+import { Empty } from 'illustrations/empty';
+import React, { useMemo } from 'react';
+
+const { Text } = Typography;
+
+export const defaultLoading = ;
+
+export const defaultRenderError = (error) => {
+ return {(error && error.message) || '未知错误'};
+};
+
+export const defaultEmpty = (
+
+);
+
+export const Render: React.FC<{ fn: ((arg: unknown) => React.ReactNode) | React.ReactNode; args?: unknown[] }> = ({
+ fn,
+ args = [],
+}) => {
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ const content = useMemo(() => (typeof fn === 'function' ? fn.apply(null, ...args) : fn), [args]);
+
+ return <>{content}>;
+};
diff --git a/packages/client/src/components/data-render/index.tsx b/packages/client/src/components/data-render/index.tsx
index 4b3c5e3..db8627e 100644
--- a/packages/client/src/components/data-render/index.tsx
+++ b/packages/client/src/components/data-render/index.tsx
@@ -1,7 +1,6 @@
-import { Spin, Typography } from '@douyinfe/semi-ui';
-import { Empty } from 'illustrations/empty';
import React from 'react';
+import { defaultEmpty, defaultLoading, defaultRenderError, Render } from './constant';
import { LoadingWrap } from './loading';
type RenderProps = React.ReactNode | (() => React.ReactNode);
@@ -16,40 +15,6 @@ interface IProps {
normalContent: RenderProps;
}
-const { Text } = Typography;
-
-const defaultLoading = () => {
- return ;
-};
-
-const defaultRenderError = (error) => {
- return {(error && error.message) || '未知错误'};
-};
-
-const defaultEmpty = () => {
- return (
-
- );
-};
-
-const runRender = (fn, ...args) => (typeof fn === 'function' ? fn(...args) : fn);
-
export const DataRender: React.FC = ({
loading,
error,
@@ -60,19 +25,14 @@ export const DataRender: React.FC = ({
normalContent,
}) => {
if (error) {
- return runRender(errorContent, error);
+ return ;
}
if (empty) {
- return runRender(emptyContent);
+ return ;
}
return (
-
+
);
};
diff --git a/packages/client/src/components/data-render/loading.tsx b/packages/client/src/components/data-render/loading.tsx
index 8940de6..d071d2d 100644
--- a/packages/client/src/components/data-render/loading.tsx
+++ b/packages/client/src/components/data-render/loading.tsx
@@ -1,15 +1,9 @@
import { useToggle } from 'hooks/use-toggle';
import React, { useEffect, useRef } from 'react';
-// interface IProps {
-// loading: boolean;
-// delay?: number;
-// runRender
-// loadingContent: React.ReactElement;
-// normalContent: React.ReactElement;
-// }
+import { Render } from './constant';
-export const LoadingWrap = ({ loading, delay = 200, runRender, loadingContent, normalContent }) => {
+export const LoadingWrap = ({ loading, delay = 200, loadingContent, normalContent }) => {
const timer = useRef>(null);
const [showLoading, toggleShowLoading] = useToggle(false);
@@ -32,8 +26,8 @@ export const LoadingWrap = ({ loading, delay = 200, runRender, loadingContent, n
}, [delay, loading, toggleShowLoading]);
if (loading) {
- return showLoading ? runRender(loadingContent) : null;
+ return showLoading ? : null;
}
- return runRender(normalContent);
+ return ;
};
diff --git a/packages/client/src/components/document/editor/index.tsx b/packages/client/src/components/document/editor/index.tsx
index f2af666..3a00816 100644
--- a/packages/client/src/components/document/editor/index.tsx
+++ b/packages/client/src/components/document/editor/index.tsx
@@ -122,13 +122,25 @@ export const DocumentEditor: React.FC = ({ documentId }) => {
{isMobile && {actions}
}
- {docAuthError && (
-
-
-
- )}
- {document && }
-
+ {
+ return (
+
+
+
+ );
+ }}
+ normalContent={() => {
+ return (
+ <>
+ {document && }
+ {user && }
+ >
+ );
+ }}
+ />
);
diff --git a/packages/server/src/services/collaboration.service.ts b/packages/server/src/services/collaboration.service.ts
index 8c89a9b..f04887c 100644
--- a/packages/server/src/services/collaboration.service.ts
+++ b/packages/server/src/services/collaboration.service.ts
@@ -90,6 +90,8 @@ export class CollaborationService {
async onAuthenticate({ connection, token, requestParameters }: onAuthenticatePayload) {
const targetId = requestParameters.get('targetId');
const docType = requestParameters.get('docType');
+ const userId = requestParameters.get('userId');
+
const user = token ? await this.userService.decodeToken(token) : null;
switch (docType) {
@@ -99,8 +101,13 @@ export class CollaborationService {
if (!document || document.status !== DocumentStatus.public) {
throw new HttpException('您无权查看此文档', HttpStatus.FORBIDDEN);
}
+ connection.readOnly = true;
return { user: { name: '匿名用户' } };
} else {
+ if (user.id !== userId) {
+ throw new HttpException('用户信息不匹配', HttpStatus.FORBIDDEN);
+ }
+
const authority = await this.documentService.getDocumentUserAuth(user.id, targetId);
if (!authority.readable) {