fix(plugin-fm): fix cos path error (#4537)

This commit is contained in:
Junyi 2024-05-31 11:29:31 +08:00 committed by GitHub
parent dc309cbab5
commit ccef72cb0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 5 deletions

View File

@ -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) => {

View File

@ -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('/');

View File

@ -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() {