添加下载功能

This commit is contained in:
柚子
2025-03-04 04:10:19 +08:00
parent 2e963b65e2
commit aadc137055
10 changed files with 682 additions and 241 deletions

View File

@@ -0,0 +1,21 @@
// 格式化文件大小
pub fn format_size(size: u64) -> String {
const KB: u64 = 1024;
const MB: u64 = KB * 1024;
const GB: u64 = MB * 1024;
if size >= GB {
format!("{:.2} GB", size as f64 / GB as f64)
} else if size >= MB {
format!("{:.2} MB", size as f64 / MB as f64)
} else if size >= KB {
format!("{:.2} KB", size as f64 / KB as f64)
} else {
format!("{} B", size)
}
}
// 格式化下载速度
pub fn format_speed(speed: u64) -> String {
format!("{}/s", format_size(speed))
}