🔢 Fix for disk size consumed by comics

This commit is contained in:
2026-03-09 21:32:41 -04:00
parent c9f323e610
commit 7f86497cfc
2 changed files with 13 additions and 8 deletions

View File

@@ -191,6 +191,7 @@ export const typeDefs = gql`
type ImportStatus { type ImportStatus {
isImported: Boolean isImported: Boolean
tagged: Boolean tagged: Boolean
isRawFileMissing: Boolean
matchedResult: MatchedResult matchedResult: MatchedResult
} }

View File

@@ -4,7 +4,7 @@ const fse = require("fs-extra");
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import { FileMagic, MagicFlags } from "@npcz/magic"; import { FileMagic, MagicFlags } from "@npcz/magic";
const { readdir, stat } = require("fs/promises"); const { stat } = require("fs/promises");
import { import {
IExplodedPathResponse, IExplodedPathResponse,
IExtractComicBookCoverErrorResponse, IExtractComicBookCoverErrorResponse,
@@ -95,19 +95,23 @@ export const getSizeOfDirectory = async (
directoryPath: string, directoryPath: string,
extensions: string[] extensions: string[]
) => { ) => {
const files = await readdir(directoryPath); let totalSizeInBytes = 0;
const stats = files.map((file) => stat(path.join(directoryPath, file))); let fileCount = 0;
const totalSizeInBytes = (await Promise.all(stats)).reduce( await Walk.walk(directoryPath, async (err, pathname, dirent) => {
(accumulator, { size }) => accumulator + size, if (err) return false;
0 if (dirent.isFile() && extensions.includes(path.extname(dirent.name))) {
); const fileStat = await stat(pathname);
totalSizeInBytes += fileStat.size;
fileCount++;
}
});
return { return {
totalSize: totalSizeInBytes, totalSize: totalSizeInBytes,
totalSizeInMB: totalSizeInBytes / (1024 * 1024), totalSizeInMB: totalSizeInBytes / (1024 * 1024),
totalSizeInGB: totalSizeInBytes / (1024 * 1024 * 1024), totalSizeInGB: totalSizeInBytes / (1024 * 1024 * 1024),
fileCount: files.length, fileCount,
}; };
}; };