Changeset 21522ae in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
05/20/2026 10:14:01 PM (4 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
353c39c
Parents:
46f23fd
git-author:
Robin Genis <roboburr@…> (05/20/2026 10:13:26 PM)
git-committer:
Robin Genis <roboburr@…> (05/20/2026 10:14:01 PM)
Message:

audio: Spotify-style blob playback + same-origin gate (fix playback loop)

Root cause of the "next-loops-but-never-plays after 4-5 songs" bug: every
track URL was HMAC-signed once at page-render time with a 10-min TTL. A whole
queue shared that single deadline, so tracks further down expired mid-session
-> /audio/stream returned 403 -> audio 'error' -> auto-skip -> next track also
expired -> infinite loop. The 3-strike guard never fired because the eager
'play' event reset the counter before each 403 landed.

Removed the expiring-token system entirely and replaced it with two
non-expiring layers:

  • Client fetch()es track bytes and plays from a blob: object URL (no shareable URL, no "save audio as"); blobs revoked to avoid leaks; loadSeq guards fast prev/next; pre-seed is metadata-only (no auto-download).
  • Server gates /audio/stream to same-origin browser fetches (X-Audio-Player header or Sec-Fetch-Site): blocks address-bar paste, hotlinks, curl.

Also: reset error counter on real 'playing' event (not eager 'play') so the
3-strike auto-skip-stop actually works; fix admin play-state detection to
compare logical currentTrack().url instead of the now-blob: audio.src; bump
audio-player.js cache-buster v5.

Co-Authored-By: Claude Opus 4.7 <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    r46f23fd r21522ae  
    1313import AudioEmbedService from '../services/AudioEmbedService.js';
    1414import PlaylistService from '../services/PlaylistService.js';
    15 import { signUrl } from '../services/AudioStreamService.js';
     15import { audioUrl } from '../services/AudioStreamService.js';
    1616
    1717const __dirname = path.dirname(fileURLToPath(import.meta.url));
     
    419419          artist: r.artist,
    420420          cover: r.cover_url,
    421           url: signUrl(r.filename).url,
     421          url: audioUrl(r.filename),
    422422        };
    423423      });
     
    439439        if (!byAlbum.has(r.album)) byAlbum.set(r.album, []);
    440440        byAlbum.get(r.album).push({
    441           url: signUrl(r.filename).url,
     441          url: audioUrl(r.filename),
    442442          title: r.title || 'Untitled',
    443443          artist: r.artist || '',
     
    464464      const isAdmin = req.session?.user?.role === 'god';
    465465      html = AudioEmbedService.embedPlaylistShortcodes(html, (id) => {
    466         return PlaylistService.get(site.id, id, signUrl);
     466        return PlaylistService.get(site.id, id, audioUrl);
    467467      }, { isAdmin });
    468468    }
Note: See TracChangeset for help on using the changeset viewer.