mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix: unable to access files stored in COS (#6512)
* fix: unable to access files stored in COS * fix: ensureUrlEncoded
This commit is contained in:
parent
2c024cc32e
commit
bd51bd545e
@ -59,7 +59,7 @@ export async function getFileData(ctx: Context) {
|
|||||||
mimetype: file.mimetype,
|
mimetype: file.mimetype,
|
||||||
meta: ctx.request.body,
|
meta: ctx.request.body,
|
||||||
storageId: storage.id,
|
storageId: storage.id,
|
||||||
...(storageInstance.getFileData ? storageInstance.getFileData(file) : {}),
|
...StorageType?.['getFileData']?.(file),
|
||||||
};
|
};
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
import { isURL } from '@nocobase/utils';
|
import { isURL } from '@nocobase/utils';
|
||||||
import { StorageEngine } from 'multer';
|
import { StorageEngine } from 'multer';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
import { encodeURL } from '../utils';
|
import { encodeURL, ensureUrlEncoded } from '../utils';
|
||||||
|
|
||||||
export interface StorageModel {
|
export interface StorageModel {
|
||||||
id?: number;
|
id?: number;
|
||||||
@ -54,7 +54,7 @@ export abstract class StorageType {
|
|||||||
const keys = [
|
const keys = [
|
||||||
this.storage.baseUrl,
|
this.storage.baseUrl,
|
||||||
file.path && encodeURI(file.path),
|
file.path && encodeURI(file.path),
|
||||||
encodeURIComponent(file.filename),
|
ensureUrlEncoded(file.filename),
|
||||||
preview && this.storage.options.thumbnailRule,
|
preview && this.storage.options.thumbnailRule,
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
return urlJoin(keys);
|
return urlJoin(keys);
|
||||||
|
@ -7,11 +7,13 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* 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 { promisify } from 'util';
|
||||||
|
|
||||||
import { AttachmentModel, StorageType } from '.';
|
import { AttachmentModel, StorageType } from '.';
|
||||||
import { STORAGE_TYPE_TX_COS } from '../../constants';
|
import { STORAGE_TYPE_TX_COS } from '../../constants';
|
||||||
import { getFilename, getFileKey } from '../utils';
|
import { getFileKey, getFilename } from '../utils';
|
||||||
|
|
||||||
export default class extends StorageType {
|
export default class extends StorageType {
|
||||||
static defaults() {
|
static defaults() {
|
||||||
|
@ -30,7 +30,7 @@ export function getFileKey(record) {
|
|||||||
return [record.path.replace(/^\/|\/$/g, ''), record.filename].filter(Boolean).join('/');
|
return [record.path.replace(/^\/|\/$/g, ''), record.filename].filter(Boolean).join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureUrlEncoded(value) {
|
export function ensureUrlEncoded(value) {
|
||||||
try {
|
try {
|
||||||
// 如果解码后与原字符串不同,说明已经被转义过
|
// 如果解码后与原字符串不同,说明已经被转义过
|
||||||
if (decodeURIComponent(value) !== value) {
|
if (decodeURIComponent(value) !== value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user