mirror of
https://github.com/YGGverse/btracker.git
synced 2026-04-01 01:25:33 +00:00
use build-in tera filters
This commit is contained in:
parent
c1ae25f04b
commit
d95cee6c09
7 changed files with 51 additions and 53 deletions
|
|
@ -71,16 +71,8 @@ impl Torrent {
|
|||
|
||||
// Format getters
|
||||
|
||||
pub fn files(&self) -> String {
|
||||
use plurify::Plurify;
|
||||
self.files.as_ref().map_or("1 file".into(), |f| {
|
||||
let l = f.len();
|
||||
format!("{l} {}", l.plurify(&["file", "files", "files"]))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn size(&self) -> String {
|
||||
size(self.size)
|
||||
pub fn files(&self) -> Option<usize> {
|
||||
self.files.as_ref().map(|f| f.len())
|
||||
}
|
||||
|
||||
pub fn magnet(&self, trackers: Option<&Vec<url::Url>>) -> String {
|
||||
|
|
@ -98,21 +90,3 @@ 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