From 7dff9a1ab4da35c7070f5d230a271c739e4cf16b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 4 Dec 2022 01:28:05 -0500 Subject: [PATCH] *Only try to stringify the data if it is not already a string --- src/modules/rpc/cache.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/modules/rpc/cache.ts b/src/modules/rpc/cache.ts index 3984c49..7ebfcef 100644 --- a/src/modules/rpc/cache.ts +++ b/src/modules/rpc/cache.ts @@ -1,13 +1,6 @@ import EventEmitter from "events"; import DHTCache from "@lumeweb/dht-cache"; -import { - RPCCacheData, - RPCCacheItem, - RPCRequest, - RPCResponse, -} from "@lumeweb/relay-types"; -import { getRpcByPeer } from "../rpc"; -import b4a from "b4a"; +import { RPCCacheItem, RPCRequest, RPCResponse } from "@lumeweb/relay-types"; import { get as getSwarm } from "../swarm"; import { RPCServer } from "./server"; // @ts-ignore @@ -50,8 +43,11 @@ export class RPCCache extends EventEmitter { const field = item.value.signedField || "data"; const updated = item.value.updated; // @ts-ignore - const data = item.value[field]; - const json = jsonStringify(data); + let json = item.value[field]; + + if (typeof json !== "string") { + json = jsonStringify(json); + } return this.server.signData(`${updated}${json}`); } @@ -60,8 +56,11 @@ export class RPCCache extends EventEmitter { const field = item.value.signedField || "data"; const updated = item.value.updated; // @ts-ignore - const data = item.value[field]; - const json = jsonStringify(data); + let json = item.value[field]; + + if (typeof json !== "string") { + json = jsonStringify(json); + } try { if (