chore: watch api

This commit is contained in:
jialin
2024-06-28 17:14:34 +08:00
parent 871bca1916
commit cf0113e8d8
35 changed files with 1171 additions and 627 deletions
+7 -6
View File
@@ -19,20 +19,21 @@ export const handleBatchRequest = async (
return Promise.all(list.map((item) => fn(item)));
};
export const convertFileSize = (sizeInBytes: number) => {
export const convertFileSize = (sizeInBytes: number, prec?: number) => {
const precision = prec ?? 2;
if (!sizeInBytes) {
return '0 B';
}
if (sizeInBytes < 1024) {
return `${sizeInBytes.toFixed(2)} B`;
return `${sizeInBytes.toFixed(precision)} B`;
} else if (sizeInBytes < 1024 * 1024) {
return `${(sizeInBytes / 1024).toFixed(2)} KB`;
return `${(sizeInBytes / 1024).toFixed(precision)} KiB`;
} else if (sizeInBytes < 1024 * 1024 * 1024) {
return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
return `${(sizeInBytes / (1024 * 1024)).toFixed(precision)} MiB`;
} else if (sizeInBytes < 1024 * 1024 * 1024 * 1024) {
return `${(sizeInBytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
return `${(sizeInBytes / (1024 * 1024 * 1024)).toFixed(precision)} GiB`;
} else {
return `${(sizeInBytes / (1024 * 1024 * 1024 * 1024)).toFixed(2)} TB`;
return `${(sizeInBytes / (1024 * 1024 * 1024 * 1024)).toFixed(precision)} TiB`;
}
};