mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
⚰️ 删除无用代码
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* @file utils toolFunc.ts
|
* @file utils toolFunc.ts
|
||||||
* @description 一些工具函数
|
* @description 一些工具函数
|
||||||
* @since Beta v0.3.4
|
* @since Beta v0.3.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fs, os, path } from "@tauri-apps/api";
|
import { os, path } from "@tauri-apps/api";
|
||||||
import type { FileEntry } from "@tauri-apps/api/fs";
|
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,33 +67,6 @@ export function bytesToSize(bytes: number): string {
|
|||||||
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
|
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 获取文件夹大小
|
|
||||||
* @since Beta v0.3.4
|
|
||||||
* @param {FileEntry[]} cacheInfo - 文件夹信息
|
|
||||||
* @param {boolean} isRoot - 是否是根目录
|
|
||||||
* @returns {Promise<number>} 文件夹大小
|
|
||||||
*/
|
|
||||||
export async function getDirSize(cacheInfo: FileEntry[], isRoot: false): Promise<number>;
|
|
||||||
export async function getDirSize(cacheInfo: FileEntry[], isRoot?: true): Promise<string>;
|
|
||||||
export async function getDirSize(
|
|
||||||
cacheInfo: FileEntry[],
|
|
||||||
isRoot?: boolean,
|
|
||||||
): Promise<number | string> {
|
|
||||||
let size = 0;
|
|
||||||
for (const item of cacheInfo) {
|
|
||||||
if (item.children) {
|
|
||||||
const dir = await fs.readDir(item.path);
|
|
||||||
size += await getDirSize(dir, false);
|
|
||||||
} else {
|
|
||||||
const file = await fs.readBinaryFile(item.path);
|
|
||||||
size += file.byteLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isRoot === undefined || isRoot) return bytesToSize(size);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 获取缓存目录
|
* @description 获取缓存目录
|
||||||
* @since Beta v0.3.4
|
* @since Beta v0.3.4
|
||||||
|
|||||||
Reference in New Issue
Block a user