Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: modified import function (#6562)

Kilu.Heb1682e4f5459
diff --git a/frontend/appflowy_web_app/package.json b/frontend/appflowy_web_app/package.json
index 77b5f09af4..d9cbcabf93 100644
--- a/frontend/appflowy_web_app/package.json
+++ b/frontend/appflowy_web_app/package.json
@@ -58,6 +58,7 @@
"is-hotkey": "^0.2.0",
"jest": "^29.5.0",
"js-base64": "^3.7.5",
+ "js-md5": "^0.8.3",
"katex": "^0.16.7",
"lightgallery": "^2.7.2",
"lodash-es": "^4.17.21",
diff --git a/frontend/appflowy_web_app/pnpm-lock.yaml b/frontend/appflowy_web_app/pnpm-lock.yaml
index 67abd8d431..a43e88f3bf 100644
--- a/frontend/appflowy_web_app/pnpm-lock.yaml
+++ b/frontend/appflowy_web_app/pnpm-lock.yaml
@@ -107,6 +107,9 @@ dependencies:
js-base64:
specifier: ^3.7.5
version: 3.7.7
+ js-md5:
+ specifier: ^0.8.3
+ version: 0.8.3
katex:
specifier: ^0.16.7
version: 0.16.10
@@ -8420,6 +8423,10 @@ packages:
resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==}
dev: false
+ resolution: {integrity: sha512-qR0HB5uP6wCuRMrWPTrkMaev7MJZwJuuw4fnwAzRgP4J4/F8RwtodOKpGp4XpqsLBFzzgqIO42efFAyz2Et6KQ==}
+ dev: false
+
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
diff --git a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts
index 2d3ee687d9..bf51b34b1f 100644
--- a/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts
+++ b/frontend/appflowy_web_app/src/application/services/js-services/http/http_api.ts
@@ -28,6 +28,7 @@ import {
TemplateCreator, TemplateCreatorFormValues, TemplateSummary,
UploadTemplatePayload,
} from '@/application/template.type';
+import { calculateMd5 } from '@/utils/md5';
import axios, { AxiosInstance } from 'axios';
import dayjs from 'dayjs';
@@ -1182,6 +1183,7 @@ export async function importFile (file: File, onProgress: (progress: number) =>
const fileSize = file.size;
const mimeType = file.type || 'application/octet-stream';
+ const md5Base64 = await calculateMd5(file);
const validZipTypes = [
'application/zip',
@@ -1202,6 +1204,7 @@ export async function importFile (file: File, onProgress: (progress: number) =>
headers: {
'Content-Type': 'multipart/form-data',
'X-Content-Length': fileSize.toString(),
+ 'X-Content-MD5': md5Base64,
},
onUploadProgress: (progressEvent) => {
const { progress = 0 } = progressEvent;
@@ -1216,4 +1219,4 @@ export async function importFile (file: File, onProgress: (progress: number) =>
}
return Promise.reject(response?.data);
-}
\ No newline at end of file
+}
diff --git a/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx b/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx
index a6f5b22802..58a8bbdab9 100644
--- a/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx
+++ b/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx
@@ -6,7 +6,10 @@ import { ReactComponent as DocumentSvg } from '@/assets/document.svg';
import { ReactComponent as GridSvg } from '@/assets/grid.svg';
import { ReactComponent as ChatSvg } from '@/assets/chat_ai.svg';
-export function ViewIcon ({ layout, size }: { layout: ViewLayout; size: number | 'small' | 'medium' | 'large' }) {
+export function ViewIcon ({ layout, size }: {
+ layout: ViewLayout;
+ size: number | 'small' | 'medium' | 'large' | 'unset'
+}) {
const iconSize = useMemo(() => {
if (size === 'small') {
return 'h-4 w-4';
@@ -20,6 +23,10 @@ export function ViewIcon ({ layout, size }: { layout: ViewLayout; size: number |
return 'h-8 w-8';
}
+ if (size === 'unset') {
+ return '';
+ }
+
return `h-${size} w-${size}`;
}, [size]);
diff --git a/frontend/appflowy_web_app/src/components/app/workspaces/Workspaces.tsx b/frontend/appflowy_web_app/src/components/app/workspaces/Workspaces.tsx
index 260c0d0de6..cb8fc7e7ae 100644
--- a/frontend/appflowy_web_app/src/components/app/workspaces/Workspaces.tsx
+++ b/frontend/appflowy_web_app/src/components/app/workspaces/Workspaces.tsx
@@ -59,19 +59,6 @@ export function Workspaces () {
setChangeLoading(null);
}, [handleSelectedWorkspace]);
- if (!userWorkspaceInfo || !selectedWorkspace) return <div
- className={'flex p-4 cursor-pointer items-center gap-1 text-text-title'}
- onClick={async () => {
- const selectedId = userWorkspaceInfo?.selectedWorkspace?.id || userWorkspaceInfo?.workspaces[0]?.id;
-
- if (!selectedId) return;
-
- void handleChange(selectedId);
- }}
- >
- <AppFlowyLogo className={'w-[88px]'} />
- </div>;
-
return <>
<Button
ref={ref}
@@ -81,16 +68,36 @@ export function Workspaces () {
className={'flex px-1 w-full cursor-pointer justify-start py-1 items-center gap-1 mx-2 text-text-title'}
>
<div className={'flex items-center gap-1.5 text-text-title overflow-hidden'}>
- <Avatar
- variant={'rounded'}
- className={`w-6 h-6 border border-line-divider rounded-[8px] p-1 ${selectedWorkspace.icon ? 'bg-transparent' : ''}`}
- {...getAvatarProps(selectedWorkspace)}
- />
- <div className={'text-text-title flex-1 truncate font-semibold'}>{selectedWorkspace.name}</div>
+ {!userWorkspaceInfo || !selectedWorkspace ?
+ <div
+ className={'flex p-2 cursor-pointer items-center gap-1 text-text-title'}
+ onClick={async () => {
+ const selectedId = userWorkspaceInfo?.selectedWorkspace?.id || userWorkspaceInfo?.workspaces[0]?.id;
+
+ if (!selectedId) return;
+
+ void handleChange(selectedId);
+ }}
+ >
+ <AppFlowyLogo className={'w-[88px]'} />
+ </div> : <>
+ <Avatar
+ variant={'rounded'}
+ className={`w-6 h-6 border border-line-divider rounded-[8px] p-1 ${selectedWorkspace.icon ? 'bg-transparent' : ''}`}
+ {...getAvatarProps(selectedWorkspace)}
+ />
+ <div className={'text-text-title flex-1 truncate font-semibold'}>{selectedWorkspace.name}</div>
+ </>
+ }
+
{hoveredHeader && <ArrowRightSvg className={'w-4 h-4 transform rotate-90'} />}
</div>
</Button>
- <Popover open={open} anchorEl={ref.current} onClose={() => setOpen(false)}>
+ <Popover
+ open={open}
+ anchorEl={ref.current}
+ onClose={() => setOpen(false)}
+ >
<div
className={'flex min-w-[260px] flex-col gap-1 p-2 w-full max-h-[560px] overflow-y-auto overflow-x-hidden appflowy-scroller'}
>
@@ -101,14 +108,19 @@ export function Workspaces () {
content={
<div className={'p-2 w-[160px]'}>
<Button
- color={'inherit'} size={'small'} className={'w-full justify-start'} onClick={handleLogin}
+ color={'inherit'}
+ size={'small'}
+ className={'w-full justify-start'}
+ onClick={handleLogin}
startIcon={<LoginIcon />}
>
{t('button.logout')}
</Button>
</div>
- } open={moreOpen} onClose={() => setMoreOpen(false)}
+ }
+ open={moreOpen}
+ onClose={() => setMoreOpen(false)}
>
<IconButton onClick={() => setMoreOpen(prev => !prev)}>
<MoreSvg className={'w-4 h-4'} />
@@ -117,7 +129,7 @@ export function Workspaces () {
</div>
<Divider className={'w-full mt-1'} />
- {userWorkspaceInfo.workspaces.map((workspace) => (
+ {userWorkspaceInfo?.workspaces.map((workspace) => (
<Button
key={workspace.id}
onClick={() => {
@@ -129,10 +141,14 @@ export function Workspaces () {
variant={'rounded'}
className={'rounded-[8px] w-7 h-7 border border-line-divider'} {...getAvatarProps(workspace)} />
- <Tooltip title={workspace.name} enterDelay={1000} enterNextDelay={1000}>
+ <Tooltip
+ title={workspace.name}
+ enterDelay={1000}
+ enterNextDelay={1000}
+ >
<div className={'text-text-title font-medium truncate flex-1 text-left'}>{workspace.name}</div>
</Tooltip>
- {changeLoading === workspace.id ? <CircularProgress size={16} /> : workspace.id === selectedWorkspace.id &&
+ {changeLoading === workspace.id ? <CircularProgress size={16} /> : workspace.id === selectedWorkspace?.id &&
<SelectedSvg className={'w-4 text-function-success h-4'} />}
</Button>
))}
diff --git a/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx b/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx
index f2bc154bd3..52ea133502 100644
--- a/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx
+++ b/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx
@@ -8,19 +8,19 @@ import { useTranslation } from 'react-i18next';
function MentionPage ({ pageId }: { pageId: string }) {
const context = useEditorContext();
const { navigateToView, loadViewMeta } = context;
- const [unPublished, setUnPublished] = useState(false);
+ const [noAccess, setNoAccess] = useState(false);
const [meta, setMeta] = useState<View | null>(null);
useEffect(() => {
void (async () => {
if (loadViewMeta) {
- setUnPublished(false);
+ setNoAccess(false);
try {
const meta = await loadViewMeta(pageId, setMeta);
setMeta(meta);
} catch (e) {
- setUnPublished(true);
+ setNoAccess(true);
}
}
})();
@@ -41,16 +41,19 @@ function MentionPage ({ pageId }: { pageId: string }) {
onClick={() => {
void navigateToView?.(pageId);
}}
- className={`mention-inline px-1 underline`}
+ className={`mention-inline cursor-pointer px-1 underline`}
contentEditable={false}
data-mention-id={pageId}
>
- {unPublished ? (
+ {noAccess ? (
<span className={'mention-unpublished font-semibold text-text-caption'}>No Access</span>
) : (
<>
<span className={`mention-icon ${isFlag ? 'icon' : ''}`}>
- {icon?.value || <ViewIcon layout={meta?.layout || ViewLayout.Document} size={'small'} />}
+ {icon?.value || <ViewIcon
+ layout={meta?.layout || ViewLayout.Document}
+ size={'unset'}
+ />}
</span>
<span className={'mention-content'}>{meta?.name || t('menuAppHeader.defaultNewPageName')}</span>
diff --git a/frontend/appflowy_web_app/src/components/editor/editor.scss b/frontend/appflowy_web_app/src/components/editor/editor.scss
index b3d391e918..f505b5104d 100644
--- a/frontend/appflowy_web_app/src/components/editor/editor.scss
+++ b/frontend/appflowy_web_app/src/components/editor/editor.scss
@@ -273,7 +273,7 @@ span[data-slate-placeholder="true"]:not(.inline-block-content) {
.mention-icon {
@apply absolute top-1/2 transform -translate-y-1/2;
- font-size: 1.25em;
+ font-size: 1em;
}
.mention-content {
diff --git a/frontend/appflowy_web_app/src/utils/md5.ts b/frontend/appflowy_web_app/src/utils/md5.ts
new file mode 100644
index 0000000000..4bafff7032
--- /dev/null
+++ b/frontend/appflowy_web_app/src/utils/md5.ts
@@ -0,0 +1,38 @@
+import { md5 } from 'js-md5';
+
+export async function calculateMd5 (file: File): Promise<string> {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ const chunkSize = 1_000_000; // Match Rust version's buffer size
+ let cursor = 0;
+ const md5Hash = md5.create();
+
+ reader.onload = (e: ProgressEvent<FileReader>) => {
+ if (e.target?.result instanceof ArrayBuffer) {
+ md5Hash.update(new Uint8Array(e.target.result));
+ cursor += e.target.result.byteLength;
+
+ if (cursor < file.size) {
+ readNextChunk();
+ } else {
+ const hashBuffer = md5Hash.arrayBuffer();
+ const hashBase64 = btoa(String.fromCharCode(...new Uint8Array(hashBuffer)));
+
+ resolve(hashBase64);
+ }
+ }
+ };
+
+ reader.onerror = (error) => {
+ reject(error);
+ };
+
+ function readNextChunk () {
+ const slice = file.slice(cursor, cursor + chunkSize);
+
+ reader.readAsArrayBuffer(slice);
+ }
+
+ readNextChunk();
+ });
+}
\ No newline at end of file