mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: implement directory size check and seed abort
This commit is contained in:
parent
bd184fceda
commit
abb3db4e30
2 changed files with 53 additions and 11 deletions
|
@ -1,3 +1,6 @@
|
|||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
export const calculateETA = (
|
||||
totalLength: number,
|
||||
completedLength: number,
|
||||
|
@ -11,3 +14,26 @@ export const calculateETA = (
|
|||
|
||||
return -1;
|
||||
};
|
||||
|
||||
export const getDirSize = async (dir: string): Promise<number> => {
|
||||
const getItemSize = async (filePath: string): Promise<number> => {
|
||||
const stat = await fs.promises.stat(filePath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
return getDirSize(filePath);
|
||||
}
|
||||
|
||||
return stat.size;
|
||||
};
|
||||
|
||||
try {
|
||||
const files = await fs.promises.readdir(dir);
|
||||
const filePaths = files.map((file) => path.join(dir, file));
|
||||
const sizes = await Promise.all(filePaths.map(getItemSize));
|
||||
|
||||
return sizes.reduce((total, size) => total + size, 0);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue