From 7d7b76770ed59bd6adc53509d60985fa6ad46276 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 10 Oct 2024 11:06:24 +0200 Subject: [PATCH] refactor: added debug logs to the gftp storage provider --- src/shared/storage/ws.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shared/storage/ws.ts b/src/shared/storage/ws.ts index 065839db8..2988771b6 100644 --- a/src/shared/storage/ws.ts +++ b/src/shared/storage/ws.ts @@ -69,9 +69,9 @@ export class WebSocketStorageProvider implements StorageProvider { constructor( private readonly yagnaApi: YagnaApi, - private readonly options?: WebSocketStorageProviderOptions, + options?: WebSocketStorageProviderOptions, ) { - this.logger = options?.logger || defaultLogger("storage"); + this.logger = options?.logger?.child("storage") || defaultLogger("storage"); } async close(): Promise { @@ -95,6 +95,9 @@ export class WebSocketStorageProvider implements StorageProvider { return; } const req = toObject(event.data) as GsbRequestPublishUnion; + + this.logger.debug("Received GFTP request for publishData", req); + if (req.component === "GetMetadata") { this.respond(ws, req.id, { fileSize: data.byteLength }); } else if (req.component === "GetChunk") { @@ -133,6 +136,8 @@ export class WebSocketStorageProvider implements StorageProvider { const req = toObject(event.data) as GsbRequestPublishUnion; + this.logger.debug("Received GFTP request for publishFile", req); + if (req.component === "GetMetadata") { this.respond(ws, req.id, { fileSize }); } else if (req.component === "GetChunk") { @@ -172,7 +177,11 @@ export class WebSocketStorageProvider implements StorageProvider { this.logger.error("Received non-ArrayBuffer data from the socket", { data: event.data }); return; } + const req = toObject(event.data) as GsbRequestReceiveUnion; + + this.logger.debug("Received GFTP request for receiveData", req); + if (req.component === "UploadChunk") { data.push(req.payload.chunk); this.respond(ws, req.id, null); @@ -206,6 +215,9 @@ export class WebSocketStorageProvider implements StorageProvider { return; } const req = toObject(event.data) as GsbRequestReceiveUnion; + + this.logger.debug("Received GFTP request for receiveFile", req); + if (req.component === "UploadChunk") { await fileHandle.write(req.payload.chunk.content); this.respond(ws, req.id, null);