feat: improve file manager plugin

This commit is contained in:
chenos 2021-08-13 23:12:57 +08:00
parent a7040efe63
commit 551b9ce45d
5 changed files with 28 additions and 32 deletions

View File

@ -43,9 +43,10 @@ const plugins = [
'@nocobase/plugin-ui-schema',
'@nocobase/plugin-users',
'@nocobase/plugin-action-logs',
// '@nocobase/plugin-file-manager',
'@nocobase/plugin-file-manager',
'@nocobase/plugin-permissions',
'@nocobase/plugin-export',
'@nocobase/plugin-system-settings',
// '@nocobase/plugin-automations',
// '@nocobase/plugin-china-region',
];

View File

@ -69,5 +69,26 @@ import * as uiSchema from './ui-schema';
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();
})();

View File

@ -93,6 +93,8 @@ export async function action(ctx: actions.Context, next: actions.Next) {
// TODO(feature): 暂时两者相同,后面 storage.path 模版化以后,这里只是 file 实际的 path
path: storage.path,
size: file.size,
// 直接缓存起来
url: `${storage.baseUrl}${storage.path}/${file.filename}`,
mimetype: file.mimetype,
// @ts-ignore
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;
await next();

View File

@ -3,8 +3,6 @@ import { TableOptions } from '@nocobase/database';
export default {
name: 'attachments',
title: '文件管理器',
internal: true,
developerMode: true,
fields: [
{
comment: '用户文件名(不含扩展名)',
@ -54,33 +52,9 @@ export default {
},
{
comment: '网络访问地址',
type: 'formula',
type: 'string',
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;

View File

@ -3,8 +3,6 @@ import { TableOptions } from '@nocobase/database';
export default {
name: 'storages',
title: '存储引擎',
internal: true,
developerMode: true,
fields: [
{
title: '存储引擎名称',