From cf75e8f9ff0166888b5824839e6d4df19219c286 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 10 May 2022 14:57:27 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Added=20a=20download=20->=20libr?= =?UTF-8?q?ary=20import=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/library.service.ts | 27 +++++++++++++++++++++++---- services/socket.service.ts | 8 ++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/services/library.service.ts b/services/library.service.ts index 09f8e96..f36dcf5 100644 --- a/services/library.service.ts +++ b/services/library.service.ts @@ -47,7 +47,7 @@ import { walkFolder, getSizeOfDirectory, } from "../utils/file.utils"; -import { uncompressEntireArchive } from "../utils/uncompression.utils"; +import { extractFromArchive, uncompressEntireArchive } from "../utils/uncompression.utils"; import { convertXMLToJSON } from "../utils/xml.utils"; import { IExtractComicBookCoverErrorResponse, @@ -89,10 +89,10 @@ export default class ImportService extends Service { return convertXMLToJSON("lagos"); }, }, - uncompressFullArchive : { + uncompressFullArchive: { rest: "POST /uncompressFullArchive", params: {}, - handler: async (ctx: Context<{filePath: string}>) => { + handler: async (ctx: Context<{ filePath: string }>) => { return await uncompressEntireArchive(ctx.params.filePath); } }, @@ -109,7 +109,7 @@ export default class ImportService extends Service { klaw(path.resolve(COMICS_DIRECTORY)) // 1.1 Filter on .cb* extensions .pipe( - through2.obj(function(item, enc, next) { + through2.obj(function (item, enc, next) { let fileExtension = path.extname(item.path); if ( [".cbz", ".cbr", ".cb7"].includes( @@ -319,6 +319,25 @@ export default class ImportService extends Service { }); }, }, + importDownloadedFileToLibrary: { + rest: "POST /importDownloadedFileToLibrary", + params: {}, + handler: async (ctx: Context<{ comicObjectId: string; downloadStatus: { name: string; } }>) => { + console.log("miscommunicate"); + console.log( + JSON.stringify(ctx.params, null, 2) + ); + const result = await extractFromArchive( + `${COMICS_DIRECTORY}/${ctx.params.downloadStatus.name}` + ); + console.log(result); + await Comic.findOneAndUpdate({ _id: new ObjectId(ctx.params.comicObjectId) }, { + rawFileDetails: { + + } + }) + } + }, getComicBooks: { rest: "POST /getComicBooks", diff --git a/services/socket.service.ts b/services/socket.service.ts index 7000081..22efdec 100644 --- a/services/socket.service.ts +++ b/services/socket.service.ts @@ -28,9 +28,7 @@ export default class SocketService extends Service { }, action: async (data, ack) => { // write your handler function here. - console.log( - JSON.stringify(data, null, 2) - ); + switch (data.type) { case "LS_IMPORT": @@ -52,7 +50,9 @@ export default class SocketService extends Service { ); break; case "LS_SINGLE_IMPORT": - console.log(data.data); + console.info("AirDC++ finished a download -> ") + + await this.broker.call("library.importDownloadedFileToLibrary", data.data, {}); break; } },