mirror of
https://github.com/YGGverse/btracker.git
synced 2026-04-01 01:25:33 +00:00
implement files list
This commit is contained in:
parent
c84e0ffbdb
commit
fa748fbd18
7 changed files with 133 additions and 76 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue