implement files list

This commit is contained in:
yggverse 2025-08-09 18:37:50 +03:00
parent c84e0ffbdb
commit fa748fbd18
7 changed files with 133 additions and 76 deletions

View file

@ -88,21 +88,7 @@ impl Torrent {
}
pub fn size(&self) -> String {
const KB: f32 = 1024.0;
const MB: f32 = KB * KB;
const GB: f32 = MB * KB;
let f = self.size as f32;
if f < KB {
format!("{} B", self.size)
} else if f < MB {
format!("{:.2} KB", f / KB)
} else if f < GB {
format!("{:.2} MB", f / MB)
} else {
format!("{:.2} GB", f / GB)
}
size(self.size)
}
pub fn magnet(&self, trackers: Option<&Vec<url::Url>>) -> String {
@ -120,3 +106,21 @@ impl Torrent {
b
}
}
fn size(value: u64) -> String {
const KB: f32 = 1024.0;
const MB: f32 = KB * KB;
const GB: f32 = MB * KB;
let f = value as f32;
if f < KB {
format!("{value} B")
} else if f < MB {
format!("{:.2} KB", f / KB)
} else if f < GB {
format!("{:.2} MB", f / MB)
} else {
format!("{:.2} GB", f / GB)
}
}