From cc0e13dce0569acc66f585faa3f613615c52ce6a Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 12 Mar 2025 23:35:14 +0800 Subject: [PATCH] fix(plugin-file-manager): fix file issues (#6436) * fix(plugin-file-manager): fix file issues * fix(plugin-file-manager): fix special char in windows --- docker/nocobase-full/nocobase.conf | 2 +- docker/nocobase/nocobase.conf | 2 +- packages/core/cli/nocobase.conf.tpl | 2 +- .../antd/input/ReadPretty.tsx | 20 +++++++++++- .../schema-component/antd/upload/Upload.tsx | 16 +++++----- .../schema-component/antd/upload/shared.ts | 12 +++++++ .../plugin-file-manager/package.json | 1 - .../plugin-file-manager/src/constants.ts | 2 +- .../src/server/__tests__/action.test.ts | 31 ++++++++++++++++++- .../files/[]中文报告! 1%~50.4% (123) {$#}.txt | 1 + .../src/server/actions/attachments.ts | 13 ++------ .../plugin-file-manager/src/server/utils.ts | 8 ++--- 12 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 packages/plugins/@nocobase/plugin-file-manager/src/server/__tests__/files/[]中文报告! 1%~50.4% (123) {$#}.txt diff --git a/docker/nocobase-full/nocobase.conf b/docker/nocobase-full/nocobase.conf index 61ddc70335..7de9bbb630 100644 --- a/docker/nocobase-full/nocobase.conf +++ b/docker/nocobase-full/nocobase.conf @@ -17,7 +17,7 @@ server { server_name _; root /app/nocobase/packages/app/client/dist; index index.html; - client_max_body_size 20M; + client_max_body_size 0; access_log /var/log/nginx/nocobase.log apm; diff --git a/docker/nocobase/nocobase.conf b/docker/nocobase/nocobase.conf index 7c0c4d2c41..d178440bf9 100644 --- a/docker/nocobase/nocobase.conf +++ b/docker/nocobase/nocobase.conf @@ -17,7 +17,7 @@ server { server_name _; root /app/nocobase/node_modules/@nocobase/app/dist/client; index index.html; - client_max_body_size 1000M; + client_max_body_size 0; access_log /var/log/nginx/nocobase.log apm; gzip on; diff --git a/packages/core/cli/nocobase.conf.tpl b/packages/core/cli/nocobase.conf.tpl index a40343cc02..141ca74282 100644 --- a/packages/core/cli/nocobase.conf.tpl +++ b/packages/core/cli/nocobase.conf.tpl @@ -17,7 +17,7 @@ server { server_name _; root {{cwd}}/node_modules/@nocobase/app/dist/client; index index.html; - client_max_body_size 1000M; + client_max_body_size 0; access_log /var/log/nginx/nocobase.log apm; gzip on; diff --git a/packages/core/client/src/schema-component/antd/input/ReadPretty.tsx b/packages/core/client/src/schema-component/antd/input/ReadPretty.tsx index 94f038ddea..3bf5255fec 100644 --- a/packages/core/client/src/schema-component/antd/input/ReadPretty.tsx +++ b/packages/core/client/src/schema-component/antd/input/ReadPretty.tsx @@ -199,11 +199,29 @@ export interface URLReadPrettyProps { } const ellipsisStyle = { textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', display: 'block' }; + +function encodeFileURL(url: string): string { + if (!url) { + return url; + } + + const parts = url.split('/'); + const filename = parts.pop(); + parts.push(encodeURIComponent(filename)); + const encodedURL = parts.join('/'); + return encodedURL; +} + ReadPretty.URL = (props: URLReadPrettyProps) => { // eslint-disable-next-line react-hooks/rules-of-hooks const prefixCls = usePrefixCls('description-url', props); const content = props.value && ( - + {props.value} ); diff --git a/packages/core/client/src/schema-component/antd/upload/Upload.tsx b/packages/core/client/src/schema-component/antd/upload/Upload.tsx index 57b00995d9..098dff9f52 100644 --- a/packages/core/client/src/schema-component/antd/upload/Upload.tsx +++ b/packages/core/client/src/schema-component/antd/upload/Upload.tsx @@ -32,6 +32,7 @@ import { toValueItem as toValueItemDefault, useBeforeUpload, useUploadProps, + encodeFileURL, } from './shared'; import { useStyles } from './style'; import type { ComposedUpload, DraggerProps, DraggerV2Props, UploadProps } from './type'; @@ -89,26 +90,27 @@ attachmentFileTypes.add({ }, }); -const iframePreviewSupportedTypes = ['application/pdf', 'audio/*', 'image/*', 'video/*']; +const iframePreviewSupportedTypes = ['application/pdf', 'audio/*', 'image/*', 'video/*', 'text/*']; function IframePreviewer({ index, list, onSwitchIndex }) { const { t } = useTranslation(); const file = list[index]; + const url = encodeFileURL(file.url); const onOpen = useCallback( (e) => { e.preventDefault(); e.stopPropagation(); - window.open(file.url); + window.open(url); }, - [file], + [url], ); const onDownload = useCallback( (e) => { e.preventDefault(); e.stopPropagation(); - saveAs(file.url, `${file.title}${file.extname}`); + saveAs(url, `${file.title}${file.extname}`); }, - [file], + [file.extname, file.title, url], ); const onClose = useCallback(() => { onSwitchIndex(null); @@ -148,7 +150,7 @@ function IframePreviewer({ index, list, onSwitchIndex }) { > {iframePreviewSupportedTypes.some((type) => matchMimetype(file, type)) ? (