⚙️ Fixed the uncompression method to use container-local comics and userdata directories

This commit is contained in:
2021-12-01 20:35:23 -08:00
parent e4bdfbdba1
commit fdd6538a96
5 changed files with 1616 additions and 3003 deletions

View File

@@ -50,86 +50,6 @@ const unrar = require("node-unrar-js");
const { Calibre } = require("node-calibre");
import { USERDATA_DIRECTORY, COMICS_DIRECTORY } from "../constants/directories";
export const extractCoverFromFile = async (
extractionOptions: IExtractionOptions,
walkedFolder: IFolderData
): Promise<
| IExtractedComicBookCoverFile
| IExtractedComicBookCoverFile[]
| IExtractComicBookCoverErrorResponse
> => {
return new Promise(async (resolve, reject) => {
try {
const constructedPaths = constructPaths(
extractionOptions,
walkedFolder
);
const calibre = new Calibre();
// create directory
const directoryOptions = {
mode: 0o2775,
};
try {
await fse.ensureDir(
constructedPaths.targetPath,
directoryOptions
);
console.info(`${constructedPaths.targetPath} was created.`);
} catch (error) {
console.error(`${error}: Couldn't create directory.`);
}
// extract the cover
let result: string;
const targetCoverImageFilePath = path.resolve(
constructedPaths.targetPath +
"/" +
walkedFolder.name +
"_cover.jpg"
);
const ebookMetaPath = process.env.CALIBRE_EBOOK_META_PATH
? `${process.env.CALIBRE_EBOOK_META_PATH}`
: `ebook-meta`;
result = await calibre.run(
ebookMetaPath,
[constructedPaths.inputFilePath],
{
getCover: targetCoverImageFilePath,
}
);
// create renditions
const renditionPath =
constructedPaths.targetPath +
"/" +
walkedFolder.name +
"_200px.jpg";
const stats: ISharpResizedImageStats = await resizeImage(
targetCoverImageFilePath,
path.resolve(renditionPath),
200
);
resolve({
name: walkedFolder.name,
path: renditionPath,
fileSize: walkedFolder.fileSize,
extension: path.extname(constructedPaths.inputFilePath),
cover: {
filePath: renditionPath,
},
containedIn: walkedFolder.containedIn,
calibreMetadata: {
coverWriteResult: result,
},
});
} catch (error) {
console.info(error);
}
});
};
export const extractCoverFromFile2 = async (
fileObject: any