PluginManager refactor (#6677)

* fix: refactor plugin manager

* fix: make id optional

* fix: allow add to accept single object

* fix: getHooks

* fix: tsc

* fix: remove id
This commit is contained in:
Apoorv Mishra
2024-03-16 21:22:25 +05:30
committed by GitHub
parent 6775f25425
commit 85c8f83e33
20 changed files with 187 additions and 178 deletions

View File

@@ -1,7 +1,11 @@
import { existsSync, mkdirSync } from "fs";
import env from "@server/env";
import Logger from "@server/logging/Logger";
import { PluginManager, PluginType } from "@server/utils/PluginManager";
import {
PluginManager,
PluginPriority,
Hook,
} from "@server/utils/PluginManager";
import router from "./api/files";
if (env.FILE_STORAGE === "local") {
@@ -19,13 +23,20 @@ if (env.FILE_STORAGE === "local") {
}
}
PluginManager.register(PluginType.API, router, {
id: "files",
name: "Local file storage",
description: "Plugin for storing files on the local file system",
enabled: !!(
env.FILE_STORAGE_UPLOAD_MAX_SIZE &&
env.FILE_STORAGE_LOCAL_ROOT_DIR &&
env.FILE_STORAGE === "local"
),
});
const enabled = !!(
env.FILE_STORAGE_UPLOAD_MAX_SIZE &&
env.FILE_STORAGE_LOCAL_ROOT_DIR &&
env.FILE_STORAGE === "local"
);
if (enabled) {
PluginManager.add([
{
name: "Local file storage",
description: "Plugin for storing files on the local file system",
type: Hook.API,
value: router,
priority: PluginPriority.Normal,
},
]);
}