fix: unable to access files stored in COS (#6512)

* fix: unable to access files stored in COS

* fix: ensureUrlEncoded
This commit is contained in:
chenos 2025-03-20 14:56:42 +08:00 committed by GitHub
parent 2c024cc32e
commit bd51bd545e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 6 deletions

View File

@ -59,7 +59,7 @@ export async function getFileData(ctx: Context) {
mimetype: file.mimetype,
meta: ctx.request.body,
storageId: storage.id,
...(storageInstance.getFileData ? storageInstance.getFileData(file) : {}),
...StorageType?.['getFileData']?.(file),
};
return data;

View File

@ -10,7 +10,7 @@
import { isURL } from '@nocobase/utils';
import { StorageEngine } from 'multer';
import urlJoin from 'url-join';
import { encodeURL } from '../utils';
import { encodeURL, ensureUrlEncoded } from '../utils';
export interface StorageModel {
id?: number;
@ -54,7 +54,7 @@ export abstract class StorageType {
const keys = [
this.storage.baseUrl,
file.path && encodeURI(file.path),
encodeURIComponent(file.filename),
ensureUrlEncoded(file.filename),
preview && this.storage.options.thumbnailRule,
].filter(Boolean);
return urlJoin(keys);

View File

@ -7,11 +7,13 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { isURL } from '@nocobase/utils';
import path from 'path';
import urlJoin from 'url-join';
import { promisify } from 'util';
import { AttachmentModel, StorageType } from '.';
import { STORAGE_TYPE_TX_COS } from '../../constants';
import { getFilename, getFileKey } from '../utils';
import { getFileKey, getFilename } from '../utils';
export default class extends StorageType {
static defaults() {

View File

@ -30,7 +30,7 @@ export function getFileKey(record) {
return [record.path.replace(/^\/|\/$/g, ''), record.filename].filter(Boolean).join('/');
}
function ensureUrlEncoded(value) {
export function ensureUrlEncoded(value) {
try {
// 如果解码后与原字符串不同,说明已经被转义过
if (decodeURIComponent(value) !== value) {