From 3f37c435845bae9ea9bbca9ca470da323dfa90e0 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Sun, 24 Jul 2022 22:20:03 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8E=20Support=20for=20downloads=20endp?= =?UTF-8?q?oint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jshintrc | 3 +++ models/comic.model.ts | 29 +++++++++++++++++++++++-- models/comicvine.metadata.model.ts | 4 ++-- services/importqueue.service.ts | 3 +++ services/library.service.ts | 7 ++++-- services/search.service.ts | 34 ++++++------------------------ tsconfig.json | 4 ++-- 7 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..816db2b --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esversion": 10 +} \ No newline at end of file diff --git a/models/comic.model.ts b/models/comic.model.ts index 860980b..c34a932 100644 --- a/models/comic.model.ts +++ b/models/comic.model.ts @@ -47,6 +47,12 @@ const LOCGSchema = mongoose.Schema({ pulls: Number, potw: Number, }); +const DirectConnectBundleSchema = mongoose.Schema({ + resultId: String, + bundleId: Number, + directoryIds: [String], + searchInstanceId: Number, +}); const ComicSchema = mongoose.Schema( { @@ -58,7 +64,7 @@ const ComicSchema = mongoose.Schema( }, }, userAddedMetadata: { - tags: [], + tags: [String], }, sourcedMetadata: { comicInfo: { type: mongoose.Schema.Types.Mixed, default: {} }, @@ -99,7 +105,13 @@ const ComicSchema = mongoose.Schema( name: String, }, release: {}, - directconnect: Array, + directconnect: { + downloads: { + type: [DirectConnectBundleSchema], + es_indexed: true, + default: [], + }, + }, torrent: { sourceApplication: String, magnet: String, @@ -120,6 +132,19 @@ ComicSchema.plugin(mongoosastic, { ComicSchema.plugin(paginate); const Comic = mongoose.model("Comic", ComicSchema); +// Comic.createMapping({ +// analysis: { +// analyzer: { +// content: { +// type: "custom", +// tokenizer: "whitespace", +// }, +// }, +// }, +// }).then((data) => { +// console.log("Mapping the index...") +// console.log(data) +// }) // const stream = Comic.synchronize(); // let count = 0; diff --git a/models/comicvine.metadata.model.ts b/models/comicvine.metadata.model.ts index 2133f5b..042a6a6 100644 --- a/models/comicvine.metadata.model.ts +++ b/models/comicvine.metadata.model.ts @@ -16,7 +16,7 @@ const Issue = mongoose.Schema({ }); const VolumeInformation = mongoose.Schema({ _id: false, - aliases: [], + aliases: [String], api_detail_url: String, characters: [Things], concepts: [Things], @@ -68,7 +68,7 @@ const ComicVineMetadataSchema = mongoose.Schema({ api_detail_url: String, has_staff_review: { type: mongoose.Schema.Types.Mixed }, - cover_date: String, + cover_date: Date, date_added: String, date_last_updated: String, deck: String, diff --git a/services/importqueue.service.ts b/services/importqueue.service.ts index ff99dca..0709811 100644 --- a/services/importqueue.service.ts +++ b/services/importqueue.service.ts @@ -124,6 +124,9 @@ export default class QueueService extends Service { source: { wanted: false, }, + directconnect: { + downloads: [], + } }, }); return { diff --git a/services/library.service.ts b/services/library.service.ts index f4ec3e7..1d74b07 100644 --- a/services/library.service.ts +++ b/services/library.service.ts @@ -186,6 +186,9 @@ export default class ImportService extends Service { wanted: boolean; name?: string; }; + directconnect: { + downloads: []; + }; }; }> ) { @@ -313,7 +316,7 @@ export default class ImportService extends Service { comicObjectId, { $push: { - "acquisition.directconnect": { + "acquisition.directconnect.downloads": { resultId: ctx.params.resultId, bundleId: ctx.params.bundleId, directoryIds: @@ -513,7 +516,7 @@ export default class ImportService extends Service { }); }, }, - + libraryStatistics: { rest: "GET /libraryStatistics", params: {}, diff --git a/services/search.service.ts b/services/search.service.ts index 2d137a2..54a69c2 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, isEmpty, isNil, isUndefined, map } from "lodash"; +import { flatten, isEmpty, isNil, isUndefined, map, result } from "lodash"; import { eSClient } from "../models/comic.model"; const s = eSClient.helpers.msearch(); @@ -154,35 +154,15 @@ export default class SettingsService extends Service { ) => { // params: array of bundle IDs // construct the elasticsearch msearch query - let elasticsearchQuery = {}; if (!isNil(ctx.params.bundleIds)) { - ctx.params.bundleIds.map(async (id) => { - let foo = await eSClient.search({ - index: "comics", - body: { - query: { - nested: { - path: "acquisition", - query: { - bool: { - must: [ - { - match: { - "acquisition.directconnect": - id, - }, - }, - ], - }, - }, - inner_hits: {}, - // ignore_unmapped: true, - }, + return await Comic.find({ + "acquisition.directconnect.downloads": { + $elemMatch: { + bundleId: { + $in: ctx.params.bundleIds, }, }, - }); - console.log(foo.body); - return foo.body; + }, }); } }, diff --git a/tsconfig.json b/tsconfig.json index 3324ae6..a87bc5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,13 @@ { "compilerOptions": { - "module": "commonjs", + "module": "CommonJS", "esModuleInterop": true, "noImplicitAny": false, "removeComments": true, "preserveConstEnums": true, "sourceMap": true, "pretty": true, - "target": "es6", + "target": "ES2022", "outDir": "dist", "skipLibCheck": true, "lib": ["es5", "es6", "dom", "dom.iterable"],