📑 Added duplicate detection logic
This commit is contained in:
@@ -3,6 +3,12 @@ import ApiGateway from "moleculer-web";
|
||||
import { extractCoverFromFile } from "../utils/uncompression.utils";
|
||||
import { map } from "lodash";
|
||||
const IO = require("socket.io")();
|
||||
import Comic from "../models/comic.model";
|
||||
import {
|
||||
IExtractComicBookCoverErrorResponse,
|
||||
IExtractedComicBookCoverFile,
|
||||
} from "threetwo-ui-typings";
|
||||
import { logger } from "../utils/logger.utils";
|
||||
|
||||
export default class ApiService extends Service {
|
||||
public constructor(broker: ServiceBroker) {
|
||||
@@ -18,9 +24,7 @@ export default class ApiService extends Service {
|
||||
routes: [
|
||||
{
|
||||
path: "/api",
|
||||
whitelist: [
|
||||
"**",
|
||||
],
|
||||
whitelist: ["**"],
|
||||
cors: {
|
||||
origin: "*",
|
||||
methods: [
|
||||
@@ -106,33 +110,50 @@ export default class ApiService extends Service {
|
||||
|
||||
const { extractionOptions, walkedFolders } = params;
|
||||
map(walkedFolders, async (folder, idx) => {
|
||||
let comicBookCoverMetadata =
|
||||
await extractCoverFromFile(
|
||||
let comicExists = await Comic.exists({
|
||||
"rawFileDetails.name": `${folder.name}`,
|
||||
});
|
||||
if (!comicExists) {
|
||||
let comicBookCoverMetadata:
|
||||
| IExtractedComicBookCoverFile
|
||||
| IExtractComicBookCoverErrorResponse
|
||||
| IExtractedComicBookCoverFile[] = await extractCoverFromFile(
|
||||
extractionOptions,
|
||||
folder
|
||||
);
|
||||
const dbImportResult = await this.broker.call(
|
||||
"import.rawImportToDB",
|
||||
{
|
||||
importStatus: {
|
||||
isImported: true,
|
||||
tagged: false,
|
||||
matchedResult: {
|
||||
score: "0",
|
||||
},
|
||||
},
|
||||
rawFileDetails: comicBookCoverMetadata,
|
||||
sourcedMetadata: {
|
||||
comicvine: {},
|
||||
},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
client.emit("comicBookCoverMetadata", {
|
||||
comicBookCoverMetadata,
|
||||
dbImportResult,
|
||||
});
|
||||
const dbImportResult =
|
||||
await this.broker.call(
|
||||
"import.rawImportToDB",
|
||||
{
|
||||
importStatus: {
|
||||
isImported: true,
|
||||
tagged: false,
|
||||
matchedResult: {
|
||||
score: "0",
|
||||
},
|
||||
},
|
||||
rawFileDetails:
|
||||
comicBookCoverMetadata,
|
||||
sourcedMetadata: {
|
||||
comicvine: {},
|
||||
},
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
client.emit("comicBookCoverMetadata", {
|
||||
comicBookCoverMetadata,
|
||||
dbImportResult,
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
`Comic: \"${folder.name}\" already exists in the database`
|
||||
);
|
||||
client.emit("comicBookExists", {
|
||||
name: folder.name,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -68,6 +68,9 @@ export default class ImportService extends Service {
|
||||
volumeInformation: {};
|
||||
};
|
||||
};
|
||||
rawFileDetails: {
|
||||
name: string;
|
||||
};
|
||||
}>
|
||||
) {
|
||||
let volumeDetails;
|
||||
@@ -87,7 +90,7 @@ export default class ImportService extends Service {
|
||||
comicMetadata.sourcedMetadata.comicvine.volumeInformation =
|
||||
volumeDetails;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
Comic.create(ctx.params, (error, data) => {
|
||||
if (data) {
|
||||
resolve(data);
|
||||
@@ -115,8 +118,8 @@ export default class ImportService extends Service {
|
||||
comicObjectId: string;
|
||||
}>
|
||||
) {
|
||||
// 1. find mongo object by id
|
||||
// 2. import payload into sourcedMetadata.comicvine
|
||||
// 1. Find mongo object by id
|
||||
// 2. Import payload into sourcedMetadata.comicvine
|
||||
const comicObjectId = new ObjectId(
|
||||
ctx.params.comicObjectId
|
||||
);
|
||||
@@ -177,8 +180,10 @@ export default class ImportService extends Service {
|
||||
"acquisition.directconnect": {
|
||||
resultId:
|
||||
ctx.params.resultId,
|
||||
bundleId: ctx.params.bundleId,
|
||||
directoryIds: ctx.params.directoryIds,
|
||||
bundleId:
|
||||
ctx.params.bundleId,
|
||||
directoryIds:
|
||||
ctx.params.directoryIds,
|
||||
searchInstanceId:
|
||||
ctx.params
|
||||
.searchInstanceId,
|
||||
@@ -219,12 +224,14 @@ export default class ImportService extends Service {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getComicVineVolumeMetadata: apiDetailURL => new Promise((resolve, reject) => https
|
||||
getComicVineVolumeMetadata: (apiDetailURL) =>
|
||||
new Promise((resolve, reject) =>
|
||||
https
|
||||
.get(
|
||||
`${apiDetailURL}?api_key=a5fa0663683df8145a85d694b5da4b87e1c92c69&format=json&limit=1&offset=0&field_list=id,name,description,image,first_issue,last_issue,publisher,count_of_issues,character_credits,person_credits,aliases`,
|
||||
resp => {
|
||||
(resp) => {
|
||||
let data = "";
|
||||
resp.on("data", chunk => {
|
||||
resp.on("data", (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
@@ -237,10 +244,11 @@ export default class ImportService extends Service {
|
||||
});
|
||||
}
|
||||
)
|
||||
.on("error", err => {
|
||||
.on("error", (err) => {
|
||||
console.log("Error: " + err.message);
|
||||
reject(err);
|
||||
})),
|
||||
})
|
||||
),
|
||||
},
|
||||
},
|
||||
schema
|
||||
|
||||
Reference in New Issue
Block a user