🤞🏽Used a promisified file exists function
This commit is contained in:
@@ -67,6 +67,15 @@ export const explodePath = (filePath: string): IExplodedPathResponse => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// returns a promise which resolves true if file exists:
|
||||||
|
export const checkFileExists = (filepath) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fs.access(filepath, fs.constants.F_OK, error => {
|
||||||
|
resolve(!error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export const getSizeOfDirectory = async (
|
export const getSizeOfDirectory = async (
|
||||||
directoryPath: string,
|
directoryPath: string,
|
||||||
extensions: string[]
|
extensions: string[]
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import path, { parse } from "path";
|
|||||||
import * as p7zip from "p7zip-threetwo";
|
import * as p7zip from "p7zip-threetwo";
|
||||||
import { IExtractedComicBookCoverFile } from "threetwo-ui-typings";
|
import { IExtractedComicBookCoverFile } from "threetwo-ui-typings";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { getFileConstituents } from "../utils/file.utils";
|
import { getFileConstituents, checkFileExists } from "../utils/file.utils";
|
||||||
import { flatten, isEmpty, isNil, isUndefined, remove } from "lodash";
|
import { flatten, isEmpty, isNil, isUndefined, remove } from "lodash";
|
||||||
import { convertXMLToJSON } from "./xml.utils";
|
import { convertXMLToJSON } from "./xml.utils";
|
||||||
import { USERDATA_DIRECTORY, COMICS_DIRECTORY } from "../constants/directories";
|
import { USERDATA_DIRECTORY, COMICS_DIRECTORY } from "../constants/directories";
|
||||||
@@ -153,7 +153,8 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
if (existsSync(`${targetDirectory}/${coverFile}`)) {
|
checkFileExists(`${targetDirectory}/${coverFile}`).then((bool) => {
|
||||||
|
console.log(`${coverFile} exists: ${bool}`);
|
||||||
// orchestrate result
|
// orchestrate result
|
||||||
resolve({
|
resolve({
|
||||||
filePath,
|
filePath,
|
||||||
@@ -167,7 +168,7 @@ export const extractComicInfoXMLFromRar = async (
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user