From 25fe3ceca13593ae48f33a2e3136b53c68088f86 Mon Sep 17 00:00:00 2001 From: CenTdemeern1 Date: Wed, 16 Oct 2024 02:48:48 +0200 Subject: [PATCH] Use esm.sh instead of unpkg as Ruffle CDN This way admins don't have to change their content security policy --- packages/frontend/src/components/SkFlashPlayer.vue | 10 +++++----- packages/frontend/src/index.html | 4 ++-- packages/frontend/vite.config.local-dev.ts | 2 +- packages/frontend/vite.config.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/components/SkFlashPlayer.vue b/packages/frontend/src/components/SkFlashPlayer.vue index c5d57d97c6..aa6dfdc642 100644 --- a/packages/frontend/src/components/SkFlashPlayer.vue +++ b/packages/frontend/src/components/SkFlashPlayer.vue @@ -95,18 +95,18 @@ function handleError(error: unknown) { } /** - * @throws if unpkg shits itself + * @throws if esm.sh shits itself */ async function loadRuffle() { if (window.RufflePlayer !== undefined) return; loadingStatus.value = 'Loading Ruffle player'; - await import('@ruffle-rs/ruffle'); // Assumption: this will throw if unpkg has a hiccup or something. If not, the next undefined check will catch it. + await import('@ruffle-rs/ruffle'); // Assumption: this will throw if esm.sh has a hiccup or something. If not, the next undefined check will catch it. window.RufflePlayer = window.RufflePlayer as PublicAPILike | PublicAPI | undefined; // Assert unknown type due to side effects - if (window.RufflePlayer === undefined) throw Error('unpkg has shit itself, but not in an expected way (has unpkg permanently shut down? how close is the heat death of the universe?)'); + if (window.RufflePlayer === undefined) throw Error('esm.sh has shit itself, but not in an expected way (has esm.sh permanently shut down? how close is the heat death of the universe?)'); window.RufflePlayer.config = { // Options affecting the whole page - 'publicPath': `https://unpkg.com/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/`, + 'publicPath': `https://esm.sh/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/`, 'polyfills': false, // Options affecting files only @@ -153,7 +153,7 @@ function createPlayer() { const ruffleAPI = (window.RufflePlayer as PublicAPI).newest(); if (ruffleAPI === null) { // This error exists because non-null assertions are forbidden, apparently. - throw Error('Ruffle could not get the latest Ruffle source. Since we\'re loading from unpkg this is genuinely impossible and you must\'ve done something incredibly cursed.'); + throw Error('Ruffle could not get the latest Ruffle source. Since we\'re loading from esm.sh this is genuinely impossible and you must\'ve done something incredibly cursed.'); } return ruffleAPI; })(); diff --git a/packages/frontend/src/index.html b/packages/frontend/src/index.html index 31dfc292d7..55d6b6cffd 100644 --- a/packages/frontend/src/index.html +++ b/packages/frontend/src/index.html @@ -18,11 +18,11 @@ http-equiv="Content-Security-Policy" content="default-src 'self' https://newassets.hcaptcha.com/ https://challenges.cloudflare.com/ http://localhost:7493/; worker-src 'self' blob:; - script-src 'self' 'unsafe-eval' https://*.hcaptcha.com https://challenges.cloudflare.com https://esm.sh https://cdn.jsdelivr.net https://unpkg.com; + script-src 'self' 'unsafe-eval' https://*.hcaptcha.com https://challenges.cloudflare.com https://esm.sh https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: www.google.com xn--931a.moe localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 activitypub.software secure.gravatar.com avatars.githubusercontent.com; media-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000; - connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 https://newassets.hcaptcha.com https://api.listenbrainz.org https://api.friendlycaptcha.com https://unpkg.com; + connect-src 'self' localhost:3000 localhost:5173 127.0.0.1:5173 127.0.0.1:3000 https://newassets.hcaptcha.com https://api.listenbrainz.org https://api.friendlycaptcha.com; frame-src *;" /> diff --git a/packages/frontend/vite.config.local-dev.ts b/packages/frontend/vite.config.local-dev.ts index d9bef48f0f..91667405a8 100644 --- a/packages/frontend/vite.config.local-dev.ts +++ b/packages/frontend/vite.config.local-dev.ts @@ -33,7 +33,7 @@ const externalPackages = [ path(id: string, pattern: RegExp): string { const match = pattern.exec(id)?.groups; return match - ? `https://unpkg.com/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}` + ? `https://esm.sh/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}` : id; }, }, diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index ede464ac2f..ae66106e6c 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -35,7 +35,7 @@ const externalPackages = [ path(id: string, pattern: RegExp): string { const match = pattern.exec(id)?.groups; return match - ? `https://unpkg.com/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}` + ? `https://esm.sh/@ruffle-rs/ruffle@${packageInfo.dependencies['@ruffle-rs/ruffle']}/${match['file']}` : id; }, },