From 1019ea1ed341e3a7769c046aa0be5764789360b6 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 2 Jun 2024 14:38:13 +0200 Subject: Migrate to Rust and Hyper With sanic, downloading a file locally is around ten times slower than with Rust and hyper. Maybe `pypy` could have helped, but I didn’t succeed to set it up quickly with the dependencies. --- src/templates.rs | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/templates.rs (limited to 'src/templates.rs') diff --git a/src/templates.rs b/src/templates.rs new file mode 100644 index 0000000..b551bf6 --- /dev/null +++ b/src/templates.rs @@ -0,0 +1,134 @@ +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#" +
+ + + + + + +
+
+ Uploading… +
+ +
+
+ + +
"# +); + +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!("{}/download", file.id); + let expiration = file.expires_at.signed_duration_since(Local::now()); + + format!( + r#" + {page} + +
+
+ {filename} – {size} +
+
+ Expires in {expiration}. +
+
+ "#, + 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)) + ) +} -- cgit v1.2.3