From 938c4f5fae7ba0016942cd30ff2e93b41b174f24 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 6 Oct 2024 23:59:36 -0300 Subject: [PATCH] Cache-bust MP3 content --- src/html/main/surah-stream.html.erb | 3 ++- src/js/components/AudioControl.tsx | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/html/main/surah-stream.html.erb b/src/html/main/surah-stream.html.erb index c0a861c..13c3f1c 100644 --- a/src/html/main/surah-stream.html.erb +++ b/src/html/main/surah-stream.html.erb @@ -23,7 +23,8 @@ <%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
+ data-audio-base-url="<%= audio_base_url %>" + data-commit-id="<%= commit %>">
diff --git a/src/js/components/AudioControl.tsx b/src/js/components/AudioControl.tsx index d7cd0c2..e5719d5 100644 --- a/src/js/components/AudioControl.tsx +++ b/src/js/components/AudioControl.tsx @@ -23,6 +23,7 @@ export function AudioControl({ const [enabled, setEnabled] = useState(false); const [audioStatus, setAudioStatus] = useState>(null); const [audioBaseUrl, setAudioBaseUrl] = useState>(null); + const [commitId, setCommitId] = useState>(null); const play = (audio: HTMLAudioElement) => audio.play().catch(() => null); const pause = (audio: HTMLAudioElement) => audio.pause(); @@ -31,7 +32,7 @@ export function AudioControl({ return; } if (enabled) { - audio.src = [audioBaseUrl, surah.id, `${ayah.id}.mp3`].join("/"); + audio.src = [audioBaseUrl, surah.id, `${ayah.id}.mp3?v=${commitId}`].join("/"); play(audio); } }, [hidden, enabled, ayah?.id, audioBaseUrl]); @@ -41,8 +42,10 @@ export function AudioControl({ "[data-audio-base-url]", ); const url = el?.dataset?.audioBaseUrl; + const commit = el?.dataset?.commitId if (url?.length) { setAudioBaseUrl(url); + setCommitId(commit); } else { console.warn("audio.base_url is not set"); }