🛠 Refactored unrar functions
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: "Gyo v02 (2004) (Digital) (LostNerevarine-Empire)",
|
name: "Fatale 004 (2012) (Digital) (Zone-Empire)",
|
||||||
extension: ".cbz",
|
extension: ".cbr",
|
||||||
containedIn: "comics/ITOU Junji - Gyo",
|
containedIn: "comics",
|
||||||
isFile: true,
|
isFile: true,
|
||||||
isLink: false,
|
isLink: false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
IExtractionOptions,
|
IExtractionOptions,
|
||||||
IFolderData,
|
IFolderData,
|
||||||
} from "../interfaces/folder.interface";
|
} from "../interfaces/folder.interface";
|
||||||
import { WriteStream } from "node:fs";
|
|
||||||
|
|
||||||
export const unrar = async (
|
export const unrar = async (
|
||||||
extractionOptions: IExtractionOptions,
|
extractionOptions: IExtractionOptions,
|
||||||
@@ -25,19 +24,25 @@ export const unrar = async (
|
|||||||
| IExtractedComicBookCoverFile[]
|
| IExtractedComicBookCoverFile[]
|
||||||
| IExtractComicBookCoverErrorResponse
|
| IExtractComicBookCoverErrorResponse
|
||||||
> => {
|
> => {
|
||||||
const extractionTargetPath =
|
const targetPath =
|
||||||
extractionOptions.sourceFolder + extractionOptions.targetExtractionFolder;
|
extractionOptions.sourceFolder +
|
||||||
|
"/" +
|
||||||
|
extractionOptions.targetExtractionFolder +
|
||||||
|
"/" +
|
||||||
|
extractionOptions.folderDetails.name;
|
||||||
|
|
||||||
|
const inputFilePath =
|
||||||
|
extractionOptions.folderDetails.containedIn +
|
||||||
|
"/" +
|
||||||
|
extractionOptions.folderDetails.name +
|
||||||
|
extractionOptions.folderDetails.extension;
|
||||||
|
|
||||||
const directoryOptions = {
|
const directoryOptions = {
|
||||||
mode: 0o2775,
|
mode: 0o2775,
|
||||||
};
|
};
|
||||||
const fileBuffer = await readFile(
|
const fileBuffer = await readFile(inputFilePath).catch((err) =>
|
||||||
extractionOptions.folderDetails.containedIn +
|
console.error("Failed to read file", err),
|
||||||
"/" +
|
);
|
||||||
extractionOptions.folderDetails.name,
|
|
||||||
).catch((err) => console.error("Failed to read file", err));
|
|
||||||
|
|
||||||
const targetPath =
|
|
||||||
extractionTargetPath + "/" + extractionOptions.folderDetails.name;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fse.ensureDir(targetPath, directoryOptions);
|
await fse.ensureDir(targetPath, directoryOptions);
|
||||||
@@ -61,7 +66,10 @@ export const unrar = async (
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const fileName = explodePath(extractedFile.fileHeader.name).fileName;
|
const fileName = explodePath(extractedFile.fileHeader.name).fileName;
|
||||||
if (fileName !== "") {
|
if (
|
||||||
|
fileName !== "" &&
|
||||||
|
extractedFile.fileHeader.flags.directory === false
|
||||||
|
) {
|
||||||
await writeFile(targetPath + "/" + fileName, fileArrayBuffer);
|
await writeFile(targetPath + "/" + fileName, fileArrayBuffer);
|
||||||
}
|
}
|
||||||
resolve({
|
resolve({
|
||||||
@@ -85,7 +93,7 @@ export const unrar = async (
|
|||||||
const fileBuffer = file.extraction;
|
const fileBuffer = file.extraction;
|
||||||
const fileName = explodePath(file.fileHeader.name).fileName;
|
const fileName = explodePath(file.fileHeader.name).fileName;
|
||||||
try {
|
try {
|
||||||
if (fileName !== "") {
|
if (fileName !== "" && file.fileHeader.flags.directory === false) {
|
||||||
await writeFile(targetPath + "/" + fileName, fileBuffer);
|
await writeFile(targetPath + "/" + fileName, fileBuffer);
|
||||||
}
|
}
|
||||||
comicBookCoverFiles.push({
|
comicBookCoverFiles.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user