-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (113 loc) · 4.2 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="upgrade-insecure-requests"
/>
<link
rel="icon"
type="image/x-icon"
href="favicon.ico?auth={{.Auth}}"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css"
/>
{{if (eq .Perm "manage")}}
<script src="https://cdn.jsdelivr.net/npm/tus-js-client@latest/dist/tus.min.js"></script>
<script>
const uploadFile = (event) => {
event.preventDefault();
const form = document.getElementById("form");
const file = document.getElementById("file").files[0];
const progress = document.createElement("progress");
progress.max = 100;
progress.value = 0;
const upload = new tus.Upload(file, {
endpoint: "/tusd/",
headers: {
Authorization: "{{.Auth}}",
},
metadata: {
filename: file.name,
filetype: file.type,
},
onProgress: (bytesUploaded, bytesTotal) => {
progress.value = (
(bytesUploaded / bytesTotal) *
100
).toFixed(2);
},
onSuccess: () => location.reload(),
onError: (error) => console.error(error),
});
form.replaceWith(progress);
upload.start();
};
const deleteFile = async (name) => {
await fetch(`file/${name}?auth={{.Auth}}`, {
method: "DELETE",
});
location.reload();
};
</script>
{{end}}
<title>File Server</title>
</head>
<body>
<main class="container">
{{if (eq .Perm "manage")}}
<form id="form" onsubmit="uploadFile(event)">
<fieldset role="group">
<input id="file" name="file" type="file" />
<input type="submit" value="Upload" />
</fieldset>
</form>
{{end}}
<div class="overflow-auto">
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Size</th>
<th scope="col">Modified</th>
<th scope="col">Download</th>
{{if (eq .Perm "manage")}}
<th scope="col">Delete</th>
{{end}}
</tr>
</thead>
<tbody>
{{range .Files}}
<tr>
<th scope="row">{{.Name}}</th>
<td>{{.Size}}</td>
<td>{{.Modified}}</td>
<td>
<a
href="file/{{.Name}}?auth={{$.Auth}}"
download
>Download
</a>
</td>
{{if (eq $.Perm "manage")}}
<td>
<a
id="{{.Name}}"
style="cursor: pointer"
onclick="deleteFile(this.id)"
>Delete</a
>
</td>
{{end}}
</tr>
{{end}}
</tbody>
</table>
</div>
</main>
</body>
</html>