From dabca46e884b605ee06cdd7cc04a0d08aa2559c1 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 18 Jun 2025 11:05:07 -0700 Subject: [PATCH 1/4] feat(webui): automatically commit toggle changes (#2198) Closes #2197 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2198 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- .../custom/updateConfigDataController.ts | 14 ++++-- src/services/configService.ts | 2 +- src/services/configWatcherService.ts | 6 --- static/webui/index.html | 23 +++++---- static/webui/script.js | 47 +++++++++---------- static/webui/translations/de.js | 2 +- static/webui/translations/en.js | 2 +- static/webui/translations/es.js | 2 +- static/webui/translations/fr.js | 2 +- static/webui/translations/ru.js | 2 +- static/webui/translations/zh.js | 2 +- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/controllers/custom/updateConfigDataController.ts b/src/controllers/custom/updateConfigDataController.ts index 534dfe0f..7c87c372 100644 --- a/src/controllers/custom/updateConfigDataController.ts +++ b/src/controllers/custom/updateConfigDataController.ts @@ -1,15 +1,21 @@ import { RequestHandler } from "express"; -import { updateConfig } from "@/src/services/configWatcherService"; +import { saveConfig } from "@/src/services/configWatcherService"; import { getAccountForRequest, isAdministrator } from "@/src/services/loginService"; +import { config, IConfig } from "@/src/services/configService"; -const updateConfigDataController: RequestHandler = async (req, res) => { +export const updateConfigDataController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); if (isAdministrator(account)) { - await updateConfig(String(req.body)); + const data = req.body as IUpdateConfigDataRequest; + config[data.key] = data.value; + await saveConfig(); res.end(); } else { res.status(401).end(); } }; -export { updateConfigDataController }; +interface IUpdateConfigDataRequest { + key: keyof IConfig; + value: never; +} diff --git a/src/services/configService.ts b/src/services/configService.ts index fbcda8af..aeabb306 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -2,7 +2,7 @@ import fs from "fs"; import path from "path"; import { repoDir } from "@/src/helpers/pathHelper"; -interface IConfig { +export interface IConfig { mongodbUrl: string; logger: { files: boolean; diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index 88a5acdc..544bd96c 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -46,12 +46,6 @@ export const validateConfig = (): void => { } }; -export const updateConfig = async (data: string): Promise => { - amnesia = true; - await fsPromises.writeFile(configPath, data); - Object.assign(config, JSON.parse(data)); -}; - export const saveConfig = async (): Promise => { amnesia = true; await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2)); diff --git a/static/webui/index.html b/static/webui/index.html index 398eb647..9b9015a2 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -571,7 +571,7 @@

-
+
@@ -732,16 +732,21 @@
-
+ - -
-
+
+ + +
+ +
- -
- - +
+ + +
+ +
diff --git a/static/webui/script.js b/static/webui/script.js index b51648e1..bb7ec52a 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1761,34 +1761,29 @@ function doAcquireMod() { const uiConfigs = [...$("#server-settings input[id]")].map(x => x.id); -function doChangeSettings() { - revalidateAuthz(() => { - fetch("/custom/config?" + window.authz) - .then(response => response.json()) - .then(json => { - for (const i of uiConfigs) { - var x = document.getElementById(i); - if (x != null) { - if (x.type == "checkbox") { - if (x.checked === true) { - json[i] = true; - } else { - json[i] = false; - } - } else if (x.type == "number") { - json[i] = parseInt(x.value); - } - } - } - $.post({ - url: "/custom/config?" + window.authz, - contentType: "text/plain", - data: JSON.stringify(json, null, 2) - }).then(() => { - // A few cheats affect the inventory response which in turn may change what values we need to show +for (const id of uiConfigs) { + const elm = document.getElementById(id); + if (elm.type == "checkbox") { + elm.onchange = function () { + $.post({ + url: "/custom/config?" + window.authz, + contentType: "application/json", + data: JSON.stringify({ key: id, value: this.checked }) + }).then(() => { + if (["infiniteCredits", "infinitePlatinum", "infiniteEndo", "infiniteRegalAya"].indexOf(id) != -1) { updateInventory(); - }); + } }); + }; + } +} + +function doSaveConfig(id) { + const elm = document.getElementById(id); + $.post({ + url: "/custom/config?" + window.authz, + contentType: "application/json", + data: JSON.stringify({ key: id, value: parseInt(elm.value) }) }); } diff --git a/static/webui/translations/de.js b/static/webui/translations/de.js index 8b88151b..a4771cf3 100644 --- a/static/webui/translations/de.js +++ b/static/webui/translations/de.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `Schneller Clan-Aufstieg`, cheats_spoofMasteryRank: `Gefälschter Meisterschaftsrang (-1 zum deaktivieren)`, cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`, - cheats_saveSettings: `Einstellungen speichern`, + cheats_save: `[UNTRANSLATED] Save`, cheats_account: `Account`, cheats_unlockAllFocusSchools: `Alle Fokus-Schulen freischalten`, cheats_helminthUnlockAll: `Helminth vollständig aufleveln`, diff --git a/static/webui/translations/en.js b/static/webui/translations/en.js index 437d5057..f17c2e0a 100644 --- a/static/webui/translations/en.js +++ b/static/webui/translations/en.js @@ -166,7 +166,7 @@ dict = { cheats_fastClanAscension: `Fast Clan Ascension`, cheats_spoofMasteryRank: `Spoofed Mastery Rank (-1 to disable)`, cheats_nightwaveStandingMultiplier: `Nightwave Standing Multiplier`, - cheats_saveSettings: `Save Settings`, + cheats_save: `Save`, cheats_account: `Account`, cheats_unlockAllFocusSchools: `Unlock All Focus Schools`, cheats_helminthUnlockAll: `Fully Level Up Helminth`, diff --git a/static/webui/translations/es.js b/static/webui/translations/es.js index e07199ca..4638debe 100644 --- a/static/webui/translations/es.js +++ b/static/webui/translations/es.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `Ascenso rápido del clan`, cheats_spoofMasteryRank: `Rango de maestría simulado (-1 para desactivar)`, cheats_nightwaveStandingMultiplier: `Multiplicador de Reputación de Onda Nocturna`, - cheats_saveSettings: `Guardar configuración`, + cheats_save: `[UNTRANSLATED] Save`, cheats_account: `Cuenta`, cheats_unlockAllFocusSchools: `Desbloquear todas las escuelas de enfoque`, cheats_helminthUnlockAll: `Subir al máximo el Helminto`, diff --git a/static/webui/translations/fr.js b/static/webui/translations/fr.js index 8d4eceb2..e4c99dd6 100644 --- a/static/webui/translations/fr.js +++ b/static/webui/translations/fr.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `Ascension de clan rapide`, cheats_spoofMasteryRank: `Rang de maîtrise personnalisé (-1 pour désactiver)`, cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`, - cheats_saveSettings: `Sauvegarder les paramètres`, + cheats_save: `[UNTRANSLATED] Save`, cheats_account: `Compte`, cheats_unlockAllFocusSchools: `Débloquer toutes les écoles de focus`, cheats_helminthUnlockAll: `Helminth niveau max`, diff --git a/static/webui/translations/ru.js b/static/webui/translations/ru.js index 7493099d..e0247b7e 100644 --- a/static/webui/translations/ru.js +++ b/static/webui/translations/ru.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `Мгновенное Вознесение Клана`, cheats_spoofMasteryRank: `Подделанный ранг мастерства (-1 для отключения)`, cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`, - cheats_saveSettings: `Сохранить настройки`, + cheats_save: `[UNTRANSLATED] Save`, cheats_account: `Аккаунт`, cheats_unlockAllFocusSchools: `Разблокировать все школы фокуса`, cheats_helminthUnlockAll: `Полностью улучшить Гельминта`, diff --git a/static/webui/translations/zh.js b/static/webui/translations/zh.js index 722b709a..22bc33f9 100644 --- a/static/webui/translations/zh.js +++ b/static/webui/translations/zh.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `快速升级氏族`, cheats_spoofMasteryRank: `伪造精通段位(-1为禁用)`, cheats_nightwaveStandingMultiplier: `午夜电波声望倍率`, - cheats_saveSettings: `保存设置`, + cheats_save: `[UNTRANSLATED] Save`, cheats_account: `账户`, cheats_unlockAllFocusSchools: `解锁所有专精学派`, cheats_helminthUnlockAll: `完全升级Helminth`, From 0c4065619dd8570d2146fd63f81a40db66422f10 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 18 Jun 2025 11:34:12 -0700 Subject: [PATCH 2/4] chore: support config path being specified via command line argument (#2201) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2201 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/index.ts | 6 +++--- src/services/configService.ts | 2 +- src/services/configWatcherService.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index d4b0f810..de36b392 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ // First, init config. -import { config, loadConfig } from "@/src/services/configService"; +import { config, configPath, loadConfig } from "@/src/services/configService"; import fs from "fs"; try { loadConfig(); } catch (e) { if (fs.existsSync("config.json")) { - console.log("Failed to load config.json: " + (e as Error).message); + console.log("Failed to load " + configPath + ": " + (e as Error).message); } else { - console.log("Failed to load config.json. You can copy config.json.example to create your config.json."); + console.log("Failed to load " + configPath + ". You can copy config.json.example to create your config file."); } process.exit(1); } diff --git a/src/services/configService.ts b/src/services/configService.ts index aeabb306..0c09eb23 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -72,7 +72,7 @@ export interface IConfig { }; } -export const configPath = path.join(repoDir, "config.json"); +export const configPath = path.join(repoDir, process.argv[2] ?? "config.json"); export const config: IConfig = { mongodbUrl: "mongodb://127.0.0.1:27017/openWF", diff --git a/src/services/configWatcherService.ts b/src/services/configWatcherService.ts index 544bd96c..197a9567 100644 --- a/src/services/configWatcherService.ts +++ b/src/services/configWatcherService.ts @@ -9,7 +9,7 @@ fs.watchFile(configPath, () => { if (amnesia) { amnesia = false; } else { - logger.info("Detected a change to config.json, reloading its contents."); + logger.info("Detected a change to config file, reloading its contents."); try { loadConfig(); } catch (e) { @@ -41,7 +41,7 @@ export const validateConfig = (): void => { } } if (modified) { - logger.info(`Updating config.json to fix some issues with it.`); + logger.info(`Updating config file to fix some issues with it.`); void saveConfig(); } }; From 7c8e8fe049859711a62af5d3bc1bf5e48ceef206 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 18 Jun 2025 20:40:46 +0200 Subject: [PATCH 3/4] ci: only run on pushes to main Non-main branches are gonna have to open a PR anyway, so we don't need to run it twice. --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aed7014e..2f265a60 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,7 @@ name: Build on: - push: {} + push: + branches: ["main"] pull_request: {} jobs: build: From 2e9d3c33b69f556708fa2b75124d74d42c8d5d9a Mon Sep 17 00:00:00 2001 From: hxedcl Date: Wed, 18 Jun 2025 11:48:22 -0700 Subject: [PATCH 4/4] chore(webui): update to Spanish translation (#2203) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2203 Co-authored-by: hxedcl Co-committed-by: hxedcl --- static/webui/translations/es.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/webui/translations/es.js b/static/webui/translations/es.js index 4638debe..c627dfa2 100644 --- a/static/webui/translations/es.js +++ b/static/webui/translations/es.js @@ -167,7 +167,7 @@ dict = { cheats_fastClanAscension: `Ascenso rápido del clan`, cheats_spoofMasteryRank: `Rango de maestría simulado (-1 para desactivar)`, cheats_nightwaveStandingMultiplier: `Multiplicador de Reputación de Onda Nocturna`, - cheats_save: `[UNTRANSLATED] Save`, + cheats_save: `Guardar`, cheats_account: `Cuenta`, cheats_unlockAllFocusSchools: `Desbloquear todas las escuelas de enfoque`, cheats_helminthUnlockAll: `Subir al máximo el Helminto`,