🚶🏽 Refactored the walk function
This commit is contained in:
@@ -255,29 +255,37 @@ export const getCovers = async (
|
|||||||
|
|
||||||
export const walkFolder = async (folder: string): Promise<IFolderData[]> => {
|
export const walkFolder = async (folder: string): Promise<IFolderData[]> => {
|
||||||
const result: IFolderData[] = [];
|
const result: IFolderData[] = [];
|
||||||
await Walk.walk(folder, async (err, pathname, dirent) => {
|
let walkResult: IFolderData = {
|
||||||
|
name: "",
|
||||||
|
extension: "",
|
||||||
|
containedIn: "",
|
||||||
|
isFile: false,
|
||||||
|
isLink: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const walk = Walk.create({ sort: filterOutDotFiles });
|
||||||
|
await walk(folder, async (err, pathname, dirent) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error("Failed to lstat directory", { error: err });
|
logger.error("Failed to lstat directory", { error: err });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const walkResult = {
|
if ([".cbz", ".cbr"].includes(path.extname(dirent.name))) {
|
||||||
name: path.basename(dirent.name, path.extname(dirent.name)),
|
walkResult = {
|
||||||
extension: path.extname(dirent.name),
|
name: path.basename(dirent.name, path.extname(dirent.name)),
|
||||||
containedIn: path.dirname(pathname),
|
extension: path.extname(dirent.name),
|
||||||
isFile: dirent.isFile(),
|
containedIn: path.dirname(pathname),
|
||||||
isLink: dirent.isSymbolicLink(),
|
isFile: dirent.isFile(),
|
||||||
};
|
isLink: dirent.isSymbolicLink(),
|
||||||
logger.info(
|
};
|
||||||
`Scanned ${dirent.name} contained in ${path.dirname(pathname)}`,
|
logger.info(
|
||||||
);
|
`Scanned ${dirent.name} contained in ${path.dirname(pathname)}`,
|
||||||
result.push(walkResult);
|
);
|
||||||
|
result.push(walkResult);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const filterNonComicBookExtensions = (entities) => {
|
|
||||||
return entities.filter((entity) => entity.extname)
|
|
||||||
}
|
|
||||||
export const explodePath = (filePath: string): IExplodedPathResponse => {
|
export const explodePath = (filePath: string): IExplodedPathResponse => {
|
||||||
const exploded = filePath.split("/");
|
const exploded = filePath.split("/");
|
||||||
const fileName = remove(exploded, (item) => {
|
const fileName = remove(exploded, (item) => {
|
||||||
@@ -315,3 +323,7 @@ export const extractMetadataFromImage = async (
|
|||||||
});
|
});
|
||||||
return image;
|
return image;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filterOutDotFiles = (entities) => {
|
||||||
|
return entities.filter((ent) => !ent.name.startsWith("."));
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user