diff --git a/package-lock.json b/package-lock.json index 3e783b1..fdf69d8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "node-unrar-js": "^1.0.2", "sharp": "^0.28.3", "socket.io": "^4.4.0", - "threetwo-ui-typings": "^1.0.11", + "threetwo-ui-typings": "^1.0.12", "through2": "^4.0.2", "unrar": "^0.2.0", "xml2js": "^0.4.23" @@ -11247,9 +11247,9 @@ "dev": true }, "node_modules/threetwo-ui-typings": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/threetwo-ui-typings/-/threetwo-ui-typings-1.0.11.tgz", - "integrity": "sha512-jRI1rUttoJDqsKFUPd4MM56NErftl2NSEo8MkeqllOtVf38Wy+wVvAT+OW6AoSguA5cLxSpOiA25c31FWjOvOw==", + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/threetwo-ui-typings/-/threetwo-ui-typings-1.0.12.tgz", + "integrity": "sha512-lKADNpD2Oa3Wmf6tdZhaPSNfIFa0KtstsZLE0yalTjqKmtQZM7Ct2OnlCkH7aonDuVn+jgcRMwkcP9krCqa2fw==", "dependencies": { "typescript": "^4.3.2" } @@ -20540,9 +20540,9 @@ "dev": true }, "threetwo-ui-typings": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/threetwo-ui-typings/-/threetwo-ui-typings-1.0.11.tgz", - "integrity": "sha512-jRI1rUttoJDqsKFUPd4MM56NErftl2NSEo8MkeqllOtVf38Wy+wVvAT+OW6AoSguA5cLxSpOiA25c31FWjOvOw==", + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/threetwo-ui-typings/-/threetwo-ui-typings-1.0.12.tgz", + "integrity": "sha512-lKADNpD2Oa3Wmf6tdZhaPSNfIFa0KtstsZLE0yalTjqKmtQZM7Ct2OnlCkH7aonDuVn+jgcRMwkcP9krCqa2fw==", "requires": { "typescript": "^4.3.2" }, diff --git a/services/api.service.ts b/services/api.service.ts index b8b10b6..4d3934b 100644 --- a/services/api.service.ts +++ b/services/api.service.ts @@ -95,10 +95,10 @@ export default class ApiService extends Service { console.log("Client connected via websocket!"); client.on("action", async (action) => { - console.log("ACCCCCTION", action); switch (action.type) { case "LS_IMPORT": // 1. Send task to queue + console.log(`Recieved ${action.type} event.`) await this.broker.call( "import.newImport", action.data, diff --git a/services/import.service.ts b/services/import.service.ts index 8b03914..12c1a88 100644 --- a/services/import.service.ts +++ b/services/import.service.ts @@ -31,8 +31,6 @@ SOFTWARE. * Initial: 2022/01/28 Rishi Ghan */ - - "use strict"; import { isNil, isUndefined, map } from "lodash"; import { @@ -395,7 +393,7 @@ export default class ImportService extends Service { { $group: { _id: "$sourcedMetadata.comicvine.volume.id", - comicObjectId : { $first: "$_id" }, + comicObjectId: { $first: "$_id" }, volumeURI: { $last: "$sourcedMetadata.comicvine.volume.api_detail_url", }, @@ -416,17 +414,21 @@ export default class ImportService extends Service { volumesMetadata = map(volumes, async (volume) => { console.log(volume); if (!isNil(volume.volumeURI)) { - const volumeMetadata = await ctx.call("comicvine.getVolumes", { - volumeURI: volume.volumeURI, - data: { - format: "json", - fieldList: - "id,name,deck,api_detail_url", - limit: "1", - offset: "0", - }, - }); - volumeMetadata["comicObjectId"] = volume.comicObjectId; + const volumeMetadata = await ctx.call( + "comicvine.getVolumes", + { + volumeURI: volume.volumeURI, + data: { + format: "json", + fieldList: + "id,name,deck,api_detail_url", + limit: "1", + offset: "0", + }, + } + ); + volumeMetadata["comicObjectId"] = + volume.comicObjectId; return volumeMetadata; } }); @@ -434,21 +436,23 @@ export default class ImportService extends Service { return Promise.all(volumesMetadata); }, }, - getIssuesForSeries: { - rest: "POST /getIssuesForSeries", + findIssuesForSeriesInLibrary: { + rest: "POST /findIssuesForSeriesInLibrary", params: {}, - handler: async (ctx:Context<{ comicObjectID: string }>) => { - // 1. Query mongo to get issues for a given volume + handler: async ( + ctx: Context<{ comicObjectID: string }> + ) => { + // 1. Query mongo to get the comic document by its _id const comicBookDetails: any = await this.broker.call( "import.getComicBookById", { id: ctx.params.comicObjectID } ); // 2. Query CV and get metadata for them - comicBookDetails.sourcedMetadata.comicvine.volumeInformation.issues.map( - async (issue: any, idx: any) => { - const issueMetadata: any = - await axios.request({ + const foo = + await comicBookDetails.sourcedMetadata.comicvine.volumeInformation.issues.map( + async (issue: any, idx: any) => { + const metadata: any = await axios.request({ url: `${issue.api_detail_url}?api_key=${process.env.COMICVINE_API_KEY}`, params: { resources: "issues", @@ -459,29 +463,34 @@ export default class ImportService extends Service { "User-Agent": "ThreeTwo", }, }); - const metadata = - issueMetadata.data.results; - - // 2a. Query Mongo with Elastic to see if a match exists for a given issue's name, and issue number - if ( - !isUndefined(metadata.volume.name) && - !isUndefined(metadata.issue_number) - ) { - console.log("asdasd", metadata.volume.name); - await ctx.broker.call("libraryqueue.issuesForSeries", { queryObject: { - issueName: - metadata.volume - .name, - issueNumber: - metadata.issue_number, - }}); - - } + const issueMetadata = metadata.data.results; - return issueMetadata.data.results; - } - ); - } + // 2a. Enqueue the Elasticsearch job + if ( + !isUndefined(issueMetadata.volume.name) && + !isUndefined(issueMetadata.issue_number) + ) { + await ctx.broker.call( + "libraryqueue.issuesForSeries", + { + queryObject: { + issueId: issue.id, + issueName: + issueMetadata.volume + .name, + issueNumber: + issueMetadata.issue_number, + issueMetadata, + }, + } + ); + } + // 3. Just return the issues + return issueMetadata; + } + ); + return Promise.all(foo); + }, }, flushDB: { rest: "POST /flushDB", diff --git a/services/libraryqueue.service.ts b/services/libraryqueue.service.ts index 62f6fd5..e4f4523 100644 --- a/services/libraryqueue.service.ts +++ b/services/libraryqueue.service.ts @@ -33,7 +33,7 @@ SOFTWARE. "use strict"; -import { isNil, isUndefined } from "lodash"; +import { extend, isNil, isUndefined } from "lodash"; import { Context, Service, @@ -101,20 +101,30 @@ export default class LibraryQueueService extends Service { async process(job: SandboxedJob) { try { console.log( - "reached the issuematchinlibrary queue" + "Job recieved to find issue matches in library." ); - console.log(job.data); const matchesInLibrary = await this.broker.call( "search.searchComic", { queryObject: job.data.queryObject, } ); - console.log( - `Matches in Library: ${matchesInLibrary}` - ); + if ( + !isNil(matchesInLibrary) && + !isUndefined(matchesInLibrary) + ) { + console.log("Matches found in library:"); - return Promise.all(matchesInLibrary); + const foo = extend( + { issue: job.data.queryObject.issueMetadata }, + { matches: matchesInLibrary } + ); + return foo; + } else { + console.log( + "No match was found for this issue in the library." + ); + } } catch (error) { throw error; } @@ -139,10 +149,14 @@ export default class LibraryQueueService extends Service { rest: "POST /findIssuesForSeries", params: {}, handler: async ( - ctx: Context<{ queryObject: { - issueName: string, - issueNumber: string, - } }> + ctx: Context<{ + queryObject: { + issueName: string; + issueNumber: string; + issueId: string; + issueMetadata: object; + }; + }> ) => { return await this.createJob( "issue.findMatchesInLibrary", @@ -197,7 +211,7 @@ export default class LibraryQueueService extends Service { "completed", async (job, res) => { client.emit("action", { - type: "LS_COVER_EXTRACTED", + type: "CV_ISSUES_FOR_VOLUME_IN_LIBRARY_SUCCESS", result: res, }); console.info(