aboutsummaryrefslogtreecommitdiff
path: root/src/templates.rs
blob: b551bf67db2f14264f2be0feabd21dbc697c08a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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))
    )
}