From ccef72cb0b89dbac7a93b64a422f9a48ff2cfe10 Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 31 May 2024 11:29:31 +0800 Subject: [PATCH] fix(plugin-fm): fix cos path error (#4537) --- .../plugin-file-manager/src/client/FileSizeField.tsx | 2 +- .../src/server/actions/attachments.ts | 2 +- .../plugin-file-manager/src/server/storages/tx-cos.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/FileSizeField.tsx b/packages/plugins/@nocobase/plugin-file-manager/src/client/FileSizeField.tsx index c784692925..d7e25cff97 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/FileSizeField.tsx +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/FileSizeField.tsx @@ -47,7 +47,7 @@ export function FileSizeField(props) { const dvOption = getUnitOption(defaultValue, defaultUnit); const dv = defaultValue / dvOption.value; const vOption = getUnitOption(value ?? defaultValue, defaultUnit); - const v = value == null ? dv : value / vOption.value; + const v = value == null ? value : value / vOption.value; const onNumberChange = useCallback( (val) => { diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/server/actions/attachments.ts b/packages/plugins/@nocobase/plugin-file-manager/src/server/actions/attachments.ts index 1918b10541..34eb2edf17 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/server/actions/attachments.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/server/actions/attachments.ts @@ -44,7 +44,7 @@ function getFileData(ctx: Context) { // make compatible filename across cloud service (with path) const filename = Path.basename(name); const extname = Path.extname(filename); - const path = storage.path.replace(/^\/|\/$/g, ''); + const path = (storage.path || '').replace(/^\/|\/$/g, ''); const baseUrl = storage.baseUrl.replace(/\/+$/, ''); const pathname = [path, filename].filter(Boolean).join('/'); diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/server/storages/tx-cos.ts b/packages/plugins/@nocobase/plugin-file-manager/src/server/storages/tx-cos.ts index fe48c01968..260117a545 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/server/storages/tx-cos.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/server/storages/tx-cos.ts @@ -11,15 +11,18 @@ import { promisify } from 'util'; import { AttachmentModel, StorageType } from '.'; import { STORAGE_TYPE_TX_COS } from '../../constants'; -import { cloudFilenameGetter, getFileKey } from '../utils'; +import { getFilename, getFileKey } from '../utils'; export default class extends StorageType { filenameKey = 'url'; make(storage) { const createTxCosStorage = require('multer-cos'); return new createTxCosStorage({ - cos: storage.options, - filename: cloudFilenameGetter(storage), + cos: { + ...storage.options, + dir: (storage.path ?? '').replace(/\/+$/, ''), + }, + filename: getFilename, }); } defaults() {