👷🏽 Workerizing the import algorithm

This commit is contained in:
2021-04-23 13:18:18 -07:00
parent ecc05b09de
commit a1418c55c4
3 changed files with 9 additions and 17 deletions

View File

@@ -1,10 +1,8 @@
import * as Comlink from "comlink"; 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) { async function importComicBooks() {
return a + b;
}
function importComicBooks() {
// 1. Walk the folder structure // 1. Walk the folder structure
// 2. Scan for .cbz, .cbr // 2. Scan for .cbz, .cbr
// 3. extract cover image // 3. extract cover image
@@ -12,10 +10,12 @@ function importComicBooks() {
// 5. Get metadata, add to data model // 5. Get metadata, add to data model
// 5. Save cover to disk // 5. Save cover to disk
// 6. Save model to mongo // 6. Save model to mongo
const fileObjects = await walkFolder("./comics");
} }
Comlink.expose({ Comlink.expose({
add, importComicBooks,
}); });
export default null as any; export default null as any;

View File

@@ -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 = const basePathToWalk =
typeof req.query.basePathToWalk === "string" typeof req.query.basePathToWalk === "string"
? req.query.basePathToWalk ? req.query.basePathToWalk

View File

@@ -166,21 +166,13 @@ export const unzip = async (
}; };
export const extractArchive = async ( export const extractArchive = async (
fileObject: IFolderData, extractionOptions: IExtractionOptions,
): Promise< ): Promise<
| IExtractedComicBookCoverFile | IExtractedComicBookCoverFile
| IExtractedComicBookCoverFile[] | IExtractedComicBookCoverFile[]
| IExtractComicBookCoverErrorResponse | IExtractComicBookCoverErrorResponse
> => { > => {
const sourceFolder = "./comics"; switch (extractionOptions.folderDetails.extension) {
const targetExtractionFolder = "covers";
const extractionOptions: IExtractionOptions = {
folderDetails: fileObject,
extractTarget: "cover",
sourceFolder,
targetExtractionFolder,
};
switch (fileObject.extension) {
case ".cbz": case ".cbz":
return await unzip(extractionOptions); return await unzip(extractionOptions);
case ".cbr": case ".cbr":