| 1 | <!DOCTYPE html> |
| 2 | <html lang="en-GB"> |
| 3 | |
| 4 | <head> |
| 5 | <meta charset="UTF-8" /> |
| 6 | <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 7 | <title>Shared file</title> |
| 8 | <link rel="stylesheet" href="/vendor/video.js/video-js.css" /> |
| 9 | <style> |
| 10 | *, |
| 11 | *::before, |
| 12 | *::after { |
| 13 | box-sizing: border-box; |
| 14 | margin: 0; |
| 15 | padding: 0; |
| 16 | } |
| 17 | |
| 18 | :root { |
| 19 | --bg: #0f1117; |
| 20 | --surface: #1a1d27; |
| 21 | --surface2: #21242f; |
| 22 | --border: #2e3247; |
| 23 | --accent: #5b7fff; |
| 24 | --accent-hover: #7b9fff; |
| 25 | --text: #e8eaf0; |
| 26 | --text-muted: #7880a0; |
| 27 | --danger: #e05c6e; |
| 28 | --success: #3fcf8e; |
| 29 | --radius: 10px; |
| 30 | } |
| 31 | |
| 32 | html, |
| 33 | body { |
| 34 | height: 100%; |
| 35 | font-family: system-ui, -apple-system, sans-serif; |
| 36 | } |
| 37 | |
| 38 | body { |
| 39 | background: var(--bg); |
| 40 | color: var(--text); |
| 41 | min-height: 100vh; |
| 42 | } |
| 43 | |
| 44 | /* ── Timer bar ── */ |
| 45 | #timer-bar { |
| 46 | position: sticky; |
| 47 | top: 0; |
| 48 | z-index: 10; |
| 49 | background: var(--surface); |
| 50 | border-bottom: 1px solid var(--border); |
| 51 | display: flex; |
| 52 | align-items: center; |
| 53 | justify-content: center; |
| 54 | gap: 0.6rem; |
| 55 | padding: 0.55rem 1rem; |
| 56 | font-size: 0.9rem; |
| 57 | color: var(--text-muted); |
| 58 | } |
| 59 | |
| 60 | #timer-bar .timer-clock { |
| 61 | font-variant-numeric: tabular-nums; |
| 62 | font-weight: 600; |
| 63 | color: var(--text); |
| 64 | letter-spacing: 0.05em; |
| 65 | } |
| 66 | |
| 67 | #timer-bar.expired { |
| 68 | color: var(--danger); |
| 69 | } |
| 70 | |
| 71 | #timer-bar.expired .timer-clock { |
| 72 | color: var(--danger); |
| 73 | } |
| 74 | |
| 75 | /* ── Main card ── */ |
| 76 | #main { |
| 77 | max-width: 760px; |
| 78 | margin: 3rem auto; |
| 79 | padding: 0 1rem; |
| 80 | } |
| 81 | |
| 82 | .card { |
| 83 | background: var(--surface); |
| 84 | border: 1px solid var(--border); |
| 85 | border-radius: var(--radius); |
| 86 | padding: 2rem; |
| 87 | margin-bottom: 1.5rem; |
| 88 | } |
| 89 | |
| 90 | .card h1 { |
| 91 | font-size: 1.3rem; |
| 92 | font-weight: 600; |
| 93 | margin-bottom: 0.3rem; |
| 94 | word-break: break-all; |
| 95 | } |
| 96 | |
| 97 | .card .meta { |
| 98 | font-size: 0.85rem; |
| 99 | color: var(--text-muted); |
| 100 | margin-bottom: 1.4rem; |
| 101 | } |
| 102 | |
| 103 | /* ── Download button ── */ |
| 104 | .btn { |
| 105 | display: inline-flex; |
| 106 | align-items: center; |
| 107 | gap: 0.5rem; |
| 108 | padding: 0.6rem 1.2rem; |
| 109 | border-radius: 7px; |
| 110 | font-size: 0.92rem; |
| 111 | font-weight: 500; |
| 112 | cursor: pointer; |
| 113 | border: none; |
| 114 | transition: background 0.15s; |
| 115 | } |
| 116 | |
| 117 | .btn-primary { |
| 118 | background: var(--accent); |
| 119 | color: #fff; |
| 120 | } |
| 121 | |
| 122 | .btn-primary:hover { |
| 123 | background: var(--accent-hover); |
| 124 | } |
| 125 | |
| 126 | .btn-primary:disabled { |
| 127 | opacity: 0.45; |
| 128 | cursor: not-allowed; |
| 129 | } |
| 130 | |
| 131 | /* ── Preview area ── */ |
| 132 | #preview-wrap { |
| 133 | background: var(--surface2); |
| 134 | border: 1px solid var(--border); |
| 135 | border-radius: var(--radius); |
| 136 | overflow: hidden; |
| 137 | margin-bottom: 1.5rem; |
| 138 | min-height: 80px; |
| 139 | display: flex; |
| 140 | align-items: center; |
| 141 | justify-content: center; |
| 142 | } |
| 143 | |
| 144 | #preview-wrap img, |
| 145 | #preview-wrap video, |
| 146 | #preview-wrap audio, |
| 147 | #preview-wrap .video-js { |
| 148 | max-width: 100%; |
| 149 | max-height: 60vh; |
| 150 | display: block; |
| 151 | } |
| 152 | |
| 153 | #preview-wrap .video-js { |
| 154 | width: 100%; |
| 155 | min-height: 360px; |
| 156 | background: #000; |
| 157 | } |
| 158 | |
| 159 | #preview-wrap .video-js .vjs-tech { |
| 160 | object-fit: contain; |
| 161 | } |
| 162 | |
| 163 | #preview-wrap audio { |
| 164 | padding: 1rem; |
| 165 | width: 100%; |
| 166 | } |
| 167 | |
| 168 | #preview-wrap pre { |
| 169 | padding: 1.2rem; |
| 170 | overflow: auto; |
| 171 | max-height: 60vh; |
| 172 | width: 100%; |
| 173 | font-size: 0.82rem; |
| 174 | font-family: monospace; |
| 175 | color: var(--text); |
| 176 | white-space: pre-wrap; |
| 177 | word-break: break-word; |
| 178 | } |
| 179 | |
| 180 | #preview-wrap .no-preview { |
| 181 | padding: 2rem; |
| 182 | color: var(--text-muted); |
| 183 | font-size: 0.9rem; |
| 184 | text-align: center; |
| 185 | } |
| 186 | |
| 187 | /* ── Error / expired states ── */ |
| 188 | #error-state { |
| 189 | text-align: center; |
| 190 | padding: 4rem 1rem; |
| 191 | } |
| 192 | |
| 193 | #error-state h2 { |
| 194 | font-size: 1.4rem; |
| 195 | margin-bottom: 0.5rem; |
| 196 | } |
| 197 | |
| 198 | #error-state p { |
| 199 | color: var(--text-muted); |
| 200 | } |
| 201 | |
| 202 | /* ── Loading spinner ── */ |
| 203 | #loading { |
| 204 | text-align: center; |
| 205 | padding: 6rem 1rem; |
| 206 | color: var(--text-muted); |
| 207 | } |
| 208 | </style> |
| 209 | </head> |
| 210 | |
| 211 | <body> |
| 212 | |
| 213 | <div id="timer-bar" style="display:none"> |
| 214 | <span>Valid for</span> |
| 215 | <span id="timer-clock" class="timer-clock">--:--:--</span> |
| 216 | </div> |
| 217 | |
| 218 | <div id="main"> |
| 219 | <div id="loading">Loading...</div> |
| 220 | <div id="error-state" style="display:none"> |
| 221 | <h2 id="error-title">Not found</h2> |
| 222 | <p id="error-msg">This link does not exist or has expired.</p> |
| 223 | </div> |
| 224 | |
| 225 | <div id="content" style="display:none"> |
| 226 | <div class="card"> |
| 227 | <h1 id="file-name"></h1> |
| 228 | <p id="file-meta" class="meta"></p> |
| 229 | <a id="btn-download" class="btn btn-primary" href="#" download> |
| 230 | <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" |
| 231 | stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 232 | <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> |
| 233 | <polyline points="7 10 12 15 17 10" /> |
| 234 | <line x1="12" y1="15" x2="12" y2="3" /> |
| 235 | </svg> |
| 236 | <span id="btn-download-label">Download</span> |
| 237 | </a> |
| 238 | </div> |
| 239 | |
| 240 | <div id="preview-wrap" style="display:none"></div> |
| 241 | </div> |
| 242 | </div> |
| 243 | |
| 244 | <script> |
| 245 | (function () |
| 246 | { |
| 247 | 'use strict'; |
| 248 | |
| 249 | const token = location.pathname.split('/').pop(); |
| 250 | const VIDEO_FORWARD_BUFFER_SECONDS = 60 * 60; |
| 251 | const SHARE_VIDEO_PREFS_KEY = 'filemanager.share-video-prefs.v1'; |
| 252 | const VIDEO_TEXT_TRACK_SETTINGS_KEY = 'vjs-text-track-settings'; |
| 253 | const VIDEO_TEXT_TRACK_DEFAULT_SETTINGS_RAW = JSON.stringify({ |
| 254 | color: '#fff', |
| 255 | textOpacity: '1', |
| 256 | backgroundColor: '#000', |
| 257 | backgroundOpacity: '0', |
| 258 | windowColor: '#000', |
| 259 | windowOpacity: '0', |
| 260 | fontPercent: '1.00', |
| 261 | edgeStyle: 'uniform', |
| 262 | fontFamily: 'proportionalSansSerif', |
| 263 | }); |
| 264 | let expiresAt = null; |
| 265 | let timerInterval = null; |
| 266 | let shareVideoPlayer = null; |
| 267 | let shareTrackPrefs = null; |
| 268 | |
| 269 | function loadShareVideoPrefs () |
| 270 | { |
| 271 | try |
| 272 | { |
| 273 | const raw = localStorage.getItem(SHARE_VIDEO_PREFS_KEY); |
| 274 | const parsed = raw ? JSON.parse(raw) : {}; |
| 275 | if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {}; |
| 276 | return parsed; |
| 277 | } catch |
| 278 | { |
| 279 | return {}; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | function saveShareVideoPrefs (patch) |
| 284 | { |
| 285 | try |
| 286 | { |
| 287 | const current = loadShareVideoPrefs(); |
| 288 | localStorage.setItem(SHARE_VIDEO_PREFS_KEY, JSON.stringify({ ...current, ...(patch || {}) })); |
| 289 | } catch |
| 290 | { |
| 291 | // Ignore localStorage failures. |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | function applyShareVideoTextTrackPrefs () |
| 296 | { |
| 297 | try |
| 298 | { |
| 299 | // Always force known caption defaults to avoid stale user overrides. |
| 300 | localStorage.setItem(VIDEO_TEXT_TRACK_SETTINGS_KEY, VIDEO_TEXT_TRACK_DEFAULT_SETTINGS_RAW); |
| 301 | } catch |
| 302 | { |
| 303 | // Ignore localStorage failures. |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | function normaliseTrackName (name) |
| 308 | { |
| 309 | return String(name || '').trim().toLowerCase(); |
| 310 | } |
| 311 | |
| 312 | function getTrackName (track) |
| 313 | { |
| 314 | if (!track || typeof track !== 'object') return ''; |
| 315 | const label = String(track.label || '').trim(); |
| 316 | if (label) return label; |
| 317 | const name = String(track.name || '').trim(); |
| 318 | if (name) return name; |
| 319 | const language = String(track.language || '').trim(); |
| 320 | if (language) return language; |
| 321 | const id = String(track.id || '').trim(); |
| 322 | if (id) return id; |
| 323 | return ''; |
| 324 | } |
| 325 | |
| 326 | function trackListToArray (trackList) |
| 327 | { |
| 328 | if (!trackList || typeof trackList.length !== 'number') return []; |
| 329 | const out = []; |
| 330 | for (let i = 0; i < trackList.length; i++) |
| 331 | { |
| 332 | const track = trackList[i] || (typeof trackList.item === 'function' ? trackList.item(i) : null); |
| 333 | if (track) out.push(track); |
| 334 | } |
| 335 | return out; |
| 336 | } |
| 337 | |
| 338 | function subtitleTracksFromPlayer (player) |
| 339 | { |
| 340 | if (!player || typeof player.textTracks !== 'function') return []; |
| 341 | return trackListToArray(player.textTracks()).filter((track) => |
| 342 | { |
| 343 | const kind = String(track.kind || '').toLowerCase(); |
| 344 | return kind === 'subtitles' || kind === 'captions'; |
| 345 | }); |
| 346 | } |
| 347 | |
| 348 | function audioTracksFromPlayer (player) |
| 349 | { |
| 350 | if (!player || typeof player.audioTracks !== 'function') return []; |
| 351 | return trackListToArray(player.audioTracks()); |
| 352 | } |
| 353 | |
| 354 | function applySavedSubtitleTrack (player, savedName) |
| 355 | { |
| 356 | if (typeof savedName !== 'string') return; |
| 357 | const tracks = subtitleTracksFromPlayer(player); |
| 358 | if (!tracks.length) return; |
| 359 | |
| 360 | const wanted = normaliseTrackName(savedName); |
| 361 | if (!wanted) |
| 362 | { |
| 363 | for (const track of tracks) track.mode = 'disabled'; |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | const match = tracks.find((track) => normaliseTrackName(getTrackName(track)) === wanted); |
| 368 | if (!match) return; |
| 369 | |
| 370 | for (const track of tracks) |
| 371 | { |
| 372 | track.mode = track === match ? 'showing' : 'disabled'; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | function applySavedAudioTrack (player, savedName) |
| 377 | { |
| 378 | if (typeof savedName !== 'string') return; |
| 379 | const tracks = audioTracksFromPlayer(player); |
| 380 | if (!tracks.length) return; |
| 381 | |
| 382 | const wanted = normaliseTrackName(savedName); |
| 383 | if (!wanted) return; |
| 384 | |
| 385 | const match = tracks.find((track) => normaliseTrackName(getTrackName(track)) === wanted); |
| 386 | if (!match) return; |
| 387 | |
| 388 | for (const track of tracks) |
| 389 | { |
| 390 | track.enabled = track === match; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | function getSelectedSubtitleTrackName (player) |
| 395 | { |
| 396 | const tracks = subtitleTracksFromPlayer(player); |
| 397 | if (!tracks.length) return null; |
| 398 | const active = tracks.find((track) => String(track.mode || '').toLowerCase() === 'showing'); |
| 399 | return active ? getTrackName(active) : ''; |
| 400 | } |
| 401 | |
| 402 | function getSelectedAudioTrackName (player) |
| 403 | { |
| 404 | const tracks = audioTracksFromPlayer(player); |
| 405 | if (!tracks.length) return null; |
| 406 | const active = tracks.find((track) => !!track.enabled); |
| 407 | return active ? getTrackName(active) : ''; |
| 408 | } |
| 409 | |
| 410 | function bindShareVideoTrackPrefs (player, prefs) |
| 411 | { |
| 412 | const applySavedTracks = () => |
| 413 | { |
| 414 | applySavedSubtitleTrack(player, prefs.subtitleTrackName); |
| 415 | applySavedAudioTrack(player, prefs.audioTrackName); |
| 416 | }; |
| 417 | |
| 418 | const captureSelectedTracks = () => |
| 419 | { |
| 420 | const subtitleTrackName = getSelectedSubtitleTrackName(player); |
| 421 | const audioTrackName = getSelectedAudioTrackName(player); |
| 422 | const patch = {}; |
| 423 | |
| 424 | if (subtitleTrackName !== null) patch.subtitleTrackName = subtitleTrackName; |
| 425 | if (audioTrackName !== null) patch.audioTrackName = audioTrackName; |
| 426 | |
| 427 | if (Object.keys(patch).length) saveShareVideoPrefs(patch); |
| 428 | }; |
| 429 | |
| 430 | const textTrackList = typeof player.textTracks === 'function' ? player.textTracks() : null; |
| 431 | const audioTrackList = typeof player.audioTracks === 'function' ? player.audioTracks() : null; |
| 432 | const onTrackListChange = () => captureSelectedTracks(); |
| 433 | |
| 434 | if (textTrackList && typeof textTrackList.addEventListener === 'function') |
| 435 | { |
| 436 | textTrackList.addEventListener('change', onTrackListChange); |
| 437 | } |
| 438 | |
| 439 | if (audioTrackList && typeof audioTrackList.addEventListener === 'function') |
| 440 | { |
| 441 | audioTrackList.addEventListener('change', onTrackListChange); |
| 442 | } |
| 443 | |
| 444 | return { |
| 445 | applySavedTracks, |
| 446 | captureSelectedTracks, |
| 447 | detach: () => |
| 448 | { |
| 449 | if (textTrackList && typeof textTrackList.removeEventListener === 'function') |
| 450 | { |
| 451 | textTrackList.removeEventListener('change', onTrackListChange); |
| 452 | } |
| 453 | if (audioTrackList && typeof audioTrackList.removeEventListener === 'function') |
| 454 | { |
| 455 | audioTrackList.removeEventListener('change', onTrackListChange); |
| 456 | } |
| 457 | }, |
| 458 | }; |
| 459 | } |
| 460 | |
| 461 | function cleanupShareVideoPlayer () |
| 462 | { |
| 463 | if (!shareVideoPlayer) return; |
| 464 | |
| 465 | try { shareTrackPrefs && shareTrackPrefs.captureSelectedTracks(); } catch { /* ignore */ } |
| 466 | try { shareTrackPrefs && shareTrackPrefs.detach(); } catch { /* ignore */ } |
| 467 | try { shareVideoPlayer.dispose(); } catch { /* ignore */ } |
| 468 | |
| 469 | shareVideoPlayer = null; |
| 470 | shareTrackPrefs = null; |
| 471 | } |
| 472 | |
| 473 | function configureVideoJsBuffering () |
| 474 | { |
| 475 | if (!window.videojs || !window.videojs.Vhs || window.videojs.__filemanagerBufferingConfigured) return; |
| 476 | window.videojs.__filemanagerBufferingConfigured = true; |
| 477 | |
| 478 | try |
| 479 | { |
| 480 | window.videojs.Vhs.GOAL_BUFFER_LENGTH = VIDEO_FORWARD_BUFFER_SECONDS; |
| 481 | window.videojs.Vhs.MAX_GOAL_BUFFER_LENGTH = VIDEO_FORWARD_BUFFER_SECONDS; |
| 482 | } catch |
| 483 | { |
| 484 | // Ignore builds that do not expose VHS buffer configuration. |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // ── Timer ─────────────────────────────────────────────────────────────── |
| 489 | function startTimer () |
| 490 | { |
| 491 | const bar = document.getElementById('timer-bar'); |
| 492 | const clock = document.getElementById('timer-clock'); |
| 493 | bar.style.display = ''; |
| 494 | |
| 495 | function tick () |
| 496 | { |
| 497 | const remaining = expiresAt - Date.now(); |
| 498 | if (remaining <= 0) |
| 499 | { |
| 500 | clock.textContent = '00:00:00'; |
| 501 | bar.classList.add('expired'); |
| 502 | bar.querySelector('span').textContent = 'Expired —'; |
| 503 | const dlBtn = document.getElementById('btn-download'); |
| 504 | if (dlBtn) dlBtn.setAttribute('disabled', 'disabled'); |
| 505 | clearInterval(timerInterval); |
| 506 | return; |
| 507 | } |
| 508 | const totalSecs = Math.floor(remaining / 1000); |
| 509 | const hh = String(Math.floor(totalSecs / 3600)).padStart(2, '0'); |
| 510 | const mm = String(Math.floor((totalSecs % 3600) / 60)).padStart(2, '0'); |
| 511 | const ss = String(totalSecs % 60).padStart(2, '0'); |
| 512 | clock.textContent = `${hh}:${mm}:${ss}`; |
| 513 | } |
| 514 | |
| 515 | tick(); |
| 516 | timerInterval = setInterval(tick, 1000); |
| 517 | } |
| 518 | |
| 519 | // ── Preview ────────────────────────────────────────────────────────────── |
| 520 | function normaliseVideoDuration (player, durationSeconds) |
| 521 | { |
| 522 | const duration = Number(durationSeconds); |
| 523 | if (!player || !Number.isFinite(duration) || duration <= 0) return; |
| 524 | |
| 525 | let originalDuration = null; |
| 526 | let durationWasChanged = false; |
| 527 | try |
| 528 | { |
| 529 | originalDuration = typeof player.duration === 'function' ? player.duration.bind(player) : null; |
| 530 | installDurationFallback(player, originalDuration, duration); |
| 531 | if (player.__filemanagerDurationApplied) return; |
| 532 | |
| 533 | const current = originalDuration ? Number(originalDuration()) : NaN; |
| 534 | const withinTolerance = Number.isFinite(current) && current >= duration * 0.95; |
| 535 | console.log(`Current duration: ${formatDurationForDebug(current)}, Target time: ${formatDurationForDebug(duration)}, within 95%? ${withinTolerance ? 'yes' : 'no'}`); |
| 536 | if (withinTolerance) |
| 537 | { |
| 538 | player.__filemanagerDurationApplied = true; |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | if (originalDuration) |
| 543 | { |
| 544 | durationWasChanged = true; |
| 545 | originalDuration(duration); |
| 546 | } |
| 547 | } catch |
| 548 | { |
| 549 | // Ignore players that do not support setting duration. |
| 550 | } |
| 551 | |
| 552 | try |
| 553 | { |
| 554 | const updated = originalDuration ? Number(originalDuration()) : NaN; |
| 555 | if (Number.isFinite(updated) && updated >= duration * 0.95) |
| 556 | { |
| 557 | player.__filemanagerDurationApplied = true; |
| 558 | if (durationWasChanged && typeof player.trigger === 'function') player.trigger('durationchange'); |
| 559 | return; |
| 560 | } |
| 561 | |
| 562 | player.__filemanagerDurationApplied = true; |
| 563 | if (typeof player.trigger === 'function') player.trigger('durationchange'); |
| 564 | } catch |
| 565 | { |
| 566 | // Ignore duration fallback failures. |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | function installDurationFallback (player, originalDuration, duration) |
| 571 | { |
| 572 | if (!player || !originalDuration || player.__filemanagerDurationFallback) return; |
| 573 | |
| 574 | player.__filemanagerDurationFallback = true; |
| 575 | player.duration = function durationWithFallback (...args) |
| 576 | { |
| 577 | if (args.length) return originalDuration(...args); |
| 578 | const current = Number(originalDuration()); |
| 579 | return Number.isFinite(current) && current >= duration * 0.95 ? current : duration; |
| 580 | }; |
| 581 | } |
| 582 | |
| 583 | function formatDurationForDebug (seconds) |
| 584 | { |
| 585 | const value = Number(seconds); |
| 586 | if (!Number.isFinite(value) || value < 0) return 'unknown'; |
| 587 | |
| 588 | const totalSeconds = Math.floor(value); |
| 589 | const hh = String(Math.floor(totalSeconds / 3600)).padStart(2, '0'); |
| 590 | const mm = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0'); |
| 591 | const ss = String(totalSeconds % 60).padStart(2, '0'); |
| 592 | return `${hh}:${mm}:${ss}`; |
| 593 | } |
| 594 | |
| 595 | function ensureVideoPlaybackUi (player, durationSeconds) |
| 596 | { |
| 597 | if (!player || typeof player.on !== 'function') return; |
| 598 | |
| 599 | const forceVodUi = () => |
| 600 | { |
| 601 | normaliseVideoDuration(player, durationSeconds); |
| 602 | |
| 603 | try |
| 604 | { |
| 605 | if (player.liveTracker && typeof player.liveTracker.stopTracking === 'function') |
| 606 | { |
| 607 | player.liveTracker.stopTracking(); |
| 608 | } |
| 609 | } catch |
| 610 | { |
| 611 | // Ignore live tracker availability issues. |
| 612 | } |
| 613 | |
| 614 | try |
| 615 | { |
| 616 | if (typeof player.removeClass === 'function') |
| 617 | { |
| 618 | player.removeClass('vjs-live'); |
| 619 | } |
| 620 | } catch |
| 621 | { |
| 622 | // Ignore class update failures. |
| 623 | } |
| 624 | }; |
| 625 | |
| 626 | player.ready(forceVodUi); |
| 627 | player.on('loadedmetadata', forceVodUi); |
| 628 | player.on('durationchange', forceVodUi); |
| 629 | player.on('loadedplaylist', forceVodUi); |
| 630 | } |
| 631 | |
| 632 | function tryPreview (name, isDir) |
| 633 | { |
| 634 | if (isDir) return; // no preview for folders |
| 635 | |
| 636 | const wrap = document.getElementById('preview-wrap'); |
| 637 | const ext = name.split('.').pop().toLowerCase(); |
| 638 | |
| 639 | const imageExts = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'avif', 'ico']; |
| 640 | const videoExts = ['mp4', 'webm', 'ogv', 'mov', 'avi', 'mkv']; |
| 641 | const audioExts = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'opus', 'm4a']; |
| 642 | 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']; |
| 643 | |
| 644 | const previewUrl = `/api/share/preview/${token}`; |
| 645 | let el; |
| 646 | |
| 647 | if (imageExts.includes(ext)) |
| 648 | { |
| 649 | el = document.createElement('img'); |
| 650 | el.src = previewUrl; |
| 651 | el.alt = name; |
| 652 | } else if (videoExts.includes(ext)) |
| 653 | { |
| 654 | fetch(`/api/share/video-stream/${token}`) |
| 655 | .then(r => r.json().then(d => ({ ok: r.ok, data: d }))) |
| 656 | .then(({ ok, data }) => |
| 657 | { |
| 658 | if (!ok) throw new Error(data.error || 'Streaming failed'); |
| 659 | configureVideoJsBuffering(); |
| 660 | applyShareVideoTextTrackPrefs(); |
| 661 | const prefs = loadShareVideoPrefs(); |
| 662 | |
| 663 | const video = document.createElement('video'); |
| 664 | video.className = 'video-js vjs-big-play-centered'; |
| 665 | video.controls = true; |
| 666 | video.preload = 'auto'; |
| 667 | video.playsInline = true; |
| 668 | |
| 669 | wrap.innerHTML = ''; |
| 670 | wrap.appendChild(video); |
| 671 | |
| 672 | cleanupShareVideoPlayer(); |
| 673 | |
| 674 | shareVideoPlayer = window.videojs(video, { |
| 675 | controls: true, |
| 676 | fluid: true, |
| 677 | responsive: true, |
| 678 | preload: 'auto', |
| 679 | controlBar: { |
| 680 | currentTimeDisplay: true, |
| 681 | timeDivider: true, |
| 682 | durationDisplay: true, |
| 683 | remainingTimeDisplay: false, |
| 684 | }, |
| 685 | sources: [{ src: data.playlistUrl, type: 'application/x-mpegURL' }], |
| 686 | tracks: (data.subtitleTracks || []).map(track => ({ |
| 687 | kind: 'subtitles', |
| 688 | src: track.src, |
| 689 | srclang: track.language || 'und', |
| 690 | label: track.label, |
| 691 | default: !!track.default, |
| 692 | })), |
| 693 | }); |
| 694 | |
| 695 | shareTrackPrefs = bindShareVideoTrackPrefs(shareVideoPlayer, prefs); |
| 696 | ensureVideoPlaybackUi(shareVideoPlayer, data.durationSeconds); |
| 697 | |
| 698 | shareVideoPlayer.ready(() => |
| 699 | { |
| 700 | const volume = Number(prefs.volume); |
| 701 | if (Number.isFinite(volume)) |
| 702 | { |
| 703 | shareVideoPlayer.volume(Math.max(0, Math.min(1, volume))); |
| 704 | } |
| 705 | shareTrackPrefs.applySavedTracks(); |
| 706 | }); |
| 707 | |
| 708 | shareVideoPlayer.on('loadedmetadata', shareTrackPrefs.applySavedTracks); |
| 709 | shareVideoPlayer.on('loadedplaylist', shareTrackPrefs.applySavedTracks); |
| 710 | shareVideoPlayer.on('volumechange', () => |
| 711 | { |
| 712 | const v = Number(shareVideoPlayer.volume()); |
| 713 | if (Number.isFinite(v)) saveShareVideoPrefs({ volume: v }); |
| 714 | }); |
| 715 | |
| 716 | wrap.style.display = ''; |
| 717 | }) |
| 718 | .catch(() => |
| 719 | { |
| 720 | wrap.innerHTML = '<div class="no-preview">No preview available.</div>'; |
| 721 | wrap.style.display = ''; |
| 722 | }); |
| 723 | return; |
| 724 | } else if (audioExts.includes(ext)) |
| 725 | { |
| 726 | el = document.createElement('audio'); |
| 727 | el.src = previewUrl; |
| 728 | el.controls = true; |
| 729 | } else if (textExts.includes(ext)) |
| 730 | { |
| 731 | fetch(previewUrl) |
| 732 | .then(r => |
| 733 | { |
| 734 | if (!r.ok) throw new Error('preview failed'); |
| 735 | return r.text(); |
| 736 | }) |
| 737 | .then(text => |
| 738 | { |
| 739 | const pre = document.createElement('pre'); |
| 740 | pre.textContent = text; |
| 741 | wrap.innerHTML = ''; |
| 742 | wrap.appendChild(pre); |
| 743 | wrap.style.display = ''; |
| 744 | }) |
| 745 | .catch(() => { /* no preview available */ }); |
| 746 | return; |
| 747 | } else |
| 748 | { |
| 749 | return; // no preview |
| 750 | } |
| 751 | |
| 752 | el.addEventListener('error', () => { wrap.innerHTML = '<div class="no-preview">No preview available.</div>'; wrap.style.display = ''; }); |
| 753 | wrap.innerHTML = ''; |
| 754 | wrap.appendChild(el); |
| 755 | wrap.style.display = ''; |
| 756 | } |
| 757 | |
| 758 | // ── Boot ───────────────────────────────────────────────────────────────── |
| 759 | function showError (title, msg) |
| 760 | { |
| 761 | document.getElementById('loading').style.display = 'none'; |
| 762 | document.getElementById('content').style.display = 'none'; |
| 763 | document.getElementById('error-title').textContent = title; |
| 764 | document.getElementById('error-msg').textContent = msg; |
| 765 | document.getElementById('error-state').style.display = ''; |
| 766 | } |
| 767 | |
| 768 | function formatBytes (bytes) |
| 769 | { |
| 770 | if (bytes == null) return ''; |
| 771 | if (bytes < 1024) return bytes + ' B'; |
| 772 | if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'; |
| 773 | if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(1) + ' MB'; |
| 774 | return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB'; |
| 775 | } |
| 776 | |
| 777 | fetch(`/api/share/info/${token}`) |
| 778 | .then(r => r.json().then(d => ({ ok: r.ok, status: r.status, data: d }))) |
| 779 | .then(({ ok, status, data }) => |
| 780 | { |
| 781 | document.getElementById('loading').style.display = 'none'; |
| 782 | |
| 783 | if (status === 410) |
| 784 | { |
| 785 | showError('Link expired', 'This share link is no longer valid.'); |
| 786 | return; |
| 787 | } |
| 788 | if (!ok) |
| 789 | { |
| 790 | showError('Not found', data.error || 'This link does not exist.'); |
| 791 | return; |
| 792 | } |
| 793 | |
| 794 | expiresAt = data.expiresAt; |
| 795 | startTimer(); |
| 796 | |
| 797 | document.getElementById('file-name').textContent = data.name; |
| 798 | const metaLine = data.isDir ? 'Folder (download as .zip)' : 'File'; |
| 799 | document.getElementById('file-meta').textContent = metaLine; |
| 800 | |
| 801 | const dlBtn = document.getElementById('btn-download'); |
| 802 | dlBtn.href = `/api/share/download/${token}`; |
| 803 | if (data.isDir) |
| 804 | { |
| 805 | document.getElementById('btn-download-label').textContent = 'Download as .zip'; |
| 806 | dlBtn.download = data.name + '.zip'; |
| 807 | } else |
| 808 | { |
| 809 | document.getElementById('btn-download-label').textContent = 'Download'; |
| 810 | dlBtn.download = data.name; |
| 811 | } |
| 812 | |
| 813 | document.getElementById('content').style.display = ''; |
| 814 | |
| 815 | tryPreview(data.name, data.isDir); |
| 816 | }) |
| 817 | .catch(() => |
| 818 | { |
| 819 | showError('Error', 'Could not reach the server.'); |
| 820 | }); |
| 821 | |
| 822 | window.addEventListener('pagehide', cleanupShareVideoPlayer); |
| 823 | window.addEventListener('beforeunload', cleanupShareVideoPlayer); |
| 824 | }()); |
| 825 | </script> |
| 826 | <script src="/vendor/video.js/video.min.js"></script> |
| 827 | </body> |
| 828 | |
| 829 | </html> |