From f264004c303d8a997ac99637b94f46cec468439c Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Sat, 5 Mar 2022 07:44:27 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8E=20Added=20a=20searchIssue=20endpoi?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/comic.model.ts | 1 - models/comicvine.metadata.model.ts | 78 ++++++++++++++++++++++++++++++ services/library.service.ts | 56 ++++++++++++--------- services/libraryqueue.service.ts | 17 +++---- services/search.service.ts | 39 ++++++++++----- 5 files changed, 144 insertions(+), 47 deletions(-) create mode 100644 models/comicvine.metadata.model.ts diff --git a/models/comic.model.ts b/models/comic.model.ts index d25ab16..3a05cfd 100644 --- a/models/comic.model.ts +++ b/models/comic.model.ts @@ -1,7 +1,6 @@ const mongoose = require("mongoose"); var mexp = require("mongoose-elasticsearch-xp").v7; const paginate = require("mongoose-paginate-v2"); - const { Client } = require("@elastic/elasticsearch"); export const eSClient = new Client({ diff --git a/models/comicvine.metadata.model.ts b/models/comicvine.metadata.model.ts new file mode 100644 index 0000000..9973654 --- /dev/null +++ b/models/comicvine.metadata.model.ts @@ -0,0 +1,78 @@ +const mongoose = require("mongoose"); +const Things = mongoose.Schema({ + api_detail_url: String, + id: Number, + name: String, + site_detail_url: String, + count: String, +}); +const Issue = mongoose.Schema({ + api_detail_url: String, + id: Number, + name: String, + issue_number: String, +}); +const VolumeInformation = mongoose.Schema({ + aliases: Array, + api_detail_url: String, + characters: [Things], + concepts: [Things], + count_of_issues: String, + date_added: String, + date_last_updated: String, + deck: String, + description: String, + first_issue: Issue, + id: Number, + image: { + icon_url: String, + medium_url: String, + screen_url: String, + screen_large_url: String, + small_url: String, + super_url: String, + thumb_url: String, + tiny_url: String, + original_url: String, + image_tags: String, + }, + + issues: [ + { + api_detail_url: String, + id: Number, + name: String, + issue_number: String, + site_detail_url: String, + }, + ], + last_issue: Issue, + locations: [Things], + name: String, + objects: [Things], + people: [Things], + publisher: { + api_detail_url: String, + id: Number, + name: String, + }, + site_detail_url: String, + start_year: String, +}); + +const ComicVineMetadata = mongoose.Schema({ + aliases: [String], + api_detail_url: String, + cover_date: String, + date_added: String, + date_last_updated: String, + deck: String, + description: String, + has_staff_review: Boolean, + id: Number, + name: String, + resource_type: String, + volumeInformation: VolumeInformation, +}); + +export default ComicVineMetadata; diff --git a/services/library.service.ts b/services/library.service.ts index 3312587..f1e1ca3 100644 --- a/services/library.service.ts +++ b/services/library.service.ts @@ -142,7 +142,7 @@ export default class ImportService extends Service { } }) .on("end", () => { - console.log("Import process complete."); + console.log("All files traversed."); }); }, }, @@ -164,6 +164,9 @@ export default class ImportService extends Service { rawFileDetails: { name: string; }; + acquisition: { + wanted: boolean; + }; }> ) { let volumeDetails; @@ -305,11 +308,16 @@ export default class ImportService extends Service { getComicBooks: { rest: "POST /getComicBooks", params: {}, - async handler(ctx: Context<{ paginationOptions: object }>) { - return await Comic.paginate( - {}, - ctx.params.paginationOptions - ); + async handler( + ctx: Context<{ + paginationOptions: object; + predicate: object; + }> + ) { + return await Comic.paginate(ctx.params.predicate, { + ...ctx.params.paginationOptions, + allowDiskUse: true, + }); }, }, getComicBookById: { @@ -338,26 +346,30 @@ export default class ImportService extends Service { rest: "GET /getComicBookGroups", params: {}, async handler(ctx: Context<{}>) { - let volumesMetadata = []; // 1. get volumes with issues mapped where issue count > 2 const volumes = await Comic.aggregate([ + { + $project: { + volumeInfo: + "$sourcedMetadata.comicvine.volumeInformation", + }, + }, + { + $unwind: "$volumeInfo", + }, { $group: { - _id: "$sourcedMetadata.comicvine.volume", - comicBookObjectId: { - $last: "$_id", - }, - count: { $sum: 1 }, - data: { - $push: "$$ROOT.sourcedMetadata.comicvine.volumeInformation", + _id: "$_id", + + volumes: { + $addToSet: "$volumeInfo", }, }, }, { - $match: { - count: { $gte: 1 }, - }, + $unwind: "$volumes", }, + { $sort: { updatedAt: -1 } }, { $skip: 0 }, { $limit: 5 }, @@ -496,12 +508,12 @@ export default class ImportService extends Service { issuesWithComicInfoXML: [ { $match: { - "sourcedMetadata.comicInfo" : { + "sourcedMetadata.comicInfo": { $exists: true, - $gt: {$size: 0} - } - } - } + $gt: { $size: 0 }, + }, + }, + }, ], publisherWithMostComicsInLibrary: [ { diff --git a/services/libraryqueue.service.ts b/services/libraryqueue.service.ts index efde5f4..cc33a30 100644 --- a/services/libraryqueue.service.ts +++ b/services/libraryqueue.service.ts @@ -72,16 +72,6 @@ export default class QueueService extends Service { const result = await extractCoverFromFile2( job.data.fileObject ); - const { filePath } = job.data.fileObject; - // get the file constituents and check for comicinfo.xml - // If present, convert the xml into json - // Import it into mongo - const { - extension, - fileNameWithoutExtension, - } = getFileConstituents(filePath); - const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`; - const info = await extractComicInfoXMLFromArchive(filePath, targetDirectory, extension); // infer any issue-related metadata from the filename const { inferredIssueDetails } = refineQuery(result.name); @@ -104,9 +94,14 @@ export default class QueueService extends Service { issue: inferredIssueDetails, }, sourcedMetadata: { - comicInfo: info, + comicInfo: {}, comicvine: {}, }, + // since we already have at least 1 copy + // mark it as not wanted by default + acquisition: { + wanted: false, + } }, {} ); diff --git a/services/search.service.ts b/services/search.service.ts index 761989a..d3c2616 100644 --- a/services/search.service.ts +++ b/services/search.service.ts @@ -9,7 +9,7 @@ import { import { DbMixin } from "../mixins/db.mixin"; import Comic from "../models/comic.model"; -import { flatten } from "lodash"; +import { flatten, isEmpty, isUndefined } from "lodash"; import { eSClient } from "../models/comic.model"; const s = eSClient.helpers.msearch(); @@ -64,25 +64,38 @@ export default class SettingsService extends Service { params: {}, handler: async ( ctx: Context<{ - queryObject: { + query: { volumeName: string; issueNumber: string; }; }> ) => { - console.log(ctx.params); - const result = await eSClient.search({ - index: "comics", - body: { - query: { - match: { - "rawFileDetails.name": - ctx.params.queryObject - .volumeName, - }, + console.log(ctx.params.query); + let eSQuery = {}; + if (isEmpty(ctx.params.query)) { + Object.assign(eSQuery, { + match_all: {}, + }); + } else { + Object.assign(eSQuery, { + match: { + "rawFileDetails.name": + ctx.params.query.volumeName, }, + }); + } + console.log("eSQuery", eSQuery); + const result = await eSClient.search( + { + index: "comics", + body: { + query: eSQuery, + }, + size: 50, }, - }); + { hydrate: true } + ); + console.log(result.body) const { hits } = result.body; return hits; },