🔧 Refactoring to move away from calibre for uncompression and extraction
This commit is contained in:
@@ -57,12 +57,13 @@ const ComicSchema = mongoose.Schema(
|
|||||||
shortboxed: {},
|
shortboxed: {},
|
||||||
gcd: {},
|
gcd: {},
|
||||||
},
|
},
|
||||||
rawFileDetails: { type: RawFileDetailsSchema, es_indexed: true },
|
rawFileDetails: { type: RawFileDetailsSchema, es_indexed: true, default: {} },
|
||||||
inferredMetadata: {
|
inferredMetadata: {
|
||||||
issue: {
|
issue: {
|
||||||
name: { type: String, es_indexed: true },
|
name: { type: String, es_indexed: true },
|
||||||
number: {
|
number: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
es_indexed: true,
|
||||||
required: false,
|
required: false,
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ const VolumeInformation = mongoose.Schema({
|
|||||||
original_url: String,
|
original_url: String,
|
||||||
image_tags: String,
|
image_tags: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
issues: [
|
issues: [
|
||||||
{
|
{
|
||||||
api_detail_url: String,
|
api_detail_url: String,
|
||||||
@@ -72,6 +71,19 @@ const ComicVineMetadataSchema = mongoose.Schema({
|
|||||||
date_last_updated: String,
|
date_last_updated: String,
|
||||||
deck: String,
|
deck: String,
|
||||||
description: String,
|
description: String,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
|
||||||
has_staff_review: Boolean,
|
has_staff_review: Boolean,
|
||||||
id: Number,
|
id: Number,
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -124,7 +124,8 @@ export default class ImportService extends Service {
|
|||||||
let comicExists = await Comic.exists({
|
let comicExists = await Comic.exists({
|
||||||
"rawFileDetails.name": `${path.basename(
|
"rawFileDetails.name": `${path.basename(
|
||||||
item.path,
|
item.path,
|
||||||
path.extname(item.path)
|
path.extname(item.path),
|
||||||
|
|
||||||
)}`,
|
)}`,
|
||||||
});
|
});
|
||||||
if (!comicExists) {
|
if (!comicExists) {
|
||||||
@@ -171,7 +172,7 @@ export default class ImportService extends Service {
|
|||||||
) {
|
) {
|
||||||
let volumeDetails;
|
let volumeDetails;
|
||||||
const comicMetadata = ctx.params;
|
const comicMetadata = ctx.params;
|
||||||
|
console.log(comicMetadata);
|
||||||
// When an issue is added from the search CV feature
|
// When an issue is added from the search CV feature
|
||||||
if (
|
if (
|
||||||
comicMetadata.sourcedMetadata.comicvine &&
|
comicMetadata.sourcedMetadata.comicvine &&
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import BullMQMixin from "moleculer-bull";
|
|||||||
import { SandboxedJob } from "moleculer-bull";
|
import { SandboxedJob } from "moleculer-bull";
|
||||||
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 { extractComicInfoXMLFromArchive, extractCoverFromFile2 } from "../utils/uncompression.utils";
|
import { extractFromArchive, extractCoverFromFile2 } from "../utils/uncompression.utils";
|
||||||
import { refineQuery } from "filename-parser";
|
import { refineQuery } from "filename-parser";
|
||||||
import { io } from "./api.service";
|
import { io } from "./api.service";
|
||||||
import { getFileConstituents } from "../utils/file.utils";
|
import { getFileConstituents } from "../utils/file.utils";
|
||||||
@@ -76,7 +76,13 @@ export default class QueueService extends Service {
|
|||||||
// infer any issue-related metadata from the filename
|
// infer any issue-related metadata from the filename
|
||||||
const { inferredIssueDetails } = refineQuery(result.name);
|
const { inferredIssueDetails } = refineQuery(result.name);
|
||||||
console.log("Issue metadata inferred: ", JSON.stringify(inferredIssueDetails, null, 2));
|
console.log("Issue metadata inferred: ", JSON.stringify(inferredIssueDetails, null, 2));
|
||||||
|
// const {
|
||||||
|
// extension,
|
||||||
|
// fileNameWithExtension,
|
||||||
|
// fileNameWithoutExtension,
|
||||||
|
// } = getFileConstituents(job.data.fileObject.filePath);
|
||||||
|
// const targetDirectory = `${USERDATA_DIRECTORY}/covers/${fileNameWithoutExtension}`;
|
||||||
|
// const foo = await extractFromArchive(job.data.fileObject.filePath, targetDirectory, extension );
|
||||||
// write to mongo
|
// write to mongo
|
||||||
console.log("Writing to mongo...")
|
console.log("Writing to mongo...")
|
||||||
const dbImportResult = await this.broker.call(
|
const dbImportResult = await this.broker.call(
|
||||||
|
|||||||
@@ -51,12 +51,11 @@ export default class SettingsService extends Service {
|
|||||||
const { body } = await eSClient.msearch({
|
const { body } = await eSClient.msearch({
|
||||||
body: queries,
|
body: queries,
|
||||||
});
|
});
|
||||||
|
body.responses.forEach((match) => {
|
||||||
body.results.forEach((match) => {
|
console.log(match.hits);
|
||||||
console.log(match.hits.hits);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return body.results;
|
return body.responses;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
issue: {
|
issue: {
|
||||||
|
|||||||
@@ -189,23 +189,33 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
const extractor = await unrar.createExtractorFromData({
|
const extractor = await unrar.createExtractorFromData({
|
||||||
data: fileBuffer,
|
data: fileBuffer,
|
||||||
});
|
});
|
||||||
|
console.info('Unrar initiating.');
|
||||||
|
|
||||||
const extracted = extractor.extract({
|
|
||||||
files: ({ name }) => name.toLowerCase() === 'comicinfo.xml',
|
|
||||||
});
|
const files = extractor.extract({});
|
||||||
const files = [...extracted.files]; //load the files
|
const extractedFiles = [...files.files];
|
||||||
if (!isUndefined(files[0])) {
|
console.log(extractedFiles[0]);
|
||||||
console.log(
|
for (const file of extractedFiles) {
|
||||||
`comicinfo.xml detected in ${filePath}, attempting extraction...`
|
console.info(`Attempting to write ${file.fileHeader.name}`);
|
||||||
);
|
}
|
||||||
const fileContents = String.fromCharCode.apply(
|
|
||||||
null,
|
// const extracted = extractor.extract({
|
||||||
files[0].extraction
|
// files: ({ name }) => name.toLowerCase() === 'comicinfo.xml',
|
||||||
);
|
// });
|
||||||
const parsedJSON = await convertXMLToJSON(fileContents);
|
// const files = [...extracted.files]; //load the files
|
||||||
console.log(parsedJSON);
|
// if (!isUndefined(files[0])) {
|
||||||
return parsedJSON.comicinfo;
|
// console.log(
|
||||||
}
|
// `comicinfo.xml detected in ${filePath}, attempting extraction...`
|
||||||
|
// );
|
||||||
|
// const fileContents = String.fromCharCode.apply(
|
||||||
|
// null,
|
||||||
|
// files[0].extraction
|
||||||
|
// );
|
||||||
|
// const parsedJSON = await convertXMLToJSON(fileContents);
|
||||||
|
// console.log(parsedJSON);
|
||||||
|
// return parsedJSON.comicinfo;
|
||||||
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
@@ -237,7 +247,7 @@ export const extractComicInfoXMLFromZip = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractComicInfoXMLFromArchive = async (
|
export const extractFromArchive = async (
|
||||||
filePath: string,
|
filePath: string,
|
||||||
outputDirectory: string,
|
outputDirectory: string,
|
||||||
extension: string
|
extension: string
|
||||||
|
|||||||
Reference in New Issue
Block a user