tachybase_todo/packages/plugin-file-manager/src/server.ts
Junyi 8bdbd804f0
feature: add file manager base architecture (#44)
* feature: add file manager base architecture

* 修改 action 注册方式

* put upload action and middleware together

* bugfix

Co-authored-by: chenos <chenlinxh@gmail.com>
2020-12-19 08:45:19 +08:00

30 lines
776 B
TypeScript

import path from 'path';
import Database, { registerFields } from '@nocobase/database';
import Resourcer from '@nocobase/resourcer';
import * as fields from './fields';
import { IStorage } from './storages';
import {
action as uploadAction,
middleware as uploadMiddleware,
} from './actions/upload';
export interface FileManagerOptions {
storages: IStorage[]
}
export default async function (options: FileManagerOptions) {
const database: Database = this.database;
const resourcer: Resourcer = this.resourcer;
registerFields(fields);
database.import({
directory: path.resolve(__dirname, 'collections'),
});
// 暂时中间件只能通过 use 加进来
resourcer.use(uploadMiddleware);
resourcer.registerActionHandler('upload', uploadAction);
}