👷🏽 Workerizing the import algorithm
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import * as Comlink from "comlink";
|
||||
import { extractCoverFromComicBookArchive } from "../shared/utils/folder.utils";
|
||||
import { walkFolder } from "../actions/fileops.actions";
|
||||
import { IExtractionOptions } from "../../server/interfaces/folder.interface";
|
||||
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
function importComicBooks() {
|
||||
async function importComicBooks() {
|
||||
// 1. Walk the folder structure
|
||||
// 2. Scan for .cbz, .cbr
|
||||
// 3. extract cover image
|
||||
@@ -12,10 +10,12 @@ function importComicBooks() {
|
||||
// 5. Get metadata, add to data model
|
||||
// 5. Save cover to disk
|
||||
// 6. Save model to mongo
|
||||
|
||||
const fileObjects = await walkFolder("./comics");
|
||||
}
|
||||
|
||||
Comlink.expose({
|
||||
add,
|
||||
importComicBooks,
|
||||
});
|
||||
|
||||
export default null as any;
|
||||
|
||||
@@ -30,7 +30,7 @@ router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
||||
});
|
||||
});
|
||||
|
||||
router.route("/walkFolder").get(async (req: Request, res: Response) => {
|
||||
router.route("/walkFolder").post(async (req: Request, res: Response) => {
|
||||
const basePathToWalk =
|
||||
typeof req.query.basePathToWalk === "string"
|
||||
? req.query.basePathToWalk
|
||||
|
||||
@@ -166,21 +166,13 @@ export const unzip = async (
|
||||
};
|
||||
|
||||
export const extractArchive = async (
|
||||
fileObject: IFolderData,
|
||||
extractionOptions: IExtractionOptions,
|
||||
): Promise<
|
||||
| IExtractedComicBookCoverFile
|
||||
| IExtractedComicBookCoverFile[]
|
||||
| IExtractComicBookCoverErrorResponse
|
||||
> => {
|
||||
const sourceFolder = "./comics";
|
||||
const targetExtractionFolder = "covers";
|
||||
const extractionOptions: IExtractionOptions = {
|
||||
folderDetails: fileObject,
|
||||
extractTarget: "cover",
|
||||
sourceFolder,
|
||||
targetExtractionFolder,
|
||||
};
|
||||
switch (fileObject.extension) {
|
||||
switch (extractionOptions.folderDetails.extension) {
|
||||
case ".cbz":
|
||||
return await unzip(extractionOptions);
|
||||
case ".cbr":
|
||||
|
||||
Reference in New Issue
Block a user