use chrono::Local;
use crate::model::File;
use crate::util;
const PAGE: &str = r#"
Files
Files
"#;
pub const INDEX: &str = const_format::concatcp!(
PAGE,
r#"
"#
);
pub const NOT_FOUND: &str = const_format::concatcp!(
PAGE,
r#"
Oops, not found.
"#
);
pub const BAD_REQUEST: &str = const_format::concatcp!(
PAGE,
r#"
Oops, bad request.
"#
);
pub const INTERNAL_SERVER_ERROR: &str = const_format::concatcp!(
PAGE,
r#"
Oops, internal server error.
"#
);
pub fn file_page(file: File) -> String {
let href = format!("/share/{}/download", file.id);
let expiration = file.expires_at.signed_duration_since(Local::now());
format!(
r#"
{page}
"#,
page = PAGE,
href = html_escape::encode_text(&href),
filename = html_escape::encode_text(&file.name),
expiration = html_escape::encode_text(&util::pretty_print_duration(expiration)),
size = html_escape::encode_text(&util::pretty_print_bytes(file.content_length))
)
}