1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 02:12:40 +01:00
This commit is contained in:
TheArcaneBrony 2022-08-24 03:02:05 +02:00
parent 5deaed33ed
commit 5c146b16bc
No known key found for this signature in database
GPG Key ID: 32FC5AAADAD75A22
6 changed files with 27 additions and 28 deletions

View File

@ -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"

View File

@ -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",

View File

@ -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'))
})
let pluginFiles = walk(pluginDir).filter((x) => !x.endsWith(".ts"));
pluginFiles.forEach((x) => {
fs.copyFileSync(x, x.replace("src", "dist"));
});

View File

@ -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 {}

View File

@ -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}`);

View File

@ -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}`);