🔧 Added a download -> library import endpoint
This commit is contained in:
@@ -47,7 +47,7 @@ import {
|
||||
walkFolder,
|
||||
getSizeOfDirectory,
|
||||
} from "../utils/file.utils";
|
||||
import { uncompressEntireArchive } from "../utils/uncompression.utils";
|
||||
import { extractFromArchive, uncompressEntireArchive } from "../utils/uncompression.utils";
|
||||
import { convertXMLToJSON } from "../utils/xml.utils";
|
||||
import {
|
||||
IExtractComicBookCoverErrorResponse,
|
||||
@@ -89,10 +89,10 @@ export default class ImportService extends Service {
|
||||
return convertXMLToJSON("lagos");
|
||||
},
|
||||
},
|
||||
uncompressFullArchive : {
|
||||
uncompressFullArchive: {
|
||||
rest: "POST /uncompressFullArchive",
|
||||
params: {},
|
||||
handler: async (ctx: Context<{filePath: string}>) => {
|
||||
handler: async (ctx: Context<{ filePath: string }>) => {
|
||||
return await uncompressEntireArchive(ctx.params.filePath);
|
||||
}
|
||||
},
|
||||
@@ -109,7 +109,7 @@ export default class ImportService extends Service {
|
||||
klaw(path.resolve(COMICS_DIRECTORY))
|
||||
// 1.1 Filter on .cb* extensions
|
||||
.pipe(
|
||||
through2.obj(function(item, enc, next) {
|
||||
through2.obj(function (item, enc, next) {
|
||||
let fileExtension = path.extname(item.path);
|
||||
if (
|
||||
[".cbz", ".cbr", ".cb7"].includes(
|
||||
@@ -319,6 +319,25 @@ 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)
|
||||
);
|
||||
const result = await extractFromArchive(
|
||||
`${COMICS_DIRECTORY}/${ctx.params.downloadStatus.name}`
|
||||
);
|
||||
console.log(result);
|
||||
await Comic.findOneAndUpdate({ _id: new ObjectId(ctx.params.comicObjectId) }, {
|
||||
rawFileDetails: {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
getComicBooks: {
|
||||
rest: "POST /getComicBooks",
|
||||
|
||||
@@ -28,9 +28,7 @@ export default class SocketService extends Service {
|
||||
},
|
||||
action: async (data, ack) => {
|
||||
// write your handler function here.
|
||||
console.log(
|
||||
JSON.stringify(data, null, 2)
|
||||
);
|
||||
|
||||
|
||||
switch (data.type) {
|
||||
case "LS_IMPORT":
|
||||
@@ -52,7 +50,9 @@ export default class SocketService extends Service {
|
||||
);
|
||||
break;
|
||||
case "LS_SINGLE_IMPORT":
|
||||
console.log(data.data);
|
||||
console.info("AirDC++ finished a download -> ")
|
||||
|
||||
await this.broker.call("library.importDownloadedFileToLibrary", data.data, {});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user