feat(webui): change server config through UI #294
							
								
								
									
										10
									
								
								src/controllers/custom/getConfigData.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/controllers/custom/getConfigData.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					import path from "path";
 | 
				
			||||||
 | 
					const rootDir = path.join(__dirname, "../../..");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getConfigData: RequestHandler = (_req, res) => {
 | 
				
			||||||
 | 
					    const configFile = require(path.join(rootDir, "config.json"));
 | 
				
			||||||
 | 
					    res.json(configFile);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export { getConfigData };
 | 
				
			||||||
							
								
								
									
										16
									
								
								src/controllers/custom/updateConfigData.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/controllers/custom/updateConfigData.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					import path from "path";
 | 
				
			||||||
 | 
					const rootDir = path.join(__dirname, "../../..");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const updateConfigData: RequestHandler = async (req) => {
 | 
				
			||||||
 | 
					    const fs = require('fs');
 | 
				
			||||||
 | 
					    const updateSettingsData = req.body;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    fs.writeFile(path.join(rootDir, "config.json"), updateSettingsData, function(err:any) {
 | 
				
			||||||
 | 
					        if(err) {
 | 
				
			||||||
 | 
					            return console.log(err);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export { updateConfigData };
 | 
				
			||||||
@ -2,6 +2,8 @@ import express from "express";
 | 
				
			|||||||
import { getItemListsController } from "@/src/controllers/custom/getItemListsController";
 | 
					import { getItemListsController } from "@/src/controllers/custom/getItemListsController";
 | 
				
			||||||
import { createAccountController } from "@/src/controllers/custom/createAccountController";
 | 
					import { createAccountController } from "@/src/controllers/custom/createAccountController";
 | 
				
			||||||
import { addItemController } from "@/src/controllers/custom/addItemController";
 | 
					import { addItemController } from "@/src/controllers/custom/addItemController";
 | 
				
			||||||
 | 
					import { getConfigData } from "@/src/controllers/custom/getConfigData";
 | 
				
			||||||
 | 
					import { updateConfigData } from "@/src/controllers/custom/updateConfigData";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const customRouter = express.Router();
 | 
					const customRouter = express.Router();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -10,4 +12,7 @@ customRouter.get("/getItemLists", getItemListsController);
 | 
				
			|||||||
customRouter.post("/createAccount", createAccountController);
 | 
					customRouter.post("/createAccount", createAccountController);
 | 
				
			||||||
customRouter.post("/addItem", addItemController);
 | 
					customRouter.post("/addItem", addItemController);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					customRouter.get("/config", getConfigData);
 | 
				
			||||||
 | 
					customRouter.post("/config", updateConfigData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { customRouter };
 | 
					export { customRouter };
 | 
				
			||||||
@ -19,6 +19,9 @@ webuiRouter.use("/webui", (req, res, next) => {
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Serve virtual routes
 | 
					// Serve virtual routes
 | 
				
			||||||
 | 
					webuiRouter.get("/webui/settings", (_req, res) => {
 | 
				
			||||||
 | 
					    res.sendFile(path.join(rootDir, "static/webui/index.html"));
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
webuiRouter.get("/webui/inventory", (_req, res) => {
 | 
					webuiRouter.get("/webui/inventory", (_req, res) => {
 | 
				
			||||||
    res.sendFile(path.join(rootDir, "static/webui/index.html"));
 | 
					    res.sendFile(path.join(rootDir, "static/webui/index.html"));
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@
 | 
				
			|||||||
        <link rel="stylesheet" href="libs/bootstrap.min.css" />
 | 
					        <link rel="stylesheet" href="libs/bootstrap.min.css" />
 | 
				
			||||||
        <link rel="stylesheet" href="style.css" />
 | 
					        <link rel="stylesheet" href="style.css" />
 | 
				
			||||||
    </head>
 | 
					    </head>
 | 
				
			||||||
    <body>
 | 
					    <body onload="fetchSettings()">
 | 
				
			||||||
        <nav class="navbar sticky-top bg-body-tertiary">
 | 
					        <nav class="navbar sticky-top bg-body-tertiary">
 | 
				
			||||||
            <div class="container">
 | 
					            <div class="container">
 | 
				
			||||||
                <button
 | 
					                <button
 | 
				
			||||||
@ -47,6 +47,16 @@
 | 
				
			|||||||
                <div class="offcanvas-body">
 | 
					                <div class="offcanvas-body">
 | 
				
			||||||
                    <div class="navbar p-0">
 | 
					                    <div class="navbar p-0">
 | 
				
			||||||
                        <ul class="navbar-nav justify-content-end">
 | 
					                        <ul class="navbar-nav justify-content-end">
 | 
				
			||||||
 | 
					                            <li class="nav-item">
 | 
				
			||||||
 | 
					                                <a
 | 
				
			||||||
 | 
					                                    class="nav-link"
 | 
				
			||||||
 | 
					                                    href="/webui/settings"
 | 
				
			||||||
 | 
					                                    data-bs-dismiss="offcanvas"
 | 
				
			||||||
 | 
					                                    data-bs-target="#sidebar"
 | 
				
			||||||
 | 
					                                >
 | 
				
			||||||
 | 
					                                    Settings
 | 
				
			||||||
 | 
					                                </a>
 | 
				
			||||||
 | 
					                            </li>
 | 
				
			||||||
                            <li class="nav-item">
 | 
					                            <li class="nav-item">
 | 
				
			||||||
                                <a
 | 
					                                <a
 | 
				
			||||||
                                    class="nav-link"
 | 
					                                    class="nav-link"
 | 
				
			||||||
@ -72,10 +82,6 @@
 | 
				
			|||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div>
 | 
					            <div>
 | 
				
			||||||
                <p id="refresh-note" class="mb-4">
 | 
					 | 
				
			||||||
                    Note: Changes made here will only be reflected in-game when the game re-downloads your inventory.
 | 
					 | 
				
			||||||
                    Visiting the navigation should be the easiest way to trigger that.
 | 
					 | 
				
			||||||
                </p>
 | 
					 | 
				
			||||||
                <div data-route="/webui/" data-title="Login | OpenWF WebUI">
 | 
					                <div data-route="/webui/" data-title="Login | OpenWF WebUI">
 | 
				
			||||||
                    <p>Login using your OpenWF account credentials.</p>
 | 
					                    <p>Login using your OpenWF account credentials.</p>
 | 
				
			||||||
                    <form onsubmit="doLogin();return false;">
 | 
					                    <form onsubmit="doLogin();return false;">
 | 
				
			||||||
@ -88,7 +94,67 @@
 | 
				
			|||||||
                        <button class="btn btn-primary" type="submit">Login</button>
 | 
					                        <button class="btn btn-primary" type="submit">Login</button>
 | 
				
			||||||
                    </form>
 | 
					                    </form>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 | 
					                <div data-route="/webui/settings" data-title="Settings | OpenWF WebUI">
 | 
				
			||||||
 | 
					                    <div class="card mb-4">
 | 
				
			||||||
 | 
					                        <h5 class="card-header">Change Settings</h5>
 | 
				
			||||||
 | 
					                        <form class="card-body" onsubmit="doChangeSettings();return false;">
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="skipStoryModeChoice"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="skipStoryModeChoice">Skip Story Mode Choice?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="skipTutorial"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="skipTutorial">Skip Tutorial?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllScans"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllScans">Unlock All Scans?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllMissions"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllMissions">Unlock All Missions?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllQuests"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllQuests">Unlock All Quests?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="completeAllQuests"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="completeAllQuests">Complete All Quests?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="infiniteResources"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="infiniteResources">Infinite Credits and Platinum?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockallShipFeatures"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockallShipFeatures">Unlock All Ship Features?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllShipDecorations"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllShipDecorations">Unlock All Ship Decorations?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllFlavourItems"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllFlavourItems">Unlock All Accessories?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <input class="form-check-input" type="checkbox" value="" id="unlockAllSkins"  />
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="unlockAllSkins">Unlock All Skins?</label>
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <div class="form-check">
 | 
				
			||||||
 | 
					                                <label label class="form-check-label" for="spoofMasteryRank">Spoofed Mastery Rank (-1 to disable)</label>
 | 
				
			||||||
 | 
					                                <input class="form-control" id="spoofMasteryRank" type="number" min="-1" value="" />
 | 
				
			||||||
 | 
					                            </div>
 | 
				
			||||||
 | 
					                            <button class="btn btn-primary" type="submit">Save Settings</button>
 | 
				
			||||||
 | 
					                        </form>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
                <div data-route="/webui/inventory" data-title="Inventory | OpenWF WebUI">
 | 
					                <div data-route="/webui/inventory" data-title="Inventory | OpenWF WebUI">
 | 
				
			||||||
 | 
					                    <p id="refresh-note" class="mb-4">
 | 
				
			||||||
 | 
					                        Note: Changes made here will only be reflected in-game when the game re-downloads your inventory.
 | 
				
			||||||
 | 
					                        Visiting the navigation should be the easiest way to trigger that.
 | 
				
			||||||
 | 
					                    </p>
 | 
				
			||||||
                    <div class="card mb-4">
 | 
					                    <div class="card mb-4">
 | 
				
			||||||
                        <h5 class="card-header">Add Items</h5>
 | 
					                        <h5 class="card-header">Add Items</h5>
 | 
				
			||||||
                        <form class="card-body input-group" onsubmit="doAcquireMiscItems();return false;">
 | 
					                        <form class="card-body input-group" onsubmit="doAcquireMiscItems();return false;">
 | 
				
			||||||
@ -133,6 +199,10 @@
 | 
				
			|||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <div data-route="/webui/mods" data-title="Mods | OpenWF WebUI">
 | 
					                <div data-route="/webui/mods" data-title="Mods | OpenWF WebUI">
 | 
				
			||||||
 | 
					                    <p id="refresh-note" class="mb-4">
 | 
				
			||||||
 | 
					                        Note: Changes made here will only be reflected in-game when the game re-downloads your inventory.
 | 
				
			||||||
 | 
					                        Visiting the navigation should be the easiest way to trigger that.
 | 
				
			||||||
 | 
					                    </p>
 | 
				
			||||||
                    <div class="row">
 | 
					                    <div class="row">
 | 
				
			||||||
                        <div class="col-xxl-6">
 | 
					                        <div class="col-xxl-6">
 | 
				
			||||||
                            <div class="card mb-4">
 | 
					                            <div class="card mb-4">
 | 
				
			||||||
 | 
				
			|||||||
@ -95,17 +95,15 @@ window.itemListPromise = new Promise(resolve => {
 | 
				
			|||||||
            "/Lotus/Weapons/Tenno/Rifle/LotusRifle": { name: "Rifle" },
 | 
					            "/Lotus/Weapons/Tenno/Rifle/LotusRifle": { name: "Rifle" },
 | 
				
			||||||
            "/Lotus/Weapons/Tenno/Shotgun/LotusShotgun": { name: "Shotgun" },
 | 
					            "/Lotus/Weapons/Tenno/Shotgun/LotusShotgun": { name: "Shotgun" },
 | 
				
			||||||
            // Missing in data sources
 | 
					            // Missing in data sources
 | 
				
			||||||
            "/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" }
 | 
					            "/Lotus/Upgrades/CosmeticEnhancers/Peculiars/CyoteMod": { name: "Traumatic Peculiar" },
 | 
				
			||||||
 | 
					            "/Lotus/Weapons/Tenno/Grimoire/TnGrimoire": { name: "Grimoire" }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        for (const [type, items] of Object.entries(data)) {
 | 
					        for (const [type, items] of Object.entries(data)) {
 | 
				
			||||||
            if (type != "badItems") {
 | 
					            if (type != "badItems") {
 | 
				
			||||||
                items.forEach(item => {
 | 
					                items.forEach(item => {
 | 
				
			||||||
                    if (item.uniqueName in data.badItems) {
 | 
					                    if (item.uniqueName in data.badItems) {
 | 
				
			||||||
                        item.name += " (Imposter)";
 | 
					                        item.name += " (Imposter)";
 | 
				
			||||||
                    } else if (
 | 
					                    } else if (item.uniqueName.substr(0, 18) != "/Lotus/Types/Game/") {
 | 
				
			||||||
                        item.uniqueName.substr(0, 18) != "/Lotus/Types/Game/" &&
 | 
					 | 
				
			||||||
                        item.uniqueName.substr(0, 18) != "/Lotus/StoreItems/"
 | 
					 | 
				
			||||||
                    ) {
 | 
					 | 
				
			||||||
                        const option = document.createElement("option");
 | 
					                        const option = document.createElement("option");
 | 
				
			||||||
                        option.setAttribute("data-key", item.uniqueName);
 | 
					                        option.setAttribute("data-key", item.uniqueName);
 | 
				
			||||||
                        option.value = item.name;
 | 
					                        option.value = item.name;
 | 
				
			||||||
@ -618,3 +616,47 @@ function doAcquireMod() {
 | 
				
			|||||||
$("#mod-to-acquire").on("input", () => {
 | 
					$("#mod-to-acquire").on("input", () => {
 | 
				
			||||||
    $("#mod-to-acquire").removeClass("is-invalid");
 | 
					    $("#mod-to-acquire").removeClass("is-invalid");
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fetchSettings() {
 | 
				
			||||||
 | 
					    fetch('/custom/config')
 | 
				
			||||||
 | 
					        .then((response) => response.json())
 | 
				
			||||||
 | 
					        .then((json) => Object.entries(json).forEach((entry) => {
 | 
				
			||||||
 | 
					            const [key, value] = entry;
 | 
				
			||||||
 | 
					            var x = document.getElementById(`${key}`);
 | 
				
			||||||
 | 
					            if (x!=null) {
 | 
				
			||||||
 | 
					                if (x.type == "checkbox") {
 | 
				
			||||||
 | 
					                    if (value === true) {
 | 
				
			||||||
 | 
					                        x.setAttribute("checked", "checked")
 | 
				
			||||||
 | 
					                    } 
 | 
				
			||||||
 | 
					                } else if (x.type == "number") {
 | 
				
			||||||
 | 
					                    x.setAttribute("value", `${value}`)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function doChangeSettings() {
 | 
				
			||||||
 | 
					    fetch('/custom/config')
 | 
				
			||||||
 | 
					        .then((response) => response.json())
 | 
				
			||||||
 | 
					        .then((json) => {
 | 
				
			||||||
 | 
					            for(var i in json) {
 | 
				
			||||||
 | 
					                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",
 | 
				
			||||||
 | 
					                contentType: "text/plain",
 | 
				
			||||||
 | 
					                data: JSON.stringify(json, null, 2)
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user