From 492a53093ba0dd20526a44cb1b31e521c94c5047 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 17 Jul 2025 14:05:34 +0200 Subject: [PATCH 1/2] chore(webui): don't refresh inventory for sell on the tab that issued it --- src/controllers/api/sellController.ts | 4 ++-- src/controllers/custom/configController.ts | 4 ++-- src/services/wsService.ts | 12 +++++++++--- static/webui/script.js | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/controllers/api/sellController.ts b/src/controllers/api/sellController.ts index c82d3b6b..0dd52bf6 100644 --- a/src/controllers/api/sellController.ts +++ b/src/controllers/api/sellController.ts @@ -15,7 +15,7 @@ import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; import { ExportDojoRecipes } from "warframe-public-export-plus"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; -import { sendWsBroadcastTo } from "@/src/services/wsService"; +import { sendWsBroadcastEx } from "@/src/services/wsService"; export const sellController: RequestHandler = async (req, res) => { const payload = JSON.parse(String(req.body)) as ISellRequest; @@ -295,7 +295,7 @@ export const sellController: RequestHandler = async (req, res) => { res.json({ inventoryChanges: inventoryChanges // "inventoryChanges" for this response instead of the usual "InventoryChanges" }); - sendWsBroadcastTo(accountId, { update_inventory: true }); + sendWsBroadcastEx({ update_inventory: true }, accountId, parseInt(String(req.query.wsid))); }; interface ISellRequest { diff --git a/src/controllers/custom/configController.ts b/src/controllers/custom/configController.ts index 2a1aca25..fa1b4a2c 100644 --- a/src/controllers/custom/configController.ts +++ b/src/controllers/custom/configController.ts @@ -2,7 +2,7 @@ import { RequestHandler } from "express"; import { config, syncConfigWithDatabase } from "@/src/services/configService"; import { getAccountForRequest, isAdministrator } from "@/src/services/loginService"; import { saveConfig } from "@/src/services/configWriterService"; -import { sendWsBroadcastExcept } from "@/src/services/wsService"; +import { sendWsBroadcastEx } from "@/src/services/wsService"; export const getConfigController: RequestHandler = async (req, res) => { const account = await getAccountForRequest(req); @@ -25,7 +25,7 @@ export const setConfigController: RequestHandler = async (req, res) => { const [obj, idx] = configIdToIndexable(id); obj[idx] = value; } - sendWsBroadcastExcept(parseInt(String(req.query.wsid)), { config_reloaded: true }); + sendWsBroadcastEx({ config_reloaded: true }, undefined, parseInt(String(req.query.wsid))); syncConfigWithDatabase(); await saveConfig(); res.end(); diff --git a/src/services/wsService.ts b/src/services/wsService.ts index 209b1bc9..7421bc10 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -181,18 +181,24 @@ export const sendWsBroadcastTo = (accountId: string, data: IWsMsgToClient): void } }; -export const sendWsBroadcastExcept = (wsid: number | undefined, data: IWsMsgToClient): void => { +export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excludeWsid?: number): void => { const msg = JSON.stringify(data); if (wsServer) { for (const client of wsServer.clients) { - if ((client as IWsCustomData).id != wsid) { + if ( + (!accountId || (client as IWsCustomData).accountId == accountId) && + (!excludeWsid || (client as IWsCustomData).id != excludeWsid) + ) { client.send(msg); } } } if (wssServer) { for (const client of wssServer.clients) { - if ((client as IWsCustomData).id != wsid) { + if ( + (!accountId || (client as IWsCustomData).accountId == accountId) && + (!excludeWsid || (client as IWsCustomData).id != excludeWsid) + ) { client.send(msg); } } diff --git a/static/webui/script.js b/static/webui/script.js index 530c88fd..6ab0fe65 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1746,7 +1746,7 @@ function disposeOfGear(category, oid) { ]; revalidateAuthz().then(() => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify(data) }); @@ -1768,7 +1768,7 @@ function disposeOfItems(category, type, count) { ]; revalidateAuthz().then(() => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify(data) }); @@ -2202,7 +2202,7 @@ function doRemoveUnrankedMods() { req.done(inventory => { window.itemListPromise.then(itemMap => { $.post({ - url: "/api/sell.php?" + window.authz, + url: "/api/sell.php?" + window.authz + "&wsid=" + wsid, contentType: "text/plain", data: JSON.stringify({ SellCurrency: "SC_RegularCredits", -- 2.47.2 From 64ebcad7fccc8962bd4cc5b36717413eb7b552df Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 17 Jul 2025 14:07:21 +0200 Subject: [PATCH 2/2] wsid cannot be undefined --- src/services/wsService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/wsService.ts b/src/services/wsService.ts index 7421bc10..1b49ae3e 100644 --- a/src/services/wsService.ts +++ b/src/services/wsService.ts @@ -43,7 +43,7 @@ export const stopWsServers = (promises: Promise[]): void => { let lastWsid: number = 0; interface IWsCustomData extends ws { - id?: number; + id: number; accountId?: string; } @@ -187,7 +187,7 @@ export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excl for (const client of wsServer.clients) { if ( (!accountId || (client as IWsCustomData).accountId == accountId) && - (!excludeWsid || (client as IWsCustomData).id != excludeWsid) + (client as IWsCustomData).id != excludeWsid ) { client.send(msg); } @@ -197,7 +197,7 @@ export const sendWsBroadcastEx = (data: IWsMsgToClient, accountId?: string, excl for (const client of wssServer.clients) { if ( (!accountId || (client as IWsCustomData).accountId == accountId) && - (!excludeWsid || (client as IWsCustomData).id != excludeWsid) + (client as IWsCustomData).id != excludeWsid ) { client.send(msg); } -- 2.47.2