feat: improve file manager plugin
This commit is contained in:
parent
a7040efe63
commit
551b9ce45d
@ -43,9 +43,10 @@ const plugins = [
|
|||||||
'@nocobase/plugin-ui-schema',
|
'@nocobase/plugin-ui-schema',
|
||||||
'@nocobase/plugin-users',
|
'@nocobase/plugin-users',
|
||||||
'@nocobase/plugin-action-logs',
|
'@nocobase/plugin-action-logs',
|
||||||
// '@nocobase/plugin-file-manager',
|
'@nocobase/plugin-file-manager',
|
||||||
'@nocobase/plugin-permissions',
|
'@nocobase/plugin-permissions',
|
||||||
'@nocobase/plugin-export',
|
'@nocobase/plugin-export',
|
||||||
|
'@nocobase/plugin-system-settings',
|
||||||
// '@nocobase/plugin-automations',
|
// '@nocobase/plugin-automations',
|
||||||
// '@nocobase/plugin-china-region',
|
// '@nocobase/plugin-china-region',
|
||||||
];
|
];
|
||||||
|
@ -69,5 +69,26 @@ import * as uiSchema from './ui-schema';
|
|||||||
await route.updateAssociations(item);
|
await route.updateAssociations(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Storage = database.getModel('storages');
|
||||||
|
await Storage.create({
|
||||||
|
title: '本地存储',
|
||||||
|
name: `local`,
|
||||||
|
type: 'local',
|
||||||
|
baseUrl: process.env.LOCAL_STORAGE_BASE_URL,
|
||||||
|
default: process.env.STORAGE_TYPE === 'local',
|
||||||
|
});
|
||||||
|
await Storage.create({
|
||||||
|
name: `ali-oss`,
|
||||||
|
type: 'ali-oss',
|
||||||
|
baseUrl: process.env.ALI_OSS_STORAGE_BASE_URL,
|
||||||
|
options: {
|
||||||
|
region: process.env.ALI_OSS_REGION,
|
||||||
|
accessKeyId: process.env.ALI_OSS_ACCESS_KEY_ID,
|
||||||
|
accessKeySecret: process.env.ALI_OSS_ACCESS_KEY_SECRET,
|
||||||
|
bucket: process.env.ALI_OSS_BUCKET,
|
||||||
|
},
|
||||||
|
default: process.env.STORAGE_TYPE === 'ali-oss',
|
||||||
|
});
|
||||||
|
|
||||||
await database.close();
|
await database.close();
|
||||||
})();
|
})();
|
||||||
|
@ -93,6 +93,8 @@ export async function action(ctx: actions.Context, next: actions.Next) {
|
|||||||
// TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
|
// TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
|
||||||
path: storage.path,
|
path: storage.path,
|
||||||
size: file.size,
|
size: file.size,
|
||||||
|
// 直接缓存起来
|
||||||
|
url: `${storage.baseUrl}${storage.path}/${file.filename}`,
|
||||||
mimetype: file.mimetype,
|
mimetype: file.mimetype,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
meta: ctx.request.body
|
meta: ctx.request.body
|
||||||
@ -113,7 +115,7 @@ export async function action(ctx: actions.Context, next: actions.Next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 将存储引擎的信息附在已创建的记录里,节省一次查询
|
// 将存储引擎的信息附在已创建的记录里,节省一次查询
|
||||||
attachment.setDataValue('storage', storage);
|
// attachment.setDataValue('storage', storage);
|
||||||
ctx.body = attachment;
|
ctx.body = attachment;
|
||||||
|
|
||||||
await next();
|
await next();
|
||||||
|
@ -3,8 +3,6 @@ import { TableOptions } from '@nocobase/database';
|
|||||||
export default {
|
export default {
|
||||||
name: 'attachments',
|
name: 'attachments',
|
||||||
title: '文件管理器',
|
title: '文件管理器',
|
||||||
internal: true,
|
|
||||||
developerMode: true,
|
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
comment: '用户文件名(不含扩展名)',
|
comment: '用户文件名(不含扩展名)',
|
||||||
@ -54,33 +52,9 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
comment: '网络访问地址',
|
comment: '网络访问地址',
|
||||||
type: 'formula',
|
type: 'string',
|
||||||
name: 'url',
|
name: 'url',
|
||||||
formula: '{{ storage.baseUrl }}{{ path }}/{{ filename }}'
|
// formula: '{{ storage.baseUrl }}{{ path }}/{{ filename }}'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
type: 'list',
|
|
||||||
name: 'list',
|
|
||||||
title: '查看',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'create',
|
|
||||||
name: 'create',
|
|
||||||
title: '新增',
|
|
||||||
viewName: 'form',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'update',
|
|
||||||
name: 'update',
|
|
||||||
title: '编辑',
|
|
||||||
viewName: 'form',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'destroy',
|
|
||||||
name: 'destroy',
|
|
||||||
title: '删除',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
} as TableOptions;
|
} as TableOptions;
|
||||||
|
@ -3,8 +3,6 @@ import { TableOptions } from '@nocobase/database';
|
|||||||
export default {
|
export default {
|
||||||
name: 'storages',
|
name: 'storages',
|
||||||
title: '存储引擎',
|
title: '存储引擎',
|
||||||
internal: true,
|
|
||||||
developerMode: true,
|
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
title: '存储引擎名称',
|
title: '存储引擎名称',
|
||||||
|
Loading…
Reference in New Issue
Block a user