2020-11-11 15:23:39 +08:00
|
|
|
import path from 'path';
|
2020-12-19 08:45:19 +08:00
|
|
|
import Database, { registerFields } from '@nocobase/database';
|
2020-11-11 15:23:39 +08:00
|
|
|
import Resourcer from '@nocobase/resourcer';
|
|
|
|
|
2020-12-19 08:45:19 +08:00
|
|
|
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) {
|
2020-11-11 15:23:39 +08:00
|
|
|
const database: Database = this.database;
|
|
|
|
const resourcer: Resourcer = this.resourcer;
|
|
|
|
|
2020-12-19 08:45:19 +08:00
|
|
|
registerFields(fields);
|
|
|
|
|
2020-11-11 20:57:18 +08:00
|
|
|
database.import({
|
2020-11-11 15:23:39 +08:00
|
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
|
|
});
|
2020-12-19 08:45:19 +08:00
|
|
|
|
|
|
|
// 暂时中间件只能通过 use 加进来
|
|
|
|
resourcer.use(uploadMiddleware);
|
|
|
|
resourcer.registerActionHandler('upload', uploadAction);
|
2020-11-11 15:23:39 +08:00
|
|
|
}
|