Skip to content

Commit

Permalink
refactor: added debug logs to the gftp storage provider
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha87 committed Oct 10, 2024
1 parent 258a653 commit 7d7b767
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/shared/storage/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7d7b767

Please sign in to comment.