feat: added download status
This commit is contained in:
1 parent
cd3fabc0d8
commit
82c14c1d5c
17 files changed
+189
-88
No files matched your search
@@ -21,3 +21,24 @@ export const createUniqueRandomGenerator = (max: number) => {
|
||||
return numbers[index++];
|
||||
};
|
||||
};
|
||||
|
||||
export const getMagnetHash = (link: string) => {
|
||||
const [, hash] = link.match(/btih:([A-Fa-f0-9]{40}|[A-Za-z0-9]{32})/) || [];
|
||||
return hash?.toUpperCase();
|
||||
};
|
||||
|
||||
export const formatBytes = (bytes?: number) => {
|
||||
if (bytes == null || !isFinite(bytes)) return '';
|
||||
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB'] as const;
|
||||
|
||||
let i = 0;
|
||||
let v = bytes;
|
||||
|
||||
while (v >= 1024 && i < units.length - 1) {
|
||||
v /= 1024;
|
||||
i++;
|
||||
}
|
||||
|
||||
return `${v.toFixed(v < 10 && i > 0 ? 1 : 0)} ${units[i]}`;
|
||||
};
|
||||
Reference in new issue
Block a user