diff options
Diffstat (limited to 'src/templates.rs')
-rw-r--r-- | src/templates.rs | 134 |
1 files changed, 134 insertions, 0 deletions
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#" +<!doctype html> +<html lang="fr"> +<meta charset="utf-8"> +<meta name="viewport" content="width=device-width"> + +<title>Files</title> +<link rel="stylesheet" href="/static/main.css"> +<script src="/static/main.js"></script> + +<a href="/"> + <h1>Files</h1> +</a> +"#; + +pub const INDEX: &str = const_format::concatcp!( + PAGE, + r#" +<form> + <label> + File + <input type="file" name="file" required> + </label> + + <label> + Expiration + <select name="expiration"> + <option value="1">1 day</option> + <option value="2">2 days</option> + <option value="3">3 days</option> + <option value="4">4 days</option> + <option value="5">5 days</option> + <option value="6">6 days</option> + <option value="7" selected>7 days</option> + <option value="8">8 days</option> + <option value="9">9 days</option> + <option value="10">10 days</option> + <option value="11">11 days</option> + <option value="12">12 days</option> + <option value="13">13 days</option> + <option value="14">14 days</option> + <option value="15">15 days</option> + <option value="16">16 days</option> + <option value="17">17 days</option> + <option value="18">18 days</option> + <option value="19">19 days</option> + <option value="20">20 days</option> + <option value="21">21 days</option> + <option value="22">22 days</option> + <option value="23">23 days</option> + <option value="24">24 days</option> + <option value="25">25 days</option> + <option value="26">26 days</option> + <option value="27">27 days</option> + <option value="28">28 days</option> + <option value="29">29 days</option> + <option value="30">30 days</option> + <option value="31">31 days</option> + </select> + </label> + + <label> + Key + <input type="password" name="key" required> + </label> + + <div class="g-Loading"> + <div class="g-Spinner"></div> + Uploading… + </div> + + <div class="g-Error"> + </div> + + <input type="submit" value="Upload"> +</form>"# +); + +pub const NOT_FOUND: &str = const_format::concatcp!( + PAGE, + r#" + <div> + Oops, not found. + </div> + "# +); + +pub const BAD_REQUEST: &str = const_format::concatcp!( + PAGE, + r#" + <div> + Oops, bad request. + </div> + "# +); + +pub const INTERNAL_SERVER_ERROR: &str = const_format::concatcp!( + PAGE, + r#" + <div> + Oops, internal server error. + </div> + "# +); + +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} + + <div> + <div> + <a class="g-Link" href="{href}">{filename}</a> – {size} + </div> + <div> + Expires in <b>{expiration}</b>. + </div> + </div> + "#, + 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)) + ) +} |