BlueGit

timfa filemanager

Files

filemanager / public / share.html

share.html

upda
timfa Tim Falken · pushed by timfa · 6 months ago
fffc2d3b History
share.html 11.1 KiB Download Raw
1<!DOCTYPE html>
2<html lang="nl">
3
4<head>
5 <meta charset="UTF-8" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 <title>Gedeeld bestand</title>
8 <style>
9 *,
10 *::before,
11 *::after {
12 box-sizing: border-box;
13 margin: 0;
14 padding: 0;
15 }
16
17 :root {
18 --bg: #0f1117;
19 --surface: #1a1d27;
20 --surface2: #21242f;
21 --border: #2e3247;
22 --accent: #5b7fff;
23 --accent-hover: #7b9fff;
24 --text: #e8eaf0;
25 --text-muted: #7880a0;
26 --danger: #e05c6e;
27 --success: #3fcf8e;
28 --radius: 10px;
29 }
30
31 html,
32 body {
33 height: 100%;
34 font-family: system-ui, -apple-system, sans-serif;
35 }
36
37 body {
38 background: var(--bg);
39 color: var(--text);
40 min-height: 100vh;
41 }
42
43 /* ── Timer bar ── */
44 #timer-bar {
45 position: sticky;
46 top: 0;
47 z-index: 10;
48 background: var(--surface);
49 border-bottom: 1px solid var(--border);
50 display: flex;
51 align-items: center;
52 justify-content: center;
53 gap: 0.6rem;
54 padding: 0.55rem 1rem;
55 font-size: 0.9rem;
56 color: var(--text-muted);
57 }
58
59 #timer-bar .timer-clock {
60 font-variant-numeric: tabular-nums;
61 font-weight: 600;
62 color: var(--text);
63 letter-spacing: 0.05em;
64 }
65
66 #timer-bar.expired {
67 color: var(--danger);
68 }
69
70 #timer-bar.expired .timer-clock {
71 color: var(--danger);
72 }
73
74 /* ── Main card ── */
75 #main {
76 max-width: 760px;
77 margin: 3rem auto;
78 padding: 0 1rem;
79 }
80
81 .card {
82 background: var(--surface);
83 border: 1px solid var(--border);
84 border-radius: var(--radius);
85 padding: 2rem;
86 margin-bottom: 1.5rem;
87 }
88
89 .card h1 {
90 font-size: 1.3rem;
91 font-weight: 600;
92 margin-bottom: 0.3rem;
93 word-break: break-all;
94 }
95
96 .card .meta {
97 font-size: 0.85rem;
98 color: var(--text-muted);
99 margin-bottom: 1.4rem;
100 }
101
102 /* ── Download button ── */
103 .btn {
104 display: inline-flex;
105 align-items: center;
106 gap: 0.5rem;
107 padding: 0.6rem 1.2rem;
108 border-radius: 7px;
109 font-size: 0.92rem;
110 font-weight: 500;
111 cursor: pointer;
112 border: none;
113 transition: background 0.15s;
114 }
115
116 .btn-primary {
117 background: var(--accent);
118 color: #fff;
119 }
120
121 .btn-primary:hover {
122 background: var(--accent-hover);
123 }
124
125 .btn-primary:disabled {
126 opacity: 0.45;
127 cursor: not-allowed;
128 }
129
130 /* ── Preview area ── */
131 #preview-wrap {
132 background: var(--surface2);
133 border: 1px solid var(--border);
134 border-radius: var(--radius);
135 overflow: hidden;
136 margin-bottom: 1.5rem;
137 min-height: 80px;
138 display: flex;
139 align-items: center;
140 justify-content: center;
141 }
142
143 #preview-wrap img,
144 #preview-wrap video,
145 #preview-wrap audio {
146 max-width: 100%;
147 max-height: 60vh;
148 display: block;
149 }
150
151 #preview-wrap audio {
152 padding: 1rem;
153 width: 100%;
154 }
155
156 #preview-wrap pre {
157 padding: 1.2rem;
158 overflow: auto;
159 max-height: 60vh;
160 width: 100%;
161 font-size: 0.82rem;
162 font-family: monospace;
163 color: var(--text);
164 white-space: pre-wrap;
165 word-break: break-word;
166 }
167
168 #preview-wrap .no-preview {
169 padding: 2rem;
170 color: var(--text-muted);
171 font-size: 0.9rem;
172 text-align: center;
173 }
174
175 /* ── Error / expired states ── */
176 #error-state {
177 text-align: center;
178 padding: 4rem 1rem;
179 }
180
181 #error-state h2 {
182 font-size: 1.4rem;
183 margin-bottom: 0.5rem;
184 }
185
186 #error-state p {
187 color: var(--text-muted);
188 }
189
190 /* ── Loading spinner ── */
191 #loading {
192 text-align: center;
193 padding: 6rem 1rem;
194 color: var(--text-muted);
195 }
196 </style>
197</head>
198
199<body>
200
201 <div id="timer-bar" style="display:none">
202 <span>Geldig voor</span>
203 <span id="timer-clock" class="timer-clock">--:--:--</span>
204 </div>
205
206 <div id="main">
207 <div id="loading">Laden…</div>
208 <div id="error-state" style="display:none">
209 <h2 id="error-title">Niet gevonden</h2>
210 <p id="error-msg">De link bestaat niet of is verlopen.</p>
211 </div>
212
213 <div id="content" style="display:none">
214 <div class="card">
215 <h1 id="file-name"></h1>
216 <p id="file-meta" class="meta"></p>
217 <a id="btn-download" class="btn btn-primary" href="#" download>
218 <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
219 stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
220 <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
221 <polyline points="7 10 12 15 17 10" />
222 <line x1="12" y1="15" x2="12" y2="3" />
223 </svg>
224 <span id="btn-download-label">Downloaden</span>
225 </a>
226 </div>
227
228 <div id="preview-wrap" style="display:none"></div>
229 </div>
230 </div>
231
232 <script>
233 (function ()
234 {
235 'use strict';
236
237 const token = location.pathname.split('/').pop();
238 let expiresAt = null;
239 let timerInterval = null;
240
241 // ── Timer ───────────────────────────────────────────────────────────────
242 function startTimer ()
243 {
244 const bar = document.getElementById('timer-bar');
245 const clock = document.getElementById('timer-clock');
246 bar.style.display = '';
247
248 function tick ()
249 {
250 const remaining = expiresAt - Date.now();
251 if (remaining <= 0)
252 {
253 clock.textContent = '00:00:00';
254 bar.classList.add('expired');
255 bar.querySelector('span').textContent = 'Verlopen —';
256 const dlBtn = document.getElementById('btn-download');
257 if (dlBtn) dlBtn.setAttribute('disabled', 'disabled');
258 clearInterval(timerInterval);
259 return;
260 }
261 const totalSecs = Math.floor(remaining / 1000);
262 const hh = String(Math.floor(totalSecs / 3600)).padStart(2, '0');
263 const mm = String(Math.floor((totalSecs % 3600) / 60)).padStart(2, '0');
264 const ss = String(totalSecs % 60).padStart(2, '0');
265 clock.textContent = `${hh}:${mm}:${ss}`;
266 }
267
268 tick();
269 timerInterval = setInterval(tick, 1000);
270 }
271
272 // ── Preview ──────────────────────────────────────────────────────────────
273 function tryPreview (name, isDir)
274 {
275 if (isDir) return; // no preview for folders
276
277 const wrap = document.getElementById('preview-wrap');
278 const ext = name.split('.').pop().toLowerCase();
279
280 const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'avif', 'ico'];
281 const videoExts = ['mp4', 'webm', 'ogg', 'mov'];
282 const audioExts = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'opus', 'm4a'];
283 const textExts = ['txt', 'md', 'json', 'js', 'ts', 'html', 'css', 'xml', 'csv', 'yaml', 'yml', 'sh', 'log', 'ini', 'toml', 'py', 'rb', 'go', 'java', 'c', 'cpp', 'h', 'rs'];
284
285 const previewUrl = `/api/share/preview/${token}`;
286 let el;
287
288 if (imageExts.includes(ext))
289 {
290 el = document.createElement('img');
291 el.src = previewUrl;
292 el.alt = name;
293 } else if (videoExts.includes(ext))
294 {
295 el = document.createElement('video');
296 el.src = previewUrl;
297 el.controls = true;
298 } else if (audioExts.includes(ext))
299 {
300 el = document.createElement('audio');
301 el.src = previewUrl;
302 el.controls = true;
303 } else if (textExts.includes(ext))
304 {
305 fetch(previewUrl)
306 .then(r =>
307 {
308 if (!r.ok) throw new Error('preview failed');
309 return r.text();
310 })
311 .then(text =>
312 {
313 const pre = document.createElement('pre');
314 pre.textContent = text;
315 wrap.innerHTML = '';
316 wrap.appendChild(pre);
317 wrap.style.display = '';
318 })
319 .catch(() => { /* no preview available */ });
320 return;
321 } else
322 {
323 return; // no preview
324 }
325
326 el.addEventListener('error', () => { wrap.innerHTML = '<div class="no-preview">Geen voorbeeldweergave beschikbaar.</div>'; wrap.style.display = ''; });
327 wrap.innerHTML = '';
328 wrap.appendChild(el);
329 wrap.style.display = '';
330 }
331
332 // ── Boot ─────────────────────────────────────────────────────────────────
333 function showError (title, msg)
334 {
335 document.getElementById('loading').style.display = 'none';
336 document.getElementById('content').style.display = 'none';
337 document.getElementById('error-title').textContent = title;
338 document.getElementById('error-msg').textContent = msg;
339 document.getElementById('error-state').style.display = '';
340 }
341
342 function formatBytes (bytes)
343 {
344 if (bytes == null) return '';
345 if (bytes < 1024) return bytes + ' B';
346 if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
347 if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
348 return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
349 }
350
351 fetch(`/api/share/info/${token}`)
352 .then(r => r.json().then(d => ({ ok: r.ok, status: r.status, data: d })))
353 .then(({ ok, status, data }) =>
354 {
355 document.getElementById('loading').style.display = 'none';
356
357 if (status === 410)
358 {
359 showError('Link verlopen', 'Deze deellink is niet meer geldig.');
360 return;
361 }
362 if (!ok)
363 {
364 showError('Niet gevonden', data.error || 'De link bestaat niet.');
365 return;
366 }
367
368 expiresAt = data.expiresAt;
369 startTimer();
370
371 document.getElementById('file-name').textContent = data.name;
372 const metaLine = data.isDir ? 'Map (download als .zip)' : 'Bestand';
373 document.getElementById('file-meta').textContent = metaLine;
374
375 const dlBtn = document.getElementById('btn-download');
376 dlBtn.href = `/api/share/download/${token}`;
377 if (data.isDir)
378 {
379 document.getElementById('btn-download-label').textContent = 'Downloaden als .zip';
380 dlBtn.download = data.name + '.zip';
381 } else
382 {
383 document.getElementById('btn-download-label').textContent = 'Downloaden';
384 dlBtn.download = data.name;
385 }
386
387 document.getElementById('content').style.display = '';
388
389 tryPreview(data.name, data.isDir);
390 })
391 .catch(() =>
392 {
393 showError('Fout', 'Kon de server niet bereiken.');
394 });
395 }());
396 </script>
397</body>
398
399</html>