summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-24 03:02:05 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-09-04 10:48:54 +0200
commit5c146b16bc348e8f68044dec74e7b1694e55d2b8 (patch)
treea231c6b971714f3a67e0fdb99339f8c8146b55ac
parentMinor fixes (diff)
downloadserver-5c146b16bc348e8f68044dec74e7b1694e55d2b8.tar.xz
-rw-r--r--fosscord-server.code-workspace2
-rw-r--r--package.json1
-rw-r--r--scripts/build.js16
-rw-r--r--src/api/Server.ts3
-rw-r--r--src/util/plugin/PluginConfig.ts14
-rw-r--r--src/util/util/Config.ts19
6 files changed, 27 insertions, 28 deletions
diff --git a/fosscord-server.code-workspace b/fosscord-server.code-workspace
index a9b15856..8b7268a5 100644
--- a/fosscord-server.code-workspace
+++ b/fosscord-server.code-workspace
@@ -30,7 +30,7 @@
 				"type": "node-terminal"
 			},
 			{
-				"command": "kitty npm run start:bundle:vscode-dbg",
+				"command": "[ \"$(basename $PWD)\" != \"fosscord-server\" ] && cd ..; node scripts/build_new.js && kitty node --enable-source-maps --inspect dist/start.js",
 				"name": "Run Fosscord with debugger (kitty)",
 				"request": "launch",
 				"type": "node-terminal"
diff --git a/package.json b/package.json
index 014e8fcd..a5de4ef1 100644
--- a/package.json
+++ b/package.json
@@ -66,6 +66,7 @@
 		"ajv": "^8.11.0",
 		"ajv-formats": "^2.1.1",
 		"amqplib": "^0.10.1",
+		"bcrypt": "^5.0.1",
 		"bcryptjs": "^2.4.3",
 		"body-parser": "^1.19.0",
 		"cheerio": "^1.0.0-rc.10",
diff --git a/scripts/build.js b/scripts/build.js
index 6cf4e818..c76f49b6 100644
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -30,10 +30,10 @@ if (silent) console.error = console.log = function () {};
 if (argv.includes("clean")) {
 	console.log(`[${++i}/${steps}] Cleaning...`);
 	let d = "../" + "/dist";
-		if (fs.existsSync(d)) {
-			fs.rmSync(d, { recursive: true });
-			if (verbose) console.log(`Deleted ${d}!`);
-		}
+	if (fs.existsSync(d)) {
+		fs.rmSync(d, { recursive: true });
+		if (verbose) console.log(`Deleted ${d}!`);
+	}
 }
 
 console.log(`[${++i}/${steps}] Compiling src files ...`);
@@ -110,7 +110,7 @@ if (!argv.includes("copyonly")) {
 }
 
 console.log(`[${++i}/${steps}] Copying plugin data...`);
-let pluginFiles = walk(pluginDir).filter(x=>!x.endsWith('.ts'));
-pluginFiles.forEach(x=>{
-	fs.copyFileSync(x, x.replace('src','dist'))
-})
\ No newline at end of file
+let pluginFiles = walk(pluginDir).filter((x) => !x.endsWith(".ts"));
+pluginFiles.forEach((x) => {
+	fs.copyFileSync(x, x.replace("src", "dist"));
+});
diff --git a/src/api/Server.ts b/src/api/Server.ts
index 03c68af1..007c8163 100644
--- a/src/api/Server.ts
+++ b/src/api/Server.ts
@@ -1,5 +1,6 @@
 import { Config, getOrInitialiseDatabase, initEvent, registerRoutes } from "@fosscord/util";
 import { NextFunction, Request, Response, Router } from "express";
+import fs from "fs";
 import { Server, ServerOptions } from "lambert-server";
 import morgan from "morgan";
 import path from "path";
@@ -12,8 +13,6 @@ import { initRateLimits } from "./middlewares/RateLimit";
 import TestClient from "./middlewares/TestClient";
 import { initTranslation } from "./middlewares/Translation";
 import { initInstance } from "./util/handlers/Instance";
-import fs from "fs";
-import { PluginConfig } from "util/plugin/PluginConfig";
 
 export interface FosscordServerOptions extends ServerOptions {}
 
diff --git a/src/util/plugin/PluginConfig.ts b/src/util/plugin/PluginConfig.ts
index b9c8aef0..17ec172c 100644
--- a/src/util/plugin/PluginConfig.ts
+++ b/src/util/plugin/PluginConfig.ts
@@ -57,12 +57,14 @@ function applyConfig(val: any) {
 		if (!pair) pair = new PluginConfigEntity();
 
 		pair.key = key;
-		pair.value = obj;
-		if (!pair.key || pair.key == null) {
-			console.log(`[PluginConfig] WARN: Empty key`);
-			console.log(pair);
-			if (Environment.isDebug) debugger;
-		} else return pair.save();
+		if (pair.value != obj) {
+			pair.value = obj;
+			if (!pair.key || pair.key == null) {
+				console.log(`[PluginConfig] WARN: Empty key`);
+				console.log(pair);
+				if (Environment.isDebug) debugger;
+			} else return pair.save();
+		}
 	}
 	if (process.env.PLUGIN_CONFIG_PATH) {
 		if (Environment.isDebug) console.log(`Writing config: ${process.env.PLUGIN_CONFIG_PATH}`);
diff --git a/src/util/util/Config.ts b/src/util/util/Config.ts
index 2879b955..567cf129 100644
--- a/src/util/util/Config.ts
+++ b/src/util/util/Config.ts
@@ -5,7 +5,6 @@ import { ConfigValue } from "../config";
 import { ConfigEntity } from "../entities/Config";
 
 const overridePath = process.env.CONFIG_PATH ?? "";
-const initialPath = path.join(process.cwd(), "initial.json");
 
 let config: ConfigValue;
 let pairs: ConfigEntity[];
@@ -18,25 +17,21 @@ export const Config = {
 		if (config) return config;
 		console.log("[Config] Loading configuration...");
 		pairs = await ConfigEntity.find();
+		console.log(`[Config] Loaded ${pairs.length} configuration pairs`);
 		config = pairsToConfig(pairs);
+		console.log("[Config] Configuration loaded");
 		//config = (config || {}).merge(new ConfigValue());
 		config = OrmUtils.mergeDeep(new ConfigValue(), config);
+		console.log("[Config] Configuration merged");
 
 		if (process.env.CONFIG_PATH)
 			try {
 				const overrideConfig = JSON.parse(fs.readFileSync(overridePath, { encoding: "utf8" }));
 				config = OrmUtils.mergeDeep(config, overrideConfig);
+				console.log("[Config] Override configuration loaded");
 			} catch (error) {
 				fs.writeFileSync(overridePath, JSON.stringify(config, null, 4));
 			}
-		if (fs.existsSync(initialPath)) {
-			console.log("[Config] Importing initial configuration...");
-			try {
-				const overrideConfig = JSON.parse(fs.readFileSync(initialPath, { encoding: "utf8" }));
-				config = overrideConfig.merge(config);
-				fs.rmSync(initialPath);
-			} catch (error) {}
-		}
 
 		if (fs.existsSync(path.join(process.cwd(), "initial.json")))
 			try {
@@ -77,8 +72,10 @@ function applyConfig(val: ConfigValue) {
 		if (!pair) pair = new ConfigEntity();
 
 		pair.key = key;
-		pair.value = obj;
-		return pair.save();
+		if (pair.value != obj) {
+			pair.value = obj;
+			return pair.save();
+		}
 	}
 	if (process.env.CONFIG_PATH) {
 		if (/--debug|--inspect/.test(process.execArgv.join(" "))) console.log(`Writing config: ${process.env.CONFIG_PATH}`);