🚥 Added image file extension validator
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
|||||||
IFolderData,
|
IFolderData,
|
||||||
} from "../interfaces/folder.interface";
|
} from "../interfaces/folder.interface";
|
||||||
import { logger } from "./logger.utils";
|
import { logger } from "./logger.utils";
|
||||||
import { each, isEmpty, map, remove, indexOf } from "lodash";
|
import { includes, remove, indexOf } from "lodash";
|
||||||
|
|
||||||
|
const ALLOWED_IMAGE_FILE_FORMATS = [".jpg", ".jpeg", ".png"];
|
||||||
|
|
||||||
export const walkFolder = async (folder: string): Promise<IFolderData[]> => {
|
export const walkFolder = async (folder: string): Promise<IFolderData[]> => {
|
||||||
const result: IFolderData[] = [];
|
const result: IFolderData[] = [];
|
||||||
@@ -57,6 +59,10 @@ export const explodePath = (filePath: string): IExplodedPathResponse => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isValidImageFileExtension = (fileName: string): boolean => {
|
||||||
|
return includes(ALLOWED_IMAGE_FILE_FORMATS, path.extname(fileName));
|
||||||
|
};
|
||||||
|
|
||||||
export const constructPaths = (
|
export const constructPaths = (
|
||||||
extractionOptions: IExtractionOptions,
|
extractionOptions: IExtractionOptions,
|
||||||
walkedFolder: IFolderData
|
walkedFolder: IFolderData
|
||||||
|
|||||||
@@ -46,7 +46,11 @@ import {
|
|||||||
} from "threetwo-ui-typings";
|
} from "threetwo-ui-typings";
|
||||||
import { logger } from "./logger.utils";
|
import { logger } from "./logger.utils";
|
||||||
import { validateComicBookMetadata } from "../utils/validation.utils";
|
import { validateComicBookMetadata } from "../utils/validation.utils";
|
||||||
import { constructPaths, explodePath } from "../utils/file.utils";
|
import {
|
||||||
|
constructPaths,
|
||||||
|
explodePath,
|
||||||
|
isValidImageFileExtension,
|
||||||
|
} from "../utils/file.utils";
|
||||||
import { resizeImage } from "./imagetransformation.utils";
|
import { resizeImage } from "./imagetransformation.utils";
|
||||||
const { writeFile, readFile } = require("fs").promises;
|
const { writeFile, readFile } = require("fs").promises;
|
||||||
const unrarer = require("node-unrar-js");
|
const unrarer = require("node-unrar-js");
|
||||||
@@ -90,6 +94,7 @@ export const unrar = async (
|
|||||||
if (
|
if (
|
||||||
fileName !== "" &&
|
fileName !== "" &&
|
||||||
fileHeader.flags.directory === false &&
|
fileHeader.flags.directory === false &&
|
||||||
|
isValidImageFileExtension(fileName) &&
|
||||||
isEmpty(fileNameToExtract)
|
isEmpty(fileNameToExtract)
|
||||||
) {
|
) {
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -211,7 +216,11 @@ export const unzip = async (
|
|||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fileName !== "" && entry.type !== "Directory") {
|
if (
|
||||||
|
fileName !== "" &&
|
||||||
|
entry.type !== "Directory" &&
|
||||||
|
isValidImageFileExtension(fileName)
|
||||||
|
) {
|
||||||
logger.info(`Attempting to write ${fileName}`);
|
logger.info(`Attempting to write ${fileName}`);
|
||||||
entry
|
entry
|
||||||
.pipe(createWriteStream(paths.targetPath + "/" + fileName))
|
.pipe(createWriteStream(paths.targetPath + "/" + fileName))
|
||||||
|
|||||||
Reference in New Issue
Block a user