BUGFIX: fix double stringify on server array (#1100)

The server array that the RFA currently sends is stringified twice. I fixed that and also added a proper ResultType for the new data
This commit is contained in:
Shy 2024-02-16 01:27:03 +01:00 committed by GitHub
parent ddb10f833c
commit c894aba8f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

@ -1,3 +1,5 @@
import type { BaseServer } from "src/Server/BaseServer";
export class RFAMessage {
jsonrpc = "2.0"; // Transmits version of JSON-RPC. Compliance maybe allows some funky interaction with external tools?
public method?: string; // Is defined when it's a request/notification, otherwise undefined
@ -15,7 +17,7 @@ export class RFAMessage {
}
}
type ResultType = string | number | string[] | FileContent[];
type ResultType = string | number | string[] | FileContent[] | RFAServerData[];
type FileMetadata = FileData | FileContent | FileLocation | FileServer;
export interface FileData {
@ -38,6 +40,8 @@ export interface FileServer {
server: string;
}
export type RFAServerData = Pick<BaseServer, "hostname" | "hasAdminRights">;
export function isFileData(p: unknown): p is FileData {
const pf = p as FileData;
return typeof pf.server === "string" && typeof pf.filename === "string" && typeof pf.content === "string";

@ -113,11 +113,11 @@ export const RFARequestHandler: Record<string, (message: RFAMessage) => void | R
},
getAllServers: function (msg: RFAMessage): RFAMessage {
const servers = GetAllServers().map((server) => ({
hostname: server.hostname,
hasAdminRights: server.hasAdminRights,
const servers = GetAllServers().map(({ hostname, hasAdminRights }) => ({
hostname,
hasAdminRights,
}));
return new RFAMessage({ result: JSON.stringify(servers), id: msg.id });
return new RFAMessage({ result: servers, id: msg.id });
},
};