mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
feat: add backend code to generate file preview url for next (#6281)
* feat: adjust preview field of file collection * fix: add banckend to generate preview * fix: undefined error
This commit is contained in:
parent
b2aa497da5
commit
669c7f6335
@ -41,6 +41,9 @@ attachmentFileTypes.add({
|
|||||||
return matchMimetype(file, 'image/*');
|
return matchMimetype(file, 'image/*');
|
||||||
},
|
},
|
||||||
getThumbnailURL(file) {
|
getThumbnailURL(file) {
|
||||||
|
if (file.preview) {
|
||||||
|
return file.preview;
|
||||||
|
}
|
||||||
if (file.url) {
|
if (file.url) {
|
||||||
return `${file.url}${file.thumbnailRule || ''}`;
|
return `${file.url}${file.thumbnailRule || ''}`;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Model } from '@nocobase/database';
|
import { Model } from '@nocobase/database';
|
||||||
|
import { STORAGE_TYPE_ALI_OSS, STORAGE_TYPE_LOCAL, STORAGE_TYPE_S3, STORAGE_TYPE_TX_COS } from '../constants';
|
||||||
|
|
||||||
|
const currentStorage = [STORAGE_TYPE_LOCAL, STORAGE_TYPE_ALI_OSS, STORAGE_TYPE_S3, STORAGE_TYPE_TX_COS];
|
||||||
|
|
||||||
export class FileModel extends Model {
|
export class FileModel extends Model {
|
||||||
public toJSON() {
|
public toJSON() {
|
||||||
@ -15,6 +18,10 @@ export class FileModel extends Model {
|
|||||||
const fileStorages = this.constructor['database']?.['_fileStorages'];
|
const fileStorages = this.constructor['database']?.['_fileStorages'];
|
||||||
if (json.storageId && fileStorages && fileStorages.has(json.storageId)) {
|
if (json.storageId && fileStorages && fileStorages.has(json.storageId)) {
|
||||||
const storage = fileStorages.get(json.storageId);
|
const storage = fileStorages.get(json.storageId);
|
||||||
|
// 当前文件管理器内的存储类型拼接生成预览链接,其他文件存储自行处理
|
||||||
|
if (currentStorage.includes(storage?.type) && storage?.options?.thumbnailRule) {
|
||||||
|
json['preview'] = `${json['url']}${storage?.options?.thumbnailRule || ''}`;
|
||||||
|
}
|
||||||
if (storage?.options?.thumbnailRule) {
|
if (storage?.options?.thumbnailRule) {
|
||||||
json['thumbnailRule'] = storage?.options?.thumbnailRule;
|
json['thumbnailRule'] = storage?.options?.thumbnailRule;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user