🔧 Support for LOCG
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
||||
MongoosasticModel,
|
||||
MongoosasticPluginOpts,
|
||||
} 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({
|
||||
node: ELASTICSEARCH_HOST,
|
||||
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(
|
||||
{
|
||||
importStatus: {
|
||||
@@ -54,6 +68,11 @@ const ComicSchema = mongoose.Schema(
|
||||
default: {},
|
||||
},
|
||||
shortboxed: {},
|
||||
locg: {
|
||||
type: LOCGSchema,
|
||||
es_indexed: true,
|
||||
default: {},
|
||||
},
|
||||
gcd: {},
|
||||
},
|
||||
rawFileDetails: {
|
||||
@@ -75,7 +94,10 @@ const ComicSchema = mongoose.Schema(
|
||||
},
|
||||
},
|
||||
acquisition: {
|
||||
wanted: Boolean,
|
||||
source: {
|
||||
wanted: Boolean,
|
||||
name: String,
|
||||
},
|
||||
release: {},
|
||||
directconnect: Array,
|
||||
torrent: {
|
||||
@@ -98,7 +120,7 @@ ComicSchema.plugin(mongoosastic, {
|
||||
ComicSchema.plugin(paginate);
|
||||
|
||||
const Comic = mongoose.model("Comic", ComicSchema);
|
||||
// stream = Comic.synchronize();
|
||||
// const stream = Comic.synchronize();
|
||||
// let count = 0;
|
||||
|
||||
// stream.on("data", function (err, doc) {
|
||||
|
||||
@@ -116,7 +116,9 @@ export default class QueueService extends Service {
|
||||
// since we already have at least 1 copy
|
||||
// mark it as not wanted by default
|
||||
acquisition: {
|
||||
wanted: false,
|
||||
source: {
|
||||
wanted: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
@@ -176,7 +178,7 @@ export default class QueueService extends Service {
|
||||
unarchiveComicBook: {
|
||||
rest: "POST /unarchiveComicBook",
|
||||
params: {},
|
||||
handler: async (ctx: Context<{}>) => { },
|
||||
handler: async (ctx: Context<{}>) => {},
|
||||
},
|
||||
},
|
||||
methods: {},
|
||||
|
||||
@@ -47,7 +47,10 @@ import {
|
||||
walkFolder,
|
||||
getSizeOfDirectory,
|
||||
} 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 {
|
||||
IExtractComicBookCoverErrorResponse,
|
||||
@@ -93,8 +96,10 @@ export default class ImportService extends Service {
|
||||
rest: "POST /uncompressFullArchive",
|
||||
params: {},
|
||||
handler: async (ctx: Context<{ filePath: string }>) => {
|
||||
return await uncompressEntireArchive(ctx.params.filePath);
|
||||
}
|
||||
return await uncompressEntireArchive(
|
||||
ctx.params.filePath
|
||||
);
|
||||
},
|
||||
},
|
||||
newImport: {
|
||||
rest: "POST /newImport",
|
||||
@@ -162,11 +167,13 @@ export default class ImportService extends Service {
|
||||
params: {},
|
||||
async handler(
|
||||
ctx: Context<{
|
||||
_id: string,
|
||||
sourcedMetadata: {
|
||||
comicvine?: {
|
||||
volume: { api_detail_url: string };
|
||||
volumeInformation: {};
|
||||
};
|
||||
locg?: {};
|
||||
};
|
||||
inferredMetadata: {
|
||||
issue: Object;
|
||||
@@ -175,7 +182,10 @@ export default class ImportService extends Service {
|
||||
name: string;
|
||||
};
|
||||
acquisition: {
|
||||
wanted: boolean;
|
||||
source: {
|
||||
wanted: boolean;
|
||||
name?: string;
|
||||
};
|
||||
};
|
||||
}>
|
||||
) {
|
||||
@@ -184,6 +194,7 @@ export default class ImportService extends Service {
|
||||
const comicMetadata = ctx.params;
|
||||
console.log(JSON.stringify(comicMetadata, null, 4));
|
||||
// When an issue is added from the search CV feature
|
||||
// we solicit volume information and add that to mongo
|
||||
if (
|
||||
comicMetadata.sourcedMetadata.comicvine &&
|
||||
!isNil(
|
||||
@@ -203,18 +214,23 @@ export default class ImportService extends Service {
|
||||
comicMetadata.sourcedMetadata.comicvine.volumeInformation =
|
||||
volumeDetails.results;
|
||||
}
|
||||
Comic.create(ctx.params, (error, data) => {
|
||||
if (data) {
|
||||
return data;
|
||||
} else if (error) {
|
||||
console.log("data", data);
|
||||
console.log("error", error);
|
||||
throw new Errors.MoleculerError(
|
||||
"Failed to import comic book",
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
Comic.findOneAndUpdate(
|
||||
{ _id: new ObjectId(ctx.params._id) },
|
||||
ctx.params,
|
||||
{ upsert: true, new: true },
|
||||
(error, data) => {
|
||||
if (data) {
|
||||
return data;
|
||||
} else if (error) {
|
||||
console.log("data", data);
|
||||
console.log("error", error);
|
||||
throw new Errors.MoleculerError(
|
||||
"Failed to import comic book",
|
||||
500
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Errors.MoleculerError(
|
||||
"Import failed.",
|
||||
@@ -322,21 +338,31 @@ export default class ImportService extends Service {
|
||||
importDownloadedFileToLibrary: {
|
||||
rest: "POST /importDownloadedFileToLibrary",
|
||||
params: {},
|
||||
handler: async (ctx: Context<{ comicObjectId: string; downloadStatus: { name: string; } }>) => {
|
||||
console.log("miscommunicate");
|
||||
console.log(
|
||||
JSON.stringify(ctx.params, null, 2)
|
||||
);
|
||||
handler: async (
|
||||
ctx: Context<{
|
||||
comicObjectId: string;
|
||||
comicObject: {
|
||||
acquisition: {
|
||||
source:{
|
||||
wanted: boolean;
|
||||
}
|
||||
}
|
||||
};
|
||||
downloadStatus: { name: string };
|
||||
}>
|
||||
) => {
|
||||
const result = await extractFromArchive(
|
||||
`${COMICS_DIRECTORY}/${ctx.params.downloadStatus.name}`
|
||||
);
|
||||
console.log(result);
|
||||
await Comic.findOneAndUpdate({ _id: new ObjectId(ctx.params.comicObjectId) }, {
|
||||
rawFileDetails: result,
|
||||
acquisition: { wanted: false, }
|
||||
|
||||
})
|
||||
}
|
||||
Object.assign(ctx.params.comicObject, { rawFileDetails: result });
|
||||
ctx.params.comicObject.acquisition.source.wanted = false;
|
||||
const updateResult = await Comic.findOneAndUpdate(
|
||||
{ _id: new ObjectId(ctx.params.comicObjectId) },
|
||||
ctx.params.comicObject,
|
||||
{ upsert: true, new: true }
|
||||
);
|
||||
await updateResult.index();
|
||||
},
|
||||
},
|
||||
|
||||
getComicBooks: {
|
||||
@@ -519,9 +545,9 @@ export default class ImportService extends Service {
|
||||
{
|
||||
$match: {
|
||||
"sourcedMetadata.comicvine.volumeInformation":
|
||||
{
|
||||
$gt: {},
|
||||
},
|
||||
{
|
||||
$gt: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -90,6 +90,7 @@ export default class SettingsService extends Service {
|
||||
multi_match: {
|
||||
fields: [
|
||||
"rawFileDetails.name",
|
||||
"sourcedMetadata.locg.name",
|
||||
"sourcedMetadata.comicvine.name",
|
||||
"sourcedMetadata.comicvine.volumeInformation.name",
|
||||
],
|
||||
@@ -102,7 +103,7 @@ export default class SettingsService extends Service {
|
||||
bool: {
|
||||
must: {
|
||||
term: {
|
||||
"acquisition.wanted":
|
||||
"acquisition.source.wanted":
|
||||
true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -28,8 +28,6 @@ export default class SocketService extends Service {
|
||||
},
|
||||
action: async (data, ack) => {
|
||||
// write your handler function here.
|
||||
|
||||
|
||||
switch (data.type) {
|
||||
case "LS_IMPORT":
|
||||
console.log(
|
||||
@@ -51,7 +49,7 @@ export default class SocketService extends Service {
|
||||
break;
|
||||
case "LS_SINGLE_IMPORT":
|
||||
console.info("AirDC++ finished a download -> ")
|
||||
|
||||
console.log(data);
|
||||
await this.broker.call("library.importDownloadedFileToLibrary", data.data, {});
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -108,14 +108,16 @@ export const extractComicInfoXMLFromRar = async (
|
||||
const comicInfoXMLFilePromise = new Promise((resolve, reject) => {
|
||||
let comicinfostring = "";
|
||||
if (!isUndefined(comicInfoXML[0])) {
|
||||
console.log(path.basename(comicInfoXML[0].name));
|
||||
const comicInfoXMLFileName = path.basename(comicInfoXML[0].name);
|
||||
const writeStream = createWriteStream(
|
||||
`${targetDirectory}/${comicInfoXML[0].name}`
|
||||
`${targetDirectory}/${comicInfoXMLFileName}`
|
||||
);
|
||||
|
||||
archive.stream(comicInfoXML[0]["name"]).pipe(writeStream);
|
||||
writeStream.on("finish", async () => {
|
||||
const readStream = createReadStream(
|
||||
`${targetDirectory}/${comicInfoXML[0].name}`
|
||||
`${targetDirectory}/${comicInfoXMLFileName}`
|
||||
);
|
||||
readStream.on("data", (data) => {
|
||||
comicinfostring += data;
|
||||
@@ -123,11 +125,7 @@ export const extractComicInfoXMLFromRar = async (
|
||||
readStream.on("error", (error) => reject(error));
|
||||
readStream.on("end", async () => {
|
||||
if (
|
||||
existsSync(
|
||||
`${targetDirectory}/${path.basename(
|
||||
comicInfoXML[0].name
|
||||
)}`
|
||||
)
|
||||
existsSync(`${targetDirectory}/${comicInfoXMLFileName}`)
|
||||
) {
|
||||
const comicInfoJSON = await convertXMLToJSON(
|
||||
comicinfostring.toString()
|
||||
@@ -378,18 +376,20 @@ export const uncompressRarArchive = async (filePath: string) => {
|
||||
// iterate over the files
|
||||
|
||||
each(filesInArchive, (file) => {
|
||||
extractionPromises.push(new Promise((resolve, reject) => {
|
||||
const fileExtractionStream = archive.stream(file.name);
|
||||
const fileWriteStream = createWriteStream(
|
||||
`${targetDirectory}/${path.basename(file.name)}`)
|
||||
fileExtractionStream.pipe(fileWriteStream);
|
||||
fileWriteStream.on("finish", async () => {
|
||||
resolve(`${targetDirectory}/${path.basename(file.name)}`);
|
||||
});
|
||||
|
||||
}));
|
||||
})
|
||||
return Promise.all(extractionPromises);
|
||||
extractionPromises.push(
|
||||
new Promise((resolve, reject) => {
|
||||
const fileExtractionStream = archive.stream(file.name);
|
||||
const fileWriteStream = createWriteStream(
|
||||
`${targetDirectory}/${path.basename(file.name)}`
|
||||
);
|
||||
fileExtractionStream.pipe(fileWriteStream);
|
||||
fileWriteStream.on("finish", async () => {
|
||||
resolve(`${targetDirectory}/${path.basename(file.name)}`);
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
return Promise.all(extractionPromises);
|
||||
};
|
||||
|
||||
export const resizeImageDirectory = async (directoryPath: string) => {
|
||||
|
||||
Reference in New Issue
Block a user