🤼‍♀️ Support for CV match

This commit is contained in:
2021-08-06 13:44:00 -07:00
parent cf65b36157
commit 9a311d707f
4 changed files with 39 additions and 26 deletions

View File

@@ -12,23 +12,23 @@ const ComicSchema = mongoose.Schema({
userAddedMetadata: { userAddedMetadata: {
tags: [], tags: [],
}, },
comicInfo: {
blackAndWhite: String,
characters: [String],
count: String,
genre: String,
manga: String,
month: String,
number: String,
pageCount: String,
pages: [],
publisher: String,
summary: String,
title: String,
writer: String,
year: String,
},
sourcedMetadata: { sourcedMetadata: {
comicInfo: {
blackAndWhite: String,
characters: [String],
count: String,
genre: String,
manga: String,
month: String,
number: String,
pageCount: String,
pages: [],
publisher: String,
summary: String,
title: String,
writer: String,
year: String,
},
comicvine: {}, comicvine: {},
shortboxed: {}, shortboxed: {},
gcd: {}, gcd: {},

View File

@@ -14,7 +14,6 @@ export default class ApiService extends Service {
// More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html // More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
settings: { settings: {
port: process.env.PORT || 3000, port: process.env.PORT || 3000,
routes: [ routes: [
{ {
path: "/api", path: "/api",
@@ -39,7 +38,6 @@ export default class ApiService extends Service {
use: [], use: [],
mergeParams: true, mergeParams: true,
autoAliases: true, autoAliases: true,
aliases: {}, aliases: {},
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options // Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
@@ -55,11 +53,7 @@ export default class ApiService extends Service {
limit: "1MB", limit: "1MB",
}, },
}, },
// Mapping policy setting. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Mapping-policy
mappingPolicy: "all", // Available values: "all", "restrict" mappingPolicy: "all", // Available values: "all", "restrict"
// Enable/disable logging
logging: true, logging: true,
}, },
{ {
@@ -71,15 +65,11 @@ export default class ApiService extends Service {
use: [ApiGateway.serveStatic("comics")], use: [ApiGateway.serveStatic("comics")],
}, },
], ],
// Do not log client side errors (does not log an error response when the error.code is 400<=X<500)
log4XXResponses: false, log4XXResponses: false,
// Logging the request parameters. Set to any log level to enable it. E.g. "info"
logRequestParams: null, logRequestParams: null,
// Logging the response data. Set to any log level to enable it. E.g. "info"
logResponseData: null, logResponseData: null,
assets: { assets: {
folder: "public", folder: "public",
// Options to `server-static` module
options: {}, options: {},
}, },
}, },

View File

@@ -10,6 +10,7 @@ import { DbMixin } from "../mixins/db.mixin";
import Comic from "../models/comic.model"; import Comic from "../models/comic.model";
import { walkFolder } from "../utils/file.utils"; import { walkFolder } from "../utils/file.utils";
import { convertXMLToJSON } from "../utils/xml.utils"; import { convertXMLToJSON } from "../utils/xml.utils";
const ObjectId = require("mongoose").Types.ObjectId;
export default class ProductsService extends Service { export default class ProductsService extends Service {
public constructor( public constructor(
@@ -74,6 +75,26 @@ export default class ProductsService extends Service {
}); });
}, },
}, },
applyComicVineMetadata: {
rest: "POST /applyComicVineMetadata",
params: {},
async handler(ctx: Context<{ match: object, comicObjectId: string }>) {
// 1. find mongo object by id
// 2. import payload into sourcedMetadata.comicvine
const comicObjectId = new ObjectId(ctx.params.comicObjectId);
return new Promise((resolve, reject) => {
Comic.findByIdAndUpdate(comicObjectId, { sourcedMetadata: { comicvine: ctx.params.match } }, { new: true}, (err, result) => {
if (err) {
console.log(err);
reject(err);
} else {
console.log("RES", result);
resolve(result);
}
})
});
}
},
getComicBooks: { getComicBooks: {
rest: "POST /getComicBooks", rest: "POST /getComicBooks",
params: {}, params: {},

View File

@@ -85,6 +85,7 @@ export const extractCoverFromFile = async (
} catch (error) { } catch (error) {
logger.error(`${error}: Couldn't create directory.`); logger.error(`${error}: Couldn't create directory.`);
} }
// extract the cover
let result: string; let result: string;
const targetCoverImageFilePath = path.resolve(constructedPaths.targetPath + "/" + walkedFolder.name + "_cover.jpg") const targetCoverImageFilePath = path.resolve(constructedPaths.targetPath + "/" + walkedFolder.name + "_cover.jpg")
result = await calibre.run( result = await calibre.run(
@@ -203,6 +204,7 @@ export const unrar = async (
mode: 0o2775, mode: 0o2775,
}; };
try { try {
// read the file into a buffer
const fileBuffer = await readFile( const fileBuffer = await readFile(
paths.inputFilePath paths.inputFilePath
).catch((err) => console.error("Failed to read file", err)); ).catch((err) => console.error("Failed to read file", err));