🎛 Tweaking interfaces for extraction methods
This commit is contained in:
@@ -2,6 +2,13 @@ export interface IFolderResponse {
|
|||||||
data: Array<IFolderData>;
|
data: Array<IFolderData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IExtractionOptions {
|
||||||
|
folderDetails: IFolderData;
|
||||||
|
extractTarget: string;
|
||||||
|
sourceFolder: string;
|
||||||
|
targetComicCoversFolder: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IComicVineSearchMatch {
|
export interface IComicVineSearchMatch {
|
||||||
description: string;
|
description: string;
|
||||||
id: number;
|
id: number;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { default as unzipper } from "unzipper";
|
import { default as unzipper } from "unzipper";
|
||||||
const etl = require("etl");
|
|
||||||
const sharp = require("sharp");
|
const sharp = require("sharp");
|
||||||
const imgHash = require("imghash");
|
|
||||||
const stream = require("stream");
|
|
||||||
const unrarer = require("node-unrar-js");
|
const unrarer = require("node-unrar-js");
|
||||||
const Walk = require("@root/walk");
|
const Walk = require("@root/walk");
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
@@ -10,15 +7,16 @@ import path from "path";
|
|||||||
import { logger } from "./logger.utils";
|
import { logger } from "./logger.utils";
|
||||||
import {
|
import {
|
||||||
IExtractedComicBookCoverFile,
|
IExtractedComicBookCoverFile,
|
||||||
|
IExtractionOptions,
|
||||||
IFolderData,
|
IFolderData,
|
||||||
} from "../interfaces/folder.interface";
|
} from "../interfaces/folder.interface";
|
||||||
|
|
||||||
export const unrar = async (
|
export const unrar = async (
|
||||||
filePath: string,
|
extractionOptions: IExtractionOptions,
|
||||||
): Promise<IExtractedComicBookCoverFile> => {
|
): Promise<IExtractedComicBookCoverFile> => {
|
||||||
const buf = Uint8Array.from(
|
const buf = Uint8Array.from(
|
||||||
fs.readFileSync(
|
fs.readFileSync(
|
||||||
"./comics/Ghosts and Ruins (2013) (digital) (Mr Norrell-Empire).cbr",
|
extractionOptions.sourceFolder + extractionOptions.folderDetails.name,
|
||||||
),
|
),
|
||||||
).buffer;
|
).buffer;
|
||||||
const extractor = await unrarer.createExtractorFromData({ data: buf });
|
const extractor = await unrarer.createExtractorFromData({ data: buf });
|
||||||
@@ -65,7 +63,7 @@ export const extractMetadataFromImage = async (
|
|||||||
export const unzip = async (
|
export const unzip = async (
|
||||||
filePath: string,
|
filePath: string,
|
||||||
): Promise<IExtractedComicBookCoverFile[]> => {
|
): Promise<IExtractedComicBookCoverFile[]> => {
|
||||||
const foo: IExtractedComicBookCoverFile[] = [];
|
const extractedFiles: IExtractedComicBookCoverFile[] = [];
|
||||||
const zip = fs
|
const zip = fs
|
||||||
.createReadStream(
|
.createReadStream(
|
||||||
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
|
"./comics/Lovecraft - The Myth of Cthulhu (2018) (Maroto) (fylgja).cbz",
|
||||||
@@ -74,7 +72,7 @@ export const unzip = async (
|
|||||||
for await (const entry of zip) {
|
for await (const entry of zip) {
|
||||||
const fileName = entry.path;
|
const fileName = entry.path;
|
||||||
const size = entry.vars.uncompressedSize; // There is also compressedSize;
|
const size = entry.vars.uncompressedSize; // There is also compressedSize;
|
||||||
foo.push({
|
extractedFiles.push({
|
||||||
name: fileName,
|
name: fileName,
|
||||||
fileSize: size,
|
fileSize: size,
|
||||||
path: filePath,
|
path: filePath,
|
||||||
@@ -83,7 +81,7 @@ export const unzip = async (
|
|||||||
entry.autodrain();
|
entry.autodrain();
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve(foo);
|
resolve(extractedFiles);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,12 +106,20 @@ export const unzipOne = async (): Promise<IExtractedComicBookCoverFile> => {
|
|||||||
|
|
||||||
export const extractArchive = async (
|
export const extractArchive = async (
|
||||||
fileObject: IFolderData,
|
fileObject: IFolderData,
|
||||||
): Promise<void> => {
|
): Promise<IExtractedComicBookCoverFile | IExtractedComicBookCoverFile[]> => {
|
||||||
|
const sourceFolder = "./comics/";
|
||||||
|
const targetComicCoversFolder = "covers";
|
||||||
|
const extractionOptions: IExtractionOptions = {
|
||||||
|
...fileObject,
|
||||||
|
extractTarget: "cover",
|
||||||
|
sourceFolder,
|
||||||
|
targetComicCoversFolder,
|
||||||
|
};
|
||||||
switch (fileObject.extension) {
|
switch (fileObject.extension) {
|
||||||
case ".cbz":
|
case ".cbz":
|
||||||
break;
|
return await unzip(extractionOptions);
|
||||||
case ".cbr":
|
case ".cbr":
|
||||||
break;
|
return await unrar(extractionOptions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user