web: human format attachment size

This commit is contained in:
2024-04-06 08:52:20 -07:00
parent 1f5f10f78d
commit dc7b3dd3e8
2 changed files with 12 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ use std::{
};
use chrono::{DateTime, Datelike, Duration, Local, Utc};
use human_format::{Formatter, Scales};
use itertools::Itertools;
use log::error;
use seed::{prelude::*, *};
@@ -641,18 +642,18 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
) => pre![C!["error"], contents],
ShowThreadQueryThreadMessagesBody::PlainText(
ShowThreadQueryThreadMessagesBodyOnPlainText {
contents,
content_tree,
},
contents,
content_tree,
},
) => div![
raw_text_message(&contents),
view_content_tree(&content_tree),
],
ShowThreadQueryThreadMessagesBody::Html(
ShowThreadQueryThreadMessagesBodyOnHtml {
contents,
content_tree,
},
contents,
content_tree,
},
) => div![
C!["view-part-text-html"],
raw![contents],
@@ -669,6 +670,9 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
let filename = a.filename.as_ref().unwrap_or(&default);
let host = seed::window().location().host().expect("couldn't get host");
let url = format!("//{host}/download/attachment/{}/{}/{}", a.id,a.idx, filename);
let mut fmtr = Formatter::new();
fmtr.with_separator(" ");
fmtr.with_scales(Scales::Binary());
div![
C!["attachment", "card"],
@@ -688,7 +692,7 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
div![C!["card-content"],
div![C!["content"],
&a.filename, br![],
small![&a.size, " bytes"]
small![ fmtr.format(a.size as f64),"B"]
]
],
footer![