From b0e9c5bcb466fa5ec5a9ec2014b9b8b6c1cc5dae Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 20 Sep 2021 16:29:18 +0800 Subject: [PATCH] fix reset-password (#448) --- extra/reset-password.js | 2 ++ server/database.js | 10 ++++++++++ server/server.js | 9 +-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/extra/reset-password.js b/extra/reset-password.js index b849848b..be039589 100644 --- a/extra/reset-password.js +++ b/extra/reset-password.js @@ -6,12 +6,14 @@ const Database = require("../server/database"); const { R } = require("redbean-node"); const readline = require("readline"); const { initJWTSecret } = require("../server/util-server"); +const args = require("args-parser")(process.argv); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); (async () => { + Database.init(args); await Database.connect(); try { diff --git a/server/database.js b/server/database.js index 55d79df6..e2020eeb 100644 --- a/server/database.js +++ b/server/database.js @@ -42,6 +42,16 @@ class Database { static noReject = true; + static init(args) { + // Data Directory (must be end with "/") + Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/"; + Database.path = Database.dataDir + "kuma.db"; + if (! fs.existsSync(Database.dataDir)) { + fs.mkdirSync(Database.dataDir, { recursive: true }); + } + console.log(`Data Dir: ${Database.dataDir}`); + } + static async connect() { const acquireConnectionTimeout = 120 * 1000; diff --git a/server/server.js b/server/server.js index b8d0c90f..c23781ae 100644 --- a/server/server.js +++ b/server/server.js @@ -69,14 +69,6 @@ if (demoMode) { console.log("==== Demo Mode ===="); } -// Data Directory (must be end with "/") -Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/"; -Database.path = Database.dataDir + "kuma.db"; -if (! fs.existsSync(Database.dataDir)) { - fs.mkdirSync(Database.dataDir, { recursive: true }); -} -console.log(`Data Dir: ${Database.dataDir}`); - console.log("Creating express and socket.io instance") const app = express(); @@ -132,6 +124,7 @@ let needSetup = false; let indexHTML = fs.readFileSync("./dist/index.html").toString(); (async () => { + Database.init(args); await initDatabase(); console.log("Adding route")