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