From 278ab9407d2c2736e60ec94cebdbb4f347ad8b76 Mon Sep 17 00:00:00 2001 From: iAmir Date: Mon, 15 Jan 2024 23:57:52 +0330 Subject: [PATCH] fix query result usage --- src/api/rpc.ts | 3 ++- src/containers/LoadingScreen/index.tsx | 8 +++++--- src/utils/query.ts | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/api/rpc.ts b/src/api/rpc.ts index ca382756..90158662 100644 --- a/src/api/rpc.ts +++ b/src/api/rpc.ts @@ -18,5 +18,6 @@ export const invoke_rpc = async (method: string, params: object) => { Log.debug(`RPC request failed with status ${response.status}`); } - return response.json(); + const text = await response.text(); + return text; }; diff --git a/src/containers/LoadingScreen/index.tsx b/src/containers/LoadingScreen/index.tsx index 186c8fa5..11b20e28 100644 --- a/src/containers/LoadingScreen/index.tsx +++ b/src/containers/LoadingScreen/index.tsx @@ -118,9 +118,11 @@ const LoadingScreen = (props: { onEnd: () => void }) => { const list: any[] = []; files.forEach((file: any) => collectFiles(file, list)); - const checksums = (await invoke_rpc("get_checksum_of_files", { - list: list, - })) as string[]; + const checksums: string[] = JSON.parse( + await invoke_rpc("get_checksum_of_files", { + list: list, + }) + ); const results = await validateFileChecksums(checksums); if (results.includes(false)) { diff --git a/src/utils/query.ts b/src/utils/query.ts index f6c76743..bb9ee132 100644 --- a/src/utils/query.ts +++ b/src/utils/query.ts @@ -38,7 +38,7 @@ export const queryServer = ( const getServerInfo = async (ip: string, port: number, listType: ListType) => { try { - const serverInfo: string = await invoke_rpc("request_server_info", { + const serverInfo: any = await invoke_rpc("request_server_info", { ip: ip, port: port, }); @@ -199,16 +199,18 @@ const getServerOmpExtraInfo = async ( const getServerPing = async (ip: string, port: number, listType: ListType) => { try { - const serverPing = await invoke_rpc("ping_server", { - ip: ip, - port: port, - }); + const serverPing = parseInt( + await invoke_rpc("ping_server", { + ip: ip, + port: port, + }) + ); let server = getServerFromList(ip, port, listType); if (server) { let ping = server.ping; - if (typeof serverPing === "number") { + if (!isNaN(serverPing)) { if (serverPing !== 9999) { ping = serverPing; } else {