fix(plugin-file-manager): fix error of getting file key when path is null

This commit is contained in:
mytharcher 2025-03-27 18:51:52 +08:00
parent 27da1d4424
commit 5f85b9ab9a
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,50 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { getApp } from '.';
import PluginFileManagerServer from '../server';
import { STORAGE_TYPE_LOCAL } from '../../constants';
import { getFileKey } from '../utils';
describe('file manager > utils', () => {
let app;
let agent;
let db;
let plugin: PluginFileManagerServer;
let StorageRepo;
let AttachmentRepo;
let local;
beforeEach(async () => {
app = await getApp();
agent = app.agent();
db = app.db;
plugin = app.pm.get(PluginFileManagerServer) as PluginFileManagerServer;
AttachmentRepo = db.getCollection('attachments').repository;
StorageRepo = db.getCollection('storages').repository;
local = await StorageRepo.findOne({
filter: {
type: STORAGE_TYPE_LOCAL,
},
});
});
afterEach(async () => {
await app.destroy();
});
describe('getFileKey', () => {
it('path as null should works', async () => {
expect(getFileKey({ path: null, filename: 'test.jpg' })).toBe('test.jpg');
});
});
});

View File

@ -28,7 +28,7 @@ export const cloudFilenameGetter = (storage) => (req, file, cb) => {
};
export function getFileKey(record) {
return urlJoin(record.path, record.filename).replace(/^\//, '');
return urlJoin(record.path || '', record.filename).replace(/^\//, '');
}
export function ensureUrlEncoded(value) {