replace filesizeformat filter with app implementation

This commit is contained in:
yggverse 2025-09-11 17:47:42 +03:00
parent fc8f9dbc3a
commit ba692f9d2a
6 changed files with 37 additions and 28 deletions

View file

@ -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('"', "&quot;")
.replace("'", "&apos;")
}
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)
}
}