⚙️ 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

4509
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -31,7 +31,8 @@
"jest-cli": "^27.2.5",
"moleculer-repl": "^0.6.6",
"ts-jest": "^25.3.0",
"ts-node": "^8.8.1"
"ts-node": "^8.8.1",
"typescript": "^3.9.10"
},
"dependencies": {
"7zip-bin": "^5.1.1",
@@ -64,11 +65,9 @@
"node-calibre": "^2.1.1",
"node-unrar-js": "^1.0.2",
"sharp": "^0.28.1",
"socket.io": "^4.3.2",
"socket.io-stream": "^0.5.3",
"socket.io": "^4.4.0",
"threetwo-ui-typings": "^1.0.11",
"through2": "^4.0.2",
"typescript": "^3.8.3",
"unrar": "^0.2.0",
"xml2js": "^0.4.23"
},

View File

@@ -17,11 +17,8 @@ import {
IExtractedComicBookCoverFile,
IExtractionOptions,
} from "threetwo-ui-typings";
import {
extractCoverFromFile,
extractCoverFromFile2,
unrarArchive,
} from "../utils/uncompression.utils";
import { unrarArchive } from "../utils/uncompression.utils";
import { extractCoverFromFile2 } from "../utils/uncompression.utils";
import { scrapeIssuesFromDOM } from "../utils/scraping.utils";
const ObjectId = require("mongoose").Types.ObjectId;
import fsExtra from "fs-extra";
@@ -120,8 +117,8 @@ export default class ImportService extends Service {
)}`,
});
if (!comicExists) {
// 2. Send the extraction job to the queue
await broker.call(
// 2. Send the extraction job to the queue
await broker.call(
"libraryqueue.enqueue",
{
fileObject: {
@@ -186,9 +183,8 @@ export default class ImportService extends Service {
let comicBookCoverMetadata:
| IExtractedComicBookCoverFile
| IExtractComicBookCoverErrorResponse
| IExtractedComicBookCoverFile[] = await extractCoverFromFile(
| IExtractedComicBookCoverFile[] = await extractCoverFromFile2(
extractionOptions,
walkedFolders
);
// 2. Add to mongo
@@ -454,10 +450,14 @@ export default class ImportService extends Service {
.then((data) => {
console.info(data);
const foo = fsExtra.emptyDirSync(
path.resolve(`${USERDATA_DIRECTORY}/covers`)
path.resolve(
`${USERDATA_DIRECTORY}/covers`
)
);
const foo2 = fsExtra.emptyDirSync(
path.resolve(`${USERDATA_DIRECTORY}/expanded`)
path.resolve(
`${USERDATA_DIRECTORY}/expanded`
)
);
return { data, foo, foo2 };
})

View File

@@ -19,7 +19,6 @@ export default class LibraryQueueService extends Service {
schema: ServiceSchema<{}> = { name: "libraryqueue" }
) {
super(broker);
console.log(this.io);
this.parseServiceSchema(
Service.mergeSchemas(
{

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