working
This commit is contained in:
parent
dd09351c8e
commit
aa872bf782
38
server/plugins-manager.js
Normal file
38
server/plugins-manager.js
Normal file
@ -0,0 +1,38 @@
|
||||
const fs = require("fs");
|
||||
const { log } = require("../src/util");
|
||||
|
||||
class PluginsManager {
|
||||
|
||||
pluginList = [];
|
||||
|
||||
/**
|
||||
* Plugins Dir
|
||||
*/
|
||||
pluginsDir;
|
||||
|
||||
constructor(dir) {
|
||||
this.pluginsDir = dir;
|
||||
|
||||
if (! fs.existsSync(this.pluginsDir)) {
|
||||
fs.mkdirSync(this.pluginsDir, { recursive: true });
|
||||
}
|
||||
|
||||
let list = fs.readdirSync(this.pluginsDir);
|
||||
|
||||
this.pluginList = [];
|
||||
for (let item of list) {
|
||||
let indexFile = this.pluginsDir + item + "/index.js";
|
||||
|
||||
if (fs.existsSync(indexFile)) {
|
||||
this.pluginList.push(require(indexFile));
|
||||
log.debug("plugin", indexFile);
|
||||
log.info("plugin", `${item} loaded`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
PluginsManager
|
||||
};
|
@ -153,6 +153,8 @@ let needSetup = false;
|
||||
Database.init(args);
|
||||
await initDatabase(testMode);
|
||||
|
||||
server.loadPlugins(Database.dataDir + "plugins/");
|
||||
|
||||
exports.entryPage = await setting("entryPage");
|
||||
await StatusPage.loadDomainMappingList();
|
||||
|
||||
|
@ -7,6 +7,7 @@ const { R } = require("redbean-node");
|
||||
const { log } = require("../src/util");
|
||||
const Database = require("./database");
|
||||
const util = require("util");
|
||||
const { PluginsManager } = require("./plugins-manager");
|
||||
|
||||
/**
|
||||
* `module.exports` (alias: `server`) should be inside this class, in order to avoid circular dependency issue.
|
||||
@ -35,6 +36,12 @@ class UptimeKumaServer {
|
||||
*/
|
||||
indexHTML = "";
|
||||
|
||||
/**
|
||||
* Plugins Manager
|
||||
* @type {PluginsManager}
|
||||
*/
|
||||
pluginsManager = null;
|
||||
|
||||
static getInstance(args) {
|
||||
if (UptimeKumaServer.instance == null) {
|
||||
UptimeKumaServer.instance = new UptimeKumaServer(args);
|
||||
@ -126,6 +133,11 @@ class UptimeKumaServer {
|
||||
|
||||
errorLogStream.end();
|
||||
}
|
||||
|
||||
loadPlugins(dir) {
|
||||
this.pluginsManager = new PluginsManager(dir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user