From 9b51a0beb71275a1259e14dee021beb0078799da Mon Sep 17 00:00:00 2001 From: Shiroki Date: Thu, 1 Feb 2024 06:16:58 +0800 Subject: [PATCH] feat: parsing stdout of steamcmd require a i386 stdbuf (from coreutils) to change buffer strategy of steamcmd --- frontend/interfaces/gateway.interface.ts | 16 +++++ frontend/pages/info.vue | 28 +++++++- gateway/Cargo.lock | 1 + gateway/Cargo.toml | 1 + gateway/Dockerfile | 11 +++ gateway/src/steamcmd.rs | 88 ++++++++++++++++++++---- 6 files changed, 132 insertions(+), 13 deletions(-) diff --git a/frontend/interfaces/gateway.interface.ts b/frontend/interfaces/gateway.interface.ts index 5f5af64..5f9d44f 100644 --- a/frontend/interfaces/gateway.interface.ts +++ b/frontend/interfaces/gateway.interface.ts @@ -3,3 +3,19 @@ type Player = { playeruid: string; steamid: string; // this should be considered unique }; + +type UpdateSteamMessage = { + type: "steam_self_update"; + status: string; +} | { + type: "update_state"; + state_id: number; + state_name: string; + progress: string; + current: number; + total: number; +} | { + type: "success" +} | { + type: "error"; reason: string +}; diff --git a/frontend/pages/info.vue b/frontend/pages/info.vue index ed9647f..feb63ca 100644 --- a/frontend/pages/info.vue +++ b/frontend/pages/info.vue @@ -37,6 +37,7 @@ const updateDropdownItems = [ } }] ] +const updateLastMessage = ref() const update_steam = async (query: { game: false } | { game: true, validate: boolean }) => { logs.value = "" updateModal.value = true @@ -54,6 +55,20 @@ const update_steam = async (query: { game: false } | { game: true, validate: boo if (data instanceof Blob) { const text = await data.text(); logs.value += text; + } else if (typeof data === "string") { + const msg: UpdateSteamMessage = JSON.parse(data); + if (msg.type === "steam_self_update") { + console.log(`Steam self update: ${msg.status}`); + } else if (msg.type === "update_state") { + console.log(`Update state: ${msg.state_name} (${msg.progress}%)`); + } else if (msg.type === "success") { + console.log("Update success"); + } else if (msg.type === "error") { + console.log("Update error"); + } else { + console.log("Received unknown message:", msg); + } + updateLastMessage.value = msg } else { // Handle other data types console.log("Received non blob data:", data); @@ -113,10 +128,21 @@ const shutdownModal = ref(false)
+