🚥 Added image file extension validator
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
||||
IFolderData,
|
||||
} from "../interfaces/folder.interface";
|
||||
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[]> => {
|
||||
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 = (
|
||||
extractionOptions: IExtractionOptions,
|
||||
walkedFolder: IFolderData
|
||||
|
||||
@@ -46,7 +46,11 @@ import {
|
||||
} from "threetwo-ui-typings";
|
||||
import { logger } from "./logger.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";
|
||||
const { writeFile, readFile } = require("fs").promises;
|
||||
const unrarer = require("node-unrar-js");
|
||||
@@ -90,6 +94,7 @@ export const unrar = async (
|
||||
if (
|
||||
fileName !== "" &&
|
||||
fileHeader.flags.directory === false &&
|
||||
isValidImageFileExtension(fileName) &&
|
||||
isEmpty(fileNameToExtract)
|
||||
) {
|
||||
logger.info(
|
||||
@@ -211,7 +216,11 @@ export const unzip = async (
|
||||
) {
|
||||
break;
|
||||
}
|
||||
if (fileName !== "" && entry.type !== "Directory") {
|
||||
if (
|
||||
fileName !== "" &&
|
||||
entry.type !== "Directory" &&
|
||||
isValidImageFileExtension(fileName)
|
||||
) {
|
||||
logger.info(`Attempting to write ${fileName}`);
|
||||
entry
|
||||
.pipe(createWriteStream(paths.targetPath + "/" + fileName))
|
||||
|
||||
Reference in New Issue
Block a user