← Commit history

adom-video: stream /render/ videos through the files API (it answers Range with 206, so the timeline seeks)

John Lauer ·5b1b30b61a ·7d ago ·parent ce1ca85
1 file changed +13−1
widgets/video-widget.js+13−1
@@ -277,6 +277,18 @@      // absolute URL for a wiki path (the frame is opaque-origin, so resolve against the real location)     _abs(u) { try { return new URL(u, location.href).href; } catch { return u; } }+    // the page render route answers a video's Range requests with the whole file (200), which makes it+    // unseekable; the files API answers 206, so stream /OWNER/SLUG/render/PATH from there+    _media(u) {+      const a = this._abs(u);+      try {+        const url = new URL(a);+        if (url.hostname !== 'wiki.adom.inc' && url.origin !== location.origin) return a;+        const m = url.pathname.match(/^\/([^/]+)\/([^/]+)\/render\/(.+)$/);+        if (m) url.pathname = `/api/pages/${m[1]}/${m[2]}/files/${m[3]}`;+        return url.href;+      } catch { return a; }+    }      // a JSON manifest (the wiki inlines a registered tag's `src` file as a child script):     // { "video": "...", "title", "poster", "chapters": [{t,title}] or a path, "captions": a path or WebVTT text }@@ -301,7 +313,7 @@       v.loop = this.hasAttribute('loop');       v.muted = this.hasAttribute('muted');       this._startAt = parseT(this.getAttribute('start') || (location.hash.match(/[#&]t=([^&]+)/) || [])[1]);-      v.src = this._abs(src);+      v.src = this._media(src);       v.addEventListener('loadedmetadata', () => {         if (v.videoWidth && !this.p.classList.contains('page')) this.p.style.aspectRatio = `${v.videoWidth} / ${v.videoHeight}`;         if (this._startAt > 0 && this._startAt < v.duration) { v.currentTime = this._startAt; this._started(); }