XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

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>

dabca46e
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

11 个文件 +52 -52
Modified src/controllers/custom/updateConfigDataController.ts +10 -4
@@ -1,15 +1,21 @@
1 1 import { RequestHandler } from "express";
2 import { updateConfig } from "@/src/services/configWatcherService";
2 import { saveConfig } from "@/src/services/configWatcherService";
3 3 import { getAccountForRequest, isAdministrator } from "@/src/services/loginService";
4 import { config, IConfig } from "@/src/services/configService";
4 5
5 const updateConfigDataController: RequestHandler = async (req, res) => {
6 export const updateConfigDataController: RequestHandler = async (req, res) => {
6 7 const account = await getAccountForRequest(req);
7 8 if (isAdministrator(account)) {
8 await updateConfig(String(req.body));
9 const data = req.body as IUpdateConfigDataRequest;
10 config[data.key] = data.value;
11 await saveConfig();
9 12 res.end();
10 13 } else {
11 14 res.status(401).end();
12 15 }
13 16 };
14 17
15 export { updateConfigDataController };
18 interface IUpdateConfigDataRequest {
19 key: keyof IConfig;
20 value: never;
21 }
Modified src/services/configService.ts +1 -1
@@ -2,7 +2,7 @@ import fs from "fs";
2 2 import path from "path";
3 3 import { repoDir } from "@/src/helpers/pathHelper";
4 4
5 interface IConfig {
5 export interface IConfig {
6 6 mongodbUrl: string;
7 7 logger: {
8 8 files: boolean;
Modified src/services/configWatcherService.ts +0 -6
@@ -46,12 +46,6 @@ export const validateConfig = (): void => {
46 46 }
47 47 };
48 48
49 export const updateConfig = async (data: string): Promise<void> => {
50 amnesia = true;
51 await fsPromises.writeFile(configPath, data);
52 Object.assign(config, JSON.parse(data));
53 };
54
55 49 export const saveConfig = async (): Promise<void> => {
56 50 amnesia = true;
57 51 await fsPromises.writeFile(configPath, JSON.stringify(config, null, 2));
Modified static/webui/index.html +14 -9
@@ -571,7 +571,7 @@
571 571 <div id="server-settings-no-perms" class="d-none">
572 572 <p class="card-text" data-loc="cheats_administratorRequirement"></p>
573 573 </div>
574 <form id="server-settings" class="d-none" onsubmit="doChangeSettings();return false;">
574 <div id="server-settings" class="d-none">
575 575 <div class="form-check">
576 576 <input class="form-check-input" type="checkbox" id="skipTutorial" />
577 577 <label class="form-check-label" for="skipTutorial" data-loc="cheats_skipTutorial"></label>
@@ -732,16 +732,21 @@
732 732 <input class="form-check-input" type="checkbox" id="fastClanAscension" />
733 733 <label class="form-check-label" for="fastClanAscension" data-loc="cheats_fastClanAscension"></label>
734 734 </div>
735 <div class="form-group mt-2">
735 <form class="form-group mt-2" onsubmit="doSaveConfig('spoofMasteryRank'); return false;">
736 736 <label class="form-label" for="spoofMasteryRank" data-loc="cheats_spoofMasteryRank"></label>
737 <input class="form-control" id="spoofMasteryRank" type="number" min="-1" max="65535" />
738 </div>
739 <div class="form-group mt-2">
737 <div class="input-group">
738 <input class="form-control" id="spoofMasteryRank" type="number" min="-1" max="65535" />
739 <button class="btn btn-primary" type="submit" data-loc="cheats_save"></button>
740 </div>
741 </form>
742 <form class="form-group mt-2" onsubmit="doSaveConfig('nightwaveStandingMultiplier'); return false;">
740 743 <label class="form-label" for="nightwaveStandingMultiplier" data-loc="cheats_nightwaveStandingMultiplier"></label>
741 <input class="form-control" id="nightwaveStandingMultiplier" type="number" min="1" max="1000000" value="1" />
742 </div>
743 <button class="btn btn-primary mt-3" type="submit" data-loc="cheats_saveSettings"></button>
744 </form>
744 <div class="input-group">
745 <input class="form-control" id="nightwaveStandingMultiplier" type="number" min="1" max="1000000" value="1" />
746 <button class="btn btn-primary" type="submit" data-loc="cheats_save"></button>
747 </div>
748 </form>
749 </div>
745 750 </div>
746 751 </div>
747 752 </div>
Modified static/webui/script.js +21 -26
@@ -1761,34 +1761,29 @@ function doAcquireMod() {
1761 1761
1762 1762 const uiConfigs = [...$("#server-settings input[id]")].map(x => x.id);
1763 1763
1764 function doChangeSettings() {
1765 revalidateAuthz(() => {
1766 fetch("/custom/config?" + window.authz)
1767 .then(response => response.json())
1768 .then(json => {
1769 for (const i of uiConfigs) {
1770 var x = document.getElementById(i);
1771 if (x != null) {
1772 if (x.type == "checkbox") {
1773 if (x.checked === true) {
1774 json[i] = true;
1775 } else {
1776 json[i] = false;
1777 }
1778 } else if (x.type == "number") {
1779 json[i] = parseInt(x.value);
1780 }
1781 }
1782 }
1783 $.post({
1784 url: "/custom/config?" + window.authz,
1785 contentType: "text/plain",
1786 data: JSON.stringify(json, null, 2)
1787 }).then(() => {
1788 // A few cheats affect the inventory response which in turn may change what values we need to show
1764 for (const id of uiConfigs) {
1765 const elm = document.getElementById(id);
1766 if (elm.type == "checkbox") {
1767 elm.onchange = function () {
1768 $.post({
1769 url: "/custom/config?" + window.authz,
1770 contentType: "application/json",
1771 data: JSON.stringify({ key: id, value: this.checked })
1772 }).then(() => {
1773 if (["infiniteCredits", "infinitePlatinum", "infiniteEndo", "infiniteRegalAya"].indexOf(id) != -1) {
1789 1774 updateInventory();
1790 });
1775 }
1791 1776 });
1777 };
1778 }
1779 }
1780
1781 function doSaveConfig(id) {
1782 const elm = document.getElementById(id);
1783 $.post({
1784 url: "/custom/config?" + window.authz,
1785 contentType: "application/json",
1786 data: JSON.stringify({ key: id, value: parseInt(elm.value) })
1792 1787 });
1793 1788 }
1794 1789
Modified static/webui/translations/de.js +1 -1
@@ -167,7 +167,7 @@ dict = {
167 167 cheats_fastClanAscension: `Schneller Clan-Aufstieg`,
168 168 cheats_spoofMasteryRank: `Gefälschter Meisterschaftsrang (-1 zum deaktivieren)`,
169 169 cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`,
170 cheats_saveSettings: `Einstellungen speichern`,
170 cheats_save: `[UNTRANSLATED] Save`,
171 171 cheats_account: `Account`,
172 172 cheats_unlockAllFocusSchools: `Alle Fokus-Schulen freischalten`,
173 173 cheats_helminthUnlockAll: `Helminth vollständig aufleveln`,
Modified static/webui/translations/en.js +1 -1
@@ -166,7 +166,7 @@ dict = {
166 166 cheats_fastClanAscension: `Fast Clan Ascension`,
167 167 cheats_spoofMasteryRank: `Spoofed Mastery Rank (-1 to disable)`,
168 168 cheats_nightwaveStandingMultiplier: `Nightwave Standing Multiplier`,
169 cheats_saveSettings: `Save Settings`,
169 cheats_save: `Save`,
170 170 cheats_account: `Account`,
171 171 cheats_unlockAllFocusSchools: `Unlock All Focus Schools`,
172 172 cheats_helminthUnlockAll: `Fully Level Up Helminth`,
Modified static/webui/translations/es.js +1 -1
@@ -167,7 +167,7 @@ dict = {
167 167 cheats_fastClanAscension: `Ascenso rápido del clan`,
168 168 cheats_spoofMasteryRank: `Rango de maestría simulado (-1 para desactivar)`,
169 169 cheats_nightwaveStandingMultiplier: `Multiplicador de Reputación de Onda Nocturna`,
170 cheats_saveSettings: `Guardar configuración`,
170 cheats_save: `[UNTRANSLATED] Save`,
171 171 cheats_account: `Cuenta`,
172 172 cheats_unlockAllFocusSchools: `Desbloquear todas las escuelas de enfoque`,
173 173 cheats_helminthUnlockAll: `Subir al máximo el Helminto`,
Modified static/webui/translations/fr.js +1 -1
@@ -167,7 +167,7 @@ dict = {
167 167 cheats_fastClanAscension: `Ascension de clan rapide`,
168 168 cheats_spoofMasteryRank: `Rang de maîtrise personnalisé (-1 pour désactiver)`,
169 169 cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`,
170 cheats_saveSettings: `Sauvegarder les paramètres`,
170 cheats_save: `[UNTRANSLATED] Save`,
171 171 cheats_account: `Compte`,
172 172 cheats_unlockAllFocusSchools: `Débloquer toutes les écoles de focus`,
173 173 cheats_helminthUnlockAll: `Helminth niveau max`,
Modified static/webui/translations/ru.js +1 -1
@@ -167,7 +167,7 @@ dict = {
167 167 cheats_fastClanAscension: `Мгновенное Вознесение Клана`,
168 168 cheats_spoofMasteryRank: `Подделанный ранг мастерства (-1 для отключения)`,
169 169 cheats_nightwaveStandingMultiplier: `[UNTRANSLATED] Nightwave Standing Multiplier`,
170 cheats_saveSettings: `Сохранить настройки`,
170 cheats_save: `[UNTRANSLATED] Save`,
171 171 cheats_account: `Аккаунт`,
172 172 cheats_unlockAllFocusSchools: `Разблокировать все школы фокуса`,
173 173 cheats_helminthUnlockAll: `Полностью улучшить Гельминта`,
Modified static/webui/translations/zh.js +1 -1
@@ -167,7 +167,7 @@ dict = {
167 167 cheats_fastClanAscension: `快速升级氏族`,
168 168 cheats_spoofMasteryRank: `伪造精通段位(-1为禁用)`,
169 169 cheats_nightwaveStandingMultiplier: `午夜电波声望倍率`,
170 cheats_saveSettings: `保存设置`,
170 cheats_save: `[UNTRANSLATED] Save`,
171 171 cheats_account: `账户`,
172 172 cheats_unlockAllFocusSchools: `解锁所有专精学派`,
173 173 cheats_helminthUnlockAll: `完全升级Helminth`,