-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.js
82 lines (74 loc) · 2.22 KB
/
template.js
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
function escape(s) {
return s.
replace(/&/g, '&').
replace(/"/g, '"').
replace(/'/g, ''').
replace(/</g, '<').
replace(/>/g, '>');
}
function humanSize(i) {
var suffix = "";
var suffixes = ["T", "G", "M", "K"];
while(suffixes.length > 0 && i >= 1024) {
i /= 1024;
suffix = suffixes.pop();
}
return Math.ceil(i) + " " + suffix;
}
function rjust(s, len, fill) {
s = s.toString();
while(s.length < len)
s = fill + s;
return s;
}
function formatDate(i) {
var d = new Date(i);
return d.getDate() + "." +
(d.getMonth() + 1) + "." +
d.getFullYear() + " " +
rjust(d.getHours(), 2, '0') + ":" +
rjust(d.getMinutes(), 2, '0') + " Uhr";
}
module.exports = {
htmlHead: "<!DOCTYPE html>\
<html>\
<head>\
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\
<title>Sharing is Caring</title>\
<meta name='viewport' content='width=device-width,initial-scale=1'>\
<link rel='stylesheet' type='text/css' href='style.css'>\
<link rel='shortcut icon' href='/favicon.png'>\
</head>\
<body>\
<div id='page'>\
<h1>\
Sharing is Caring\
</h1>",
htmlFoot: "<p class='foot'>\
Kopimi\
</p>\
</div>\
</body>\
</html>",
uploadForm: "<div id='up'>\
<form action='/upload' method='post' enctype='multipart/form-data'>\
<input id='file' name='file' type='file' size='8'>\
<input type='submit' value='Hochladen'>\
</form>\
<p class='hint'>\
Give something to other visitors!\
</p>\
</div>",
downloadList: function(files) {
return "<ul id='down'>" +
files.map(function(file) {
var cssClass = file.type.split('/')[0];
return "<li><a href='/file/" + file.id + "/" + escape(encodeURIComponent(file.name)) + "' type='" + escape(file.type) + "' class='" + escape(cssClass) + "'>" + escape(file.name) + "</a> <span class='size'>" + humanSize(file.size) + "B</span><span class='stats'><b>" + file.downloads + "×</b> seit " + formatDate(file.date) + "</span></li>";
}).join('') +
"</ul>";
},
thanks: "<p>Vielen Dank, <a href='/'>zurück zur Übersicht.</a></p>",
error: function(e) {
return "<p>" + escape(e.message) + "</p><p><a href='/'>Zurück zur Übersicht.</a></p>";
}
};