💽 mongo import endpoint
This commit is contained in:
@@ -2,10 +2,9 @@ const mongoose = require("mongoose");
|
|||||||
const paginate = require("mongoose-paginate");
|
const paginate = require("mongoose-paginate");
|
||||||
|
|
||||||
const ComicSchema = mongoose.Schema({
|
const ComicSchema = mongoose.Schema({
|
||||||
name: String,
|
importStatus: {
|
||||||
type: String,
|
|
||||||
import: {
|
|
||||||
isImported: Boolean,
|
isImported: Boolean,
|
||||||
|
tagged: Boolean,
|
||||||
matchedResult: {
|
matchedResult: {
|
||||||
score: String,
|
score: String,
|
||||||
},
|
},
|
||||||
@@ -14,28 +13,21 @@ const ComicSchema = mongoose.Schema({
|
|||||||
tags: [],
|
tags: [],
|
||||||
},
|
},
|
||||||
|
|
||||||
comicStructure: {
|
comicInfo: {
|
||||||
cover: {
|
blackAndWhite: String,
|
||||||
thumb: String,
|
characters: [String],
|
||||||
medium: String,
|
count: String,
|
||||||
large: String,
|
genre: String,
|
||||||
},
|
manga: String,
|
||||||
collection: {
|
month: String,
|
||||||
publishDate: String,
|
number: String,
|
||||||
type: String, // issue, series, trade paperback
|
pageCount: String,
|
||||||
metadata: {
|
pages: [],
|
||||||
publisher: String,
|
publisher: String,
|
||||||
issueNumber: String,
|
summary: String,
|
||||||
description: String,
|
title: String,
|
||||||
synopsis: String,
|
writer: String,
|
||||||
team: {
|
year: String,
|
||||||
writer: String,
|
|
||||||
inker: String,
|
|
||||||
penciler: String,
|
|
||||||
colorist: String,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
sourcedMetadata: {
|
sourcedMetadata: {
|
||||||
comicvine: {},
|
comicvine: {},
|
||||||
@@ -43,13 +35,14 @@ const ComicSchema = mongoose.Schema({
|
|||||||
gcd: {},
|
gcd: {},
|
||||||
},
|
},
|
||||||
rawFileDetails: {
|
rawFileDetails: {
|
||||||
fileName: String,
|
name: String,
|
||||||
path: String,
|
path: String,
|
||||||
extension: String,
|
fileSize: Number,
|
||||||
},
|
},
|
||||||
acquisition: {
|
acquisition: {
|
||||||
wanted: Boolean,
|
wanted: Boolean,
|
||||||
release: {},
|
release: {},
|
||||||
|
directconnect: {},
|
||||||
torrent: {
|
torrent: {
|
||||||
sourceApplication: String,
|
sourceApplication: String,
|
||||||
magnet: String,
|
magnet: String,
|
||||||
|
|||||||
19
package-lock.json
generated
19
package-lock.json
generated
@@ -7778,6 +7778,11 @@
|
|||||||
"sparse-bitfield": "^3.0.3"
|
"sparse-bitfield": "^3.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"sax": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||||
|
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
|
||||||
|
},
|
||||||
"saxes": {
|
"saxes": {
|
||||||
"version": "3.1.11",
|
"version": "3.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/saxes/-/saxes-3.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/saxes/-/saxes-3.1.11.tgz",
|
||||||
@@ -9440,6 +9445,20 @@
|
|||||||
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"xml2js": {
|
||||||
|
"version": "0.4.23",
|
||||||
|
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
|
||||||
|
"integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==",
|
||||||
|
"requires": {
|
||||||
|
"sax": ">=0.6.0",
|
||||||
|
"xmlbuilder": "~11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"xmlbuilder": {
|
||||||
|
"version": "11.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
|
||||||
|
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
|
||||||
|
},
|
||||||
"xmlchars": {
|
"xmlchars": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
|
||||||
|
|||||||
@@ -54,7 +54,8 @@
|
|||||||
"socket.io": "^4.1.1",
|
"socket.io": "^4.1.1",
|
||||||
"socket.io-stream": "^0.9.1",
|
"socket.io-stream": "^0.9.1",
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^3.8.3",
|
||||||
"unzipper": "^0.10.11"
|
"unzipper": "^0.10.11",
|
||||||
|
"xml2js": "^0.4.23"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 10.x.x"
|
"node": ">= 10.x.x"
|
||||||
|
|||||||
@@ -22,6 +22,20 @@ export default class ApiService extends Service {
|
|||||||
// Access to any actions in all services under "/api" URL
|
// Access to any actions in all services under "/api" URL
|
||||||
"**",
|
"**",
|
||||||
],
|
],
|
||||||
|
cors: {
|
||||||
|
origin: "*",
|
||||||
|
methods: [
|
||||||
|
"GET",
|
||||||
|
"OPTIONS",
|
||||||
|
"POST",
|
||||||
|
"PUT",
|
||||||
|
"DELETE",
|
||||||
|
],
|
||||||
|
allowedHeaders: ["*"],
|
||||||
|
exposedHeaders: [],
|
||||||
|
credentials: false,
|
||||||
|
maxAge: 3600,
|
||||||
|
},
|
||||||
use: [],
|
use: [],
|
||||||
mergeParams: true,
|
mergeParams: true,
|
||||||
autoAliases: true,
|
autoAliases: true,
|
||||||
@@ -59,7 +73,6 @@ export default class ApiService extends Service {
|
|||||||
logRequestParams: null,
|
logRequestParams: null,
|
||||||
// Logging the response data. Set to any log level to enable it. E.g. "info"
|
// Logging the response data. Set to any log level to enable it. E.g. "info"
|
||||||
logResponseData: null,
|
logResponseData: null,
|
||||||
// Serve assets from "public" folder
|
|
||||||
assets: {
|
assets: {
|
||||||
folder: "public",
|
folder: "public",
|
||||||
// Options to `server-static` module
|
// Options to `server-static` module
|
||||||
@@ -105,10 +118,10 @@ export default class ApiService extends Service {
|
|||||||
folder
|
folder
|
||||||
);
|
);
|
||||||
|
|
||||||
client.emit("comicBookCoverMetadata", {
|
client.emit(
|
||||||
data: comicBookCoverMetadata,
|
"comicBookCoverMetadata",
|
||||||
status: "Done!",
|
comicBookCoverMetadata
|
||||||
});
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
case "single":
|
case "single":
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
|
|||||||
import { DbMixin } from "../mixins/db.mixin";
|
import { DbMixin } from "../mixins/db.mixin";
|
||||||
import Comic from "../models/comic.model";
|
import Comic from "../models/comic.model";
|
||||||
import { walkFolder } from "../utils/uncompression.utils";
|
import { walkFolder } from "../utils/uncompression.utils";
|
||||||
|
import { convertXMLToJSON } from "../utils/xml.utils";
|
||||||
|
|
||||||
export default class ProductsService extends Service {
|
export default class ProductsService extends Service {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -41,6 +42,31 @@ export default class ProductsService extends Service {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
convertXMLToJSON: {
|
||||||
|
rest: "POST /convertXmlToJson",
|
||||||
|
params: {},
|
||||||
|
async handler(ctx: Context<{}>) {
|
||||||
|
return convertXMLToJSON("lagos");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
rawImportToDB: {
|
||||||
|
rest: "POST /rawImportToDB",
|
||||||
|
params: { payload: "object" },
|
||||||
|
async handler(ctx: Context<{ payload: object }>) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
Comic.create(
|
||||||
|
ctx.params.payload,
|
||||||
|
(error, data) => {
|
||||||
|
if (data) {
|
||||||
|
resolve(data);
|
||||||
|
} else if (error) {
|
||||||
|
reject(new Error(error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {},
|
methods: {},
|
||||||
},
|
},
|
||||||
|
|||||||
24
utils/comicinfo.xml
Normal file
24
utils/comicinfo.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<ComicInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<Title>Title of the Book</Title>
|
||||||
|
<Summary>A description of the book</Summary>
|
||||||
|
<Number>1</Number>
|
||||||
|
<Count>3</Count>
|
||||||
|
<Year>2010</Year>
|
||||||
|
<Month>4</Month>
|
||||||
|
<Writer>Author name</Writer>
|
||||||
|
<Publisher>self</Publisher>
|
||||||
|
<Genre>educational</Genre>
|
||||||
|
<BlackAndWhite>No</BlackAndWhite>
|
||||||
|
<Manga>No</Manga>
|
||||||
|
<Characters>Superman</Characters>
|
||||||
|
<PageCount>5</PageCount>
|
||||||
|
<Pages>
|
||||||
|
<Page Image="0" Type="FrontCover" ImageSize="139382" ImageWidth="774" ImageHeight="1024" />
|
||||||
|
<Page Image="2" ImageSize="125736" ImageWidth="797" ImageHeight="1024" />
|
||||||
|
<Page Image="1" ImageSize="127937" ImageWidth="797" ImageHeight="1024" />
|
||||||
|
<Page Image="4" ImageSize="160902" ImageWidth="804" ImageHeight="1024" />
|
||||||
|
<Page Image="3" ImageSize="211181" ImageWidth="804" ImageHeight="1024" />
|
||||||
|
</Pages>
|
||||||
|
</ComicInfo>
|
||||||
@@ -205,12 +205,15 @@ export const unzip = async (
|
|||||||
}
|
}
|
||||||
if (fileName !== "" && entry.type !== "Directory") {
|
if (fileName !== "" && entry.type !== "Directory") {
|
||||||
logger.info(`Attempting to write ${fileName}`);
|
logger.info(`Attempting to write ${fileName}`);
|
||||||
entry.pipe(createWriteStream(paths.targetPath + "/" + fileName));
|
entry
|
||||||
extractedFiles.push({
|
.pipe(createWriteStream(paths.targetPath + "/" + fileName))
|
||||||
name: fileName,
|
.on("finish", () => {
|
||||||
fileSize: size,
|
extractedFiles.push({
|
||||||
path: paths.targetPath,
|
name: fileName,
|
||||||
});
|
fileSize: size,
|
||||||
|
path: paths.targetPath,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
entry.autodrain();
|
entry.autodrain();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import {
|
|||||||
IFolderData,
|
IFolderData,
|
||||||
} from "../interfaces/folder.interface";
|
} from "../interfaces/folder.interface";
|
||||||
const Validator = require("fastest-validator");
|
const Validator = require("fastest-validator");
|
||||||
|
import { logger } from "./logger.utils";
|
||||||
|
|
||||||
export const validateComicBookMetadata = (
|
export const validateComicBookMetadata = (
|
||||||
comicBookMetadataObject: IExtractedComicBookCoverFile
|
comicBookMetadataObject: IExtractedComicBookCoverFile
|
||||||
): boolean => {
|
): boolean => {
|
||||||
console.log(comicBookMetadataObject);
|
|
||||||
const validator = new Validator();
|
const validator = new Validator();
|
||||||
const sch = {
|
const sch = {
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
@@ -18,5 +18,13 @@ export const validateComicBookMetadata = (
|
|||||||
path: { type: "string" },
|
path: { type: "string" },
|
||||||
};
|
};
|
||||||
const check = validator.compile(sch);
|
const check = validator.compile(sch);
|
||||||
|
if (check(comicBookMetadataObject)) {
|
||||||
|
logger.info(`Valid comic book metadata: ${comicBookMetadataObject}`);
|
||||||
|
} else {
|
||||||
|
logger.error(
|
||||||
|
`Comic book metadata was invalid:
|
||||||
|
${comicBookMetadataObject}`
|
||||||
|
);
|
||||||
|
}
|
||||||
return check(comicBookMetadataObject);
|
return check(comicBookMetadataObject);
|
||||||
};
|
};
|
||||||
|
|||||||
48
utils/xml.utils.ts
Normal file
48
utils/xml.utils.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Rishi Ghan
|
||||||
|
*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2021 Rishi Ghan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import xml2js from "xml2js";
|
||||||
|
import fs from "fs";
|
||||||
|
import { logger } from "../utils/logger.utils";
|
||||||
|
|
||||||
|
export const convertXMLToJSON = (xmlPayload) => {
|
||||||
|
const parser = new xml2js.Parser({
|
||||||
|
mergeAttrs: true,
|
||||||
|
trim: true,
|
||||||
|
normalizeTags: true,
|
||||||
|
});
|
||||||
|
const xml = fs.readFileSync(__dirname + "/comicinfo.xml", "utf8");
|
||||||
|
return parser
|
||||||
|
.parseStringPromise(xml)
|
||||||
|
.then((result) => {
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
logger.error(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user