🦝 Fixed code smell
This commit is contained in:
@@ -11,9 +11,9 @@ import { Request, Response } from "express";
|
|||||||
|
|
||||||
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
||||||
const options = {
|
const options = {
|
||||||
name: "Beautiful Darkness (2014) (scan) (Anonymous) (resized)",
|
name: "Gyo v02 (2004) (Digital) (LostNerevarine-Empire)",
|
||||||
extension: ".cbz",
|
extension: ".cbz",
|
||||||
containedIn: "comics",
|
containedIn: "comics/ITOU Junji - Gyo",
|
||||||
isFile: true,
|
isFile: true,
|
||||||
isLink: false,
|
isLink: false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -151,61 +151,34 @@ export const unzip = async (
|
|||||||
logger.error(`${error} Couldn't create directory.`);
|
logger.error(`${error} Couldn't create directory.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (extractionOptions.extractTarget) {
|
const extractedFiles: IExtractedComicBookCoverFile[] = [];
|
||||||
case "all":
|
const zip = createReadStream(inputFilePath).pipe(
|
||||||
const extractedFiles: IExtractedComicBookCoverFile[] = [];
|
unzipper.Parse({ forceStream: true }),
|
||||||
const zip = createReadStream(inputFilePath).pipe(
|
);
|
||||||
unzipper.Parse({ forceStream: true }),
|
for await (const entry of zip) {
|
||||||
);
|
const fileName = explodePath(entry.path).fileName;
|
||||||
for await (const entry of zip) {
|
const size = entry.vars.uncompressedSize;
|
||||||
const fileName = explodePath(entry.path).fileName;
|
if (
|
||||||
const size = entry.vars.uncompressedSize;
|
extractedFiles.length === 1 &&
|
||||||
entry.pipe(createWriteStream(targetPath + "/" + fileName));
|
extractionOptions.extractTarget === "cover"
|
||||||
if (fileName !== "" && entry.type !== "Directory") {
|
) {
|
||||||
extractedFiles.push({
|
break;
|
||||||
name: fileName,
|
}
|
||||||
fileSize: size,
|
if (fileName !== "" && entry.type !== "Directory") {
|
||||||
path: targetPath,
|
entry.pipe(createWriteStream(targetPath + "/" + fileName));
|
||||||
});
|
extractedFiles.push({
|
||||||
}
|
name: fileName,
|
||||||
entry.autodrain();
|
fileSize: size,
|
||||||
}
|
path: targetPath,
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
logger.info("");
|
|
||||||
resolve(extractedFiles);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
case "cover":
|
entry.autodrain();
|
||||||
const extractedFile: IExtractedComicBookCoverFile[] = [];
|
|
||||||
const singleZip = createReadStream(inputFilePath).pipe(
|
|
||||||
unzipper.Parse({ forceStream: true }),
|
|
||||||
);
|
|
||||||
for await (const item of singleZip) {
|
|
||||||
const writeableFileName = explodePath(item.path).fileName;
|
|
||||||
if (extractedFile.length === 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (writeableFileName !== "" && item.type !== "Directory") {
|
|
||||||
item.pipe(createWriteStream(targetPath + "/" + writeableFileName));
|
|
||||||
extractedFile.push({
|
|
||||||
name: writeableFileName,
|
|
||||||
fileSize: item.size,
|
|
||||||
path: targetPath,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
resolve(extractedFile[0]);
|
|
||||||
});
|
|
||||||
|
|
||||||
default:
|
|
||||||
return {
|
|
||||||
message: "File format not supported, yet.",
|
|
||||||
errorCode: "90",
|
|
||||||
data: "asda",
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
logger.info("");
|
||||||
|
resolve(extractedFiles);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractArchive = async (
|
export const extractArchive = async (
|
||||||
@@ -216,10 +189,10 @@ export const extractArchive = async (
|
|||||||
| IExtractComicBookCoverErrorResponse
|
| IExtractComicBookCoverErrorResponse
|
||||||
> => {
|
> => {
|
||||||
const sourceFolder = "./comics";
|
const sourceFolder = "./comics";
|
||||||
const targetExtractionFolder = "covers";
|
const targetExtractionFolder = "expanded";
|
||||||
const extractionOptions: IExtractionOptions = {
|
const extractionOptions: IExtractionOptions = {
|
||||||
folderDetails: fileObject,
|
folderDetails: fileObject,
|
||||||
extractTarget: "cover",
|
extractTarget: "all",
|
||||||
sourceFolder,
|
sourceFolder,
|
||||||
targetExtractionFolder,
|
targetExtractionFolder,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user