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