mirror of
https://github.com/YGGverse/btracker.git
synced 2026-04-01 01:25:33 +00:00
replace filesizeformat filter with app implementation
This commit is contained in:
parent
fc8f9dbc3a
commit
ba692f9d2a
6 changed files with 37 additions and 28 deletions
21
src/feed.rs
21
src/feed.rs
|
|
@ -69,8 +69,7 @@ impl Feed {
|
|||
));
|
||||
|
||||
self.buffer.push_str("<description>");
|
||||
self.buffer
|
||||
.push_str(&format!("size: {}", size(torrent.size)));
|
||||
self.buffer.push_str(&format!("size: {}", torrent.size()));
|
||||
if let Some(f) = torrent.files() {
|
||||
self.buffer.push_str(&format!(" / files: {f}"));
|
||||
}
|
||||
|
|
@ -101,21 +100,3 @@ fn escape(value: &str) -> String {
|
|||
.replace('"', """)
|
||||
.replace("'", "'")
|
||||
}
|
||||
|
||||
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