mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 14:43:06 +08:00
21c3ad0ecc
* * multi-file paste support * allow media files (image/videos) to be attachments * insert trailing node if file placeholder is at the end of the editor * fix video align
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { handleAttachmentUpload } from "@docmost/editor-ext";
|
|
import { uploadFile } from "@/features/page/services/page-service.ts";
|
|
import { notifications } from "@mantine/notifications";
|
|
import { getFileUploadSizeLimit } from "@/lib/config.ts";
|
|
import { formatBytes } from "@/lib";
|
|
import i18n from "@/i18n.ts";
|
|
|
|
export const uploadAttachmentAction = handleAttachmentUpload({
|
|
onUpload: async (file: File, pageId: string): Promise<any> => {
|
|
try {
|
|
return await uploadFile(file, pageId);
|
|
} catch (err) {
|
|
notifications.show({
|
|
color: "red",
|
|
message: err?.response.data.message,
|
|
});
|
|
throw err;
|
|
}
|
|
},
|
|
validateFn: (file, allowMedia: boolean) => {
|
|
if (
|
|
(file.type.includes("image/") || file.type.includes("video/")) &&
|
|
!allowMedia
|
|
) {
|
|
return false;
|
|
}
|
|
if (file.size > getFileUploadSizeLimit()) {
|
|
notifications.show({
|
|
color: "red",
|
|
message: i18n.t("File exceeds the {{limit}} attachment limit", {
|
|
limit: formatBytes(getFileUploadSizeLimit()),
|
|
}),
|
|
});
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
},
|
|
});
|