From 55e0ce6d36e6c0c13132659e843d50bca0c56227 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Fri, 18 Oct 2024 13:19:57 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=96=8C=EF=B8=8F=20Formatting=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/socket.service.ts | 115 ++++++++++++------------------------- 1 file changed, 36 insertions(+), 79 deletions(-) diff --git a/services/socket.service.ts b/services/socket.service.ts index 0610db5..df8e384 100644 --- a/services/socket.service.ts +++ b/services/socket.service.ts @@ -62,12 +62,8 @@ export default class SocketService extends Service { if (active > 0 || paused > 0 || waiting > 0) { // 3. Get job counts - const completedJobCount = await pubClient.get( - "completedJobCount" - ); - const failedJobCount = await pubClient.get( - "failedJobCount" - ); + const completedJobCount = await pubClient.get("completedJobCount"); + const failedJobCount = await pubClient.get("failedJobCount"); // 4. Send the counts to the active socket.io session await this.broker.call("socket.broadcast", { @@ -84,14 +80,9 @@ export default class SocketService extends Service { } } } catch (err) { - throw new MoleculerError( - err, - 500, - "SESSION_ID_NOT_FOUND", - { - data: sessionId, - } - ); + throw new MoleculerError(err, 500, "SESSION_ID_NOT_FOUND", { + data: sessionId, + }); } }, @@ -102,11 +93,7 @@ export default class SocketService extends Service { }> ) => { const { queueAction } = ctx.params; - await this.broker.call( - "jobqueue.toggle", - { action: queueAction }, - {} - ); + await this.broker.call("jobqueue.toggle", { action: queueAction }, {}); }, importSingleIssue: async (ctx: Context<{}>) => { console.info("AirDC++ finished a download -> "); @@ -119,9 +106,14 @@ export default class SocketService extends Service { }, // AirDCPP Socket actions getBundles: { - async handler(ctx) { - // get bundles bitch - } + async handler( + ctx: Context<{ + comicObjectId: string; + }> + ) { + // get bundles bitch + // 1. Get the comic object Id + }, }, search: { params: { @@ -134,10 +126,7 @@ export default class SocketService extends Service { const ADCPPSocket = new AirDCPPSocket(config); try { await ADCPPSocket.connect(); - const instance = await ADCPPSocket.post( - "search", - query - ); + const instance = await ADCPPSocket.post("search", query); // Send the instance to the client await namespacedInstance.emit("searchInitiated", { @@ -150,10 +139,7 @@ export default class SocketService extends Service { `search_result_added`, (groupedResult) => { console.log(JSON.stringify(groupedResult, null, 4)); - namespacedInstance.emit( - "searchResultAdded", - groupedResult - ); + namespacedInstance.emit("searchResultAdded", groupedResult); }, instance.id ); @@ -162,10 +148,7 @@ export default class SocketService extends Service { `search`, `search_result_updated`, (updatedResult) => { - namespacedInstance.emit( - "searchResultUpdated", - updatedResult - ); + namespacedInstance.emit("searchResultUpdated", updatedResult); }, instance.id ); @@ -175,47 +158,30 @@ export default class SocketService extends Service { `search_hub_searches_sent`, async (searchInfo) => { await this.sleep(5000); - const currentInstance = - await ADCPPSocket.get( - `search/${instance.id}` - ); - // Send the instance to the client - await namespacedInstance.emit( - "searchesSent", - { - searchInfo, - } + const currentInstance = await ADCPPSocket.get( + `search/${instance.id}` ); + // Send the instance to the client + await namespacedInstance.emit("searchesSent", { + searchInfo, + }); if (currentInstance.result_count === 0) { console.log("No more search results."); - namespacedInstance.emit( - "searchComplete", - { - message: - "No more search results.", - } - ); + namespacedInstance.emit("searchComplete", { + message: "No more search results.", + }); } }, instance.id ); // Perform the actual search - await ADCPPSocket.post( - `search/${instance.id}/hub_search`, - query - ); + await ADCPPSocket.post(`search/${instance.id}/hub_search`, query); } catch (error) { - await namespacedInstance.emit( - "searchError", - error.message - ); - throw new MoleculerError( - "Search failed", - 500, - "SEARCH_FAILED", - { error } - ); + await namespacedInstance.emit("searchError", error.message); + throw new MoleculerError("Search failed", 500, "SEARCH_FAILED", { + error, + }); } finally { // await ADCPPSocket.disconnect(); } @@ -266,10 +232,7 @@ export default class SocketService extends Service { "Download and metadata update successful", bundleDBImportResult ); - this.broker.emit( - "downloadCompleted", - bundleDBImportResult - ); + this.broker.emit("downloadCompleted", bundleDBImportResult); return bundleDBImportResult; } else { throw new Error( @@ -278,12 +241,9 @@ export default class SocketService extends Service { } } catch (error) { this.broker.emit("downloadError", error.message); - throw new MoleculerError( - "Download failed", - 500, - "DOWNLOAD_FAILED", - { error } - ); + throw new MoleculerError("Download failed", 500, "DOWNLOAD_FAILED", { + error, + }); } finally { // await ADCPPSocket.disconnect(); } @@ -303,10 +263,7 @@ export default class SocketService extends Service { "queue", "queue_bundle_tick", (tickData) => { - console.log( - "Received tick data: ", - tickData - ); + console.log("Received tick data: ", tickData); this.io.emit("bundleTickUpdate", tickData); }, null