🔧 Support for LOCG

This commit is contained in:
2022-05-23 23:02:05 -07:00
parent 0b195d6ff3
commit c4b421bc28
6 changed files with 108 additions and 59 deletions

View File

@@ -8,7 +8,8 @@ import {
MongoosasticModel, MongoosasticModel,
MongoosasticPluginOpts, MongoosasticPluginOpts,
} from "mongoosastic-ts/dist/types"; } from "mongoosastic-ts/dist/types";
const ELASTICSEARCH_HOST = process.env.ELASTICSEARCH_URI || "http://localhost:9200"; const ELASTICSEARCH_HOST =
process.env.ELASTICSEARCH_URI || "http://localhost:9200";
export const eSClient = new Client({ export const eSClient = new Client({
node: ELASTICSEARCH_HOST, node: ELASTICSEARCH_HOST,
auth: { auth: {
@@ -34,6 +35,19 @@ const RawFileDetailsSchema = mongoose.Schema({
}, },
}); });
const LOCGSchema = mongoose.Schema({
_id: false,
name: String,
publisher: String,
url: String,
cover: String,
description: String,
price: String,
rating: Number,
pulls: Number,
potw: Number,
});
const ComicSchema = mongoose.Schema( const ComicSchema = mongoose.Schema(
{ {
importStatus: { importStatus: {
@@ -54,6 +68,11 @@ const ComicSchema = mongoose.Schema(
default: {}, default: {},
}, },
shortboxed: {}, shortboxed: {},
locg: {
type: LOCGSchema,
es_indexed: true,
default: {},
},
gcd: {}, gcd: {},
}, },
rawFileDetails: { rawFileDetails: {
@@ -75,7 +94,10 @@ const ComicSchema = mongoose.Schema(
}, },
}, },
acquisition: { acquisition: {
wanted: Boolean, source: {
wanted: Boolean,
name: String,
},
release: {}, release: {},
directconnect: Array, directconnect: Array,
torrent: { torrent: {
@@ -98,7 +120,7 @@ ComicSchema.plugin(mongoosastic, {
ComicSchema.plugin(paginate); ComicSchema.plugin(paginate);
const Comic = mongoose.model("Comic", ComicSchema); const Comic = mongoose.model("Comic", ComicSchema);
// stream = Comic.synchronize(); // const stream = Comic.synchronize();
// let count = 0; // let count = 0;
// stream.on("data", function (err, doc) { // stream.on("data", function (err, doc) {

View File

@@ -116,7 +116,9 @@ export default class QueueService extends Service {
// since we already have at least 1 copy // since we already have at least 1 copy
// mark it as not wanted by default // mark it as not wanted by default
acquisition: { acquisition: {
wanted: false, source: {
wanted: false,
},
}, },
}); });
return { return {
@@ -176,7 +178,7 @@ export default class QueueService extends Service {
unarchiveComicBook: { unarchiveComicBook: {
rest: "POST /unarchiveComicBook", rest: "POST /unarchiveComicBook",
params: {}, params: {},
handler: async (ctx: Context<{}>) => { }, handler: async (ctx: Context<{}>) => {},
}, },
}, },
methods: {}, methods: {},

View File

@@ -47,7 +47,10 @@ import {
walkFolder, walkFolder,
getSizeOfDirectory, getSizeOfDirectory,
} from "../utils/file.utils"; } from "../utils/file.utils";
import { extractFromArchive, uncompressEntireArchive } from "../utils/uncompression.utils"; import {
extractFromArchive,
uncompressEntireArchive,
} from "../utils/uncompression.utils";
import { convertXMLToJSON } from "../utils/xml.utils"; import { convertXMLToJSON } from "../utils/xml.utils";
import { import {
IExtractComicBookCoverErrorResponse, IExtractComicBookCoverErrorResponse,
@@ -93,8 +96,10 @@ export default class ImportService extends Service {
rest: "POST /uncompressFullArchive", rest: "POST /uncompressFullArchive",
params: {}, params: {},
handler: async (ctx: Context<{ filePath: string }>) => { handler: async (ctx: Context<{ filePath: string }>) => {
return await uncompressEntireArchive(ctx.params.filePath); return await uncompressEntireArchive(
} ctx.params.filePath
);
},
}, },
newImport: { newImport: {
rest: "POST /newImport", rest: "POST /newImport",
@@ -162,11 +167,13 @@ export default class ImportService extends Service {
params: {}, params: {},
async handler( async handler(
ctx: Context<{ ctx: Context<{
_id: string,
sourcedMetadata: { sourcedMetadata: {
comicvine?: { comicvine?: {
volume: { api_detail_url: string }; volume: { api_detail_url: string };
volumeInformation: {}; volumeInformation: {};
}; };
locg?: {};
}; };
inferredMetadata: { inferredMetadata: {
issue: Object; issue: Object;
@@ -175,7 +182,10 @@ export default class ImportService extends Service {
name: string; name: string;
}; };
acquisition: { acquisition: {
wanted: boolean; source: {
wanted: boolean;
name?: string;
};
}; };
}> }>
) { ) {
@@ -184,6 +194,7 @@ export default class ImportService extends Service {
const comicMetadata = ctx.params; const comicMetadata = ctx.params;
console.log(JSON.stringify(comicMetadata, null, 4)); console.log(JSON.stringify(comicMetadata, null, 4));
// When an issue is added from the search CV feature // When an issue is added from the search CV feature
// we solicit volume information and add that to mongo
if ( if (
comicMetadata.sourcedMetadata.comicvine && comicMetadata.sourcedMetadata.comicvine &&
!isNil( !isNil(
@@ -203,18 +214,23 @@ export default class ImportService extends Service {
comicMetadata.sourcedMetadata.comicvine.volumeInformation = comicMetadata.sourcedMetadata.comicvine.volumeInformation =
volumeDetails.results; volumeDetails.results;
} }
Comic.create(ctx.params, (error, data) => { Comic.findOneAndUpdate(
if (data) { { _id: new ObjectId(ctx.params._id) },
return data; ctx.params,
} else if (error) { { upsert: true, new: true },
console.log("data", data); (error, data) => {
console.log("error", error); if (data) {
throw new Errors.MoleculerError( return data;
"Failed to import comic book", } else if (error) {
500 console.log("data", data);
); console.log("error", error);
} throw new Errors.MoleculerError(
}); "Failed to import comic book",
500
);
}
},
);
} catch (error) { } catch (error) {
throw new Errors.MoleculerError( throw new Errors.MoleculerError(
"Import failed.", "Import failed.",
@@ -322,21 +338,31 @@ export default class ImportService extends Service {
importDownloadedFileToLibrary: { importDownloadedFileToLibrary: {
rest: "POST /importDownloadedFileToLibrary", rest: "POST /importDownloadedFileToLibrary",
params: {}, params: {},
handler: async (ctx: Context<{ comicObjectId: string; downloadStatus: { name: string; } }>) => { handler: async (
console.log("miscommunicate"); ctx: Context<{
console.log( comicObjectId: string;
JSON.stringify(ctx.params, null, 2) comicObject: {
); acquisition: {
source:{
wanted: boolean;
}
}
};
downloadStatus: { name: string };
}>
) => {
const result = await extractFromArchive( const result = await extractFromArchive(
`${COMICS_DIRECTORY}/${ctx.params.downloadStatus.name}` `${COMICS_DIRECTORY}/${ctx.params.downloadStatus.name}`
); );
console.log(result); Object.assign(ctx.params.comicObject, { rawFileDetails: result });
await Comic.findOneAndUpdate({ _id: new ObjectId(ctx.params.comicObjectId) }, { ctx.params.comicObject.acquisition.source.wanted = false;
rawFileDetails: result, const updateResult = await Comic.findOneAndUpdate(
acquisition: { wanted: false, } { _id: new ObjectId(ctx.params.comicObjectId) },
ctx.params.comicObject,
}) { upsert: true, new: true }
} );
await updateResult.index();
},
}, },
getComicBooks: { getComicBooks: {
@@ -519,9 +545,9 @@ export default class ImportService extends Service {
{ {
$match: { $match: {
"sourcedMetadata.comicvine.volumeInformation": "sourcedMetadata.comicvine.volumeInformation":
{ {
$gt: {}, $gt: {},
}, },
}, },
}, },
{ {

View File

@@ -90,6 +90,7 @@ export default class SettingsService extends Service {
multi_match: { multi_match: {
fields: [ fields: [
"rawFileDetails.name", "rawFileDetails.name",
"sourcedMetadata.locg.name",
"sourcedMetadata.comicvine.name", "sourcedMetadata.comicvine.name",
"sourcedMetadata.comicvine.volumeInformation.name", "sourcedMetadata.comicvine.volumeInformation.name",
], ],
@@ -102,7 +103,7 @@ export default class SettingsService extends Service {
bool: { bool: {
must: { must: {
term: { term: {
"acquisition.wanted": "acquisition.source.wanted":
true, true,
}, },
}, },

View File

@@ -28,8 +28,6 @@ export default class SocketService extends Service {
}, },
action: async (data, ack) => { action: async (data, ack) => {
// write your handler function here. // write your handler function here.
switch (data.type) { switch (data.type) {
case "LS_IMPORT": case "LS_IMPORT":
console.log( console.log(
@@ -51,7 +49,7 @@ export default class SocketService extends Service {
break; break;
case "LS_SINGLE_IMPORT": case "LS_SINGLE_IMPORT":
console.info("AirDC++ finished a download -> ") console.info("AirDC++ finished a download -> ")
console.log(data);
await this.broker.call("library.importDownloadedFileToLibrary", data.data, {}); await this.broker.call("library.importDownloadedFileToLibrary", data.data, {});
break; break;
} }

View File

@@ -108,14 +108,16 @@ export const extractComicInfoXMLFromRar = async (
const comicInfoXMLFilePromise = new Promise((resolve, reject) => { const comicInfoXMLFilePromise = new Promise((resolve, reject) => {
let comicinfostring = ""; let comicinfostring = "";
if (!isUndefined(comicInfoXML[0])) { if (!isUndefined(comicInfoXML[0])) {
console.log(path.basename(comicInfoXML[0].name));
const comicInfoXMLFileName = path.basename(comicInfoXML[0].name);
const writeStream = createWriteStream( const writeStream = createWriteStream(
`${targetDirectory}/${comicInfoXML[0].name}` `${targetDirectory}/${comicInfoXMLFileName}`
); );
archive.stream(comicInfoXML[0]["name"]).pipe(writeStream); archive.stream(comicInfoXML[0]["name"]).pipe(writeStream);
writeStream.on("finish", async () => { writeStream.on("finish", async () => {
const readStream = createReadStream( const readStream = createReadStream(
`${targetDirectory}/${comicInfoXML[0].name}` `${targetDirectory}/${comicInfoXMLFileName}`
); );
readStream.on("data", (data) => { readStream.on("data", (data) => {
comicinfostring += data; comicinfostring += data;
@@ -123,11 +125,7 @@ export const extractComicInfoXMLFromRar = async (
readStream.on("error", (error) => reject(error)); readStream.on("error", (error) => reject(error));
readStream.on("end", async () => { readStream.on("end", async () => {
if ( if (
existsSync( existsSync(`${targetDirectory}/${comicInfoXMLFileName}`)
`${targetDirectory}/${path.basename(
comicInfoXML[0].name
)}`
)
) { ) {
const comicInfoJSON = await convertXMLToJSON( const comicInfoJSON = await convertXMLToJSON(
comicinfostring.toString() comicinfostring.toString()
@@ -378,18 +376,20 @@ export const uncompressRarArchive = async (filePath: string) => {
// iterate over the files // iterate over the files
each(filesInArchive, (file) => { each(filesInArchive, (file) => {
extractionPromises.push(new Promise((resolve, reject) => { extractionPromises.push(
const fileExtractionStream = archive.stream(file.name); new Promise((resolve, reject) => {
const fileWriteStream = createWriteStream( const fileExtractionStream = archive.stream(file.name);
`${targetDirectory}/${path.basename(file.name)}`) const fileWriteStream = createWriteStream(
fileExtractionStream.pipe(fileWriteStream); `${targetDirectory}/${path.basename(file.name)}`
fileWriteStream.on("finish", async () => { );
resolve(`${targetDirectory}/${path.basename(file.name)}`); fileExtractionStream.pipe(fileWriteStream);
}); fileWriteStream.on("finish", async () => {
resolve(`${targetDirectory}/${path.basename(file.name)}`);
})); });
}) })
return Promise.all(extractionPromises); );
});
return Promise.all(extractionPromises);
}; };
export const resizeImageDirectory = async (directoryPath: string) => { export const resizeImageDirectory = async (directoryPath: string) => {