From 4506a1b3de1ef583ced2126f5362c441a1c9f0e8 Mon Sep 17 00:00:00 2001 From: teahubxyz Date: Thu, 22 Oct 2026 18:30:30 +0000 Subject: [PATCH] plugins/webamp: self-host the Webamp bundle webamp@1.5.0 ships no .mjs build, so the unpkg import 404'd (seen in the browser as a CORS error). Load the UMD bundle served from Teahub's own assets instead; bump cache key to v=011. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HLEj1MiGohaV4qJE4NE1Xq --- plugins/webamp/plugin.json | 5 ++++- .../public/assets/plugins/webamp/webamp-mod.js | 17 ++++++++++++++--- plugins/webamp/templates/custom/footer.tmpl | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/plugins/webamp/plugin.json b/plugins/webamp/plugin.json index d644739..6d8cf1b 100644 --- a/plugins/webamp/plugin.json +++ b/plugins/webamp/plugin.json @@ -1,12 +1,15 @@ { "name": "webamp", "title": "Webamp", - "version": "0.1.0", + "version": "0.1.1", "description": "A Winamp-style player on every Teahub page, fed by gandora.", "slots": { "footer": "templates/custom/footer.tmpl" }, "assets": ["public/assets/plugins/webamp/webamp-mod.js"], + "vendor": { + "public/assets/plugins/webamp/webamp.bundle.min.js": "https://registry.npmjs.org/webamp/-/webamp-1.5.0.tgz#package/built/webamp.bundle.min.js" + }, "config": { "playlist_url": "https://gandora.yolopreneur.lol/playlist.json" } diff --git a/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js b/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js index 931b9c8..71b0860 100644 --- a/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js +++ b/plugins/webamp/public/assets/plugins/webamp/webamp-mod.js @@ -1,7 +1,7 @@ // teahub plugin: webamp — a Winamp-style player docked on every Teahub page. -// Loads Webamp from the CDN on first click, so pages stay fast for everyone else. +// Loads the self-hosted Webamp bundle on first click, so pages stay fast for everyone else. -// Module scripts have no document.currentScript, so find our tag by its data attribute. +// Module scripts have no document.currentScript, so find our tag by its src. const script = document.querySelector('script[src*="plugins/webamp/webamp-mod.js"]'); const PLAYLIST_URL = script?.dataset.playlist; const KEY = 'teahub-webamp-open'; @@ -36,9 +36,20 @@ async function loadTracks() { let webamp = null; +function loadWebamp() { + if (window.Webamp) return Promise.resolve(window.Webamp); + return new Promise((ok, fail) => { + const s = document.createElement('script'); + s.src = new URL('webamp.bundle.min.js', import.meta.url).href; + s.onload = () => ok(window.Webamp); + s.onerror = fail; + document.head.appendChild(s); + }); +} + async function open() { if (webamp) return; - const { default: Webamp } = await import('https://unpkg.com/webamp@1.5.0/built/webamp.bundle.min.mjs'); + const Webamp = await loadWebamp(); if (!Webamp.browserIsSupported()) return; webamp = new Webamp({ initialTracks: await loadTracks() }); webamp.onClose(() => { diff --git a/plugins/webamp/templates/custom/footer.tmpl b/plugins/webamp/templates/custom/footer.tmpl index 770cec0..4a97501 100644 --- a/plugins/webamp/templates/custom/footer.tmpl +++ b/plugins/webamp/templates/custom/footer.tmpl @@ -1,2 +1,2 @@ {{/* teahub plugin: webamp */}} - +