🔎 Added a searchIssue endpoint

This commit is contained in:
2022-03-05 07:44:27 -08:00
parent 07e02cc90a
commit f264004c30
5 changed files with 144 additions and 47 deletions

View File

@@ -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({

View File

@@ -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;

View File

@@ -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: [
{

View File

@@ -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,
}
},
{}
);

View File

@@ -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;
},