Cache-bust MP3 content

This commit is contained in:
0x1eef 2024-10-06 23:59:36 -03:00
parent bfec7a8069
commit 938c4f5fae
2 changed files with 6 additions and 2 deletions

View file

@ -23,7 +23,8 @@
<%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %> <%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
<div class="app mount root" <div class="app mount root"
data-surah-id="<%= context.surah.id %>" data-surah-id="<%= context.surah.id %>"
data-audio-base-url="<%= audio_base_url %>"> data-audio-base-url="<%= audio_base_url %>"
data-commit-id="<%= commit %>">
</div> </div>
<script src="/js/loaders/surah-stream-loader.js?v=<%= commit %>"></script> <script src="/js/loaders/surah-stream-loader.js?v=<%= commit %>"></script>
</body> </body>

View file

@ -23,6 +23,7 @@ export function AudioControl({
const [enabled, setEnabled] = useState<boolean>(false); const [enabled, setEnabled] = useState<boolean>(false);
const [audioStatus, setAudioStatus] = useState<Maybe<TAudioStatus>>(null); const [audioStatus, setAudioStatus] = useState<Maybe<TAudioStatus>>(null);
const [audioBaseUrl, setAudioBaseUrl] = useState<Maybe<string>>(null); const [audioBaseUrl, setAudioBaseUrl] = useState<Maybe<string>>(null);
const [commitId, setCommitId] = useState<Maybe<string>>(null);
const play = (audio: HTMLAudioElement) => audio.play().catch(() => null); const play = (audio: HTMLAudioElement) => audio.play().catch(() => null);
const pause = (audio: HTMLAudioElement) => audio.pause(); const pause = (audio: HTMLAudioElement) => audio.pause();
@ -31,7 +32,7 @@ export function AudioControl({
return; return;
} }
if (enabled) { if (enabled) {
audio.src = [audioBaseUrl, surah.id, `${ayah.id}.mp3`].join("/"); audio.src = [audioBaseUrl, surah.id, `${ayah.id}.mp3?v=${commitId}`].join("/");
play(audio); play(audio);
} }
}, [hidden, enabled, ayah?.id, audioBaseUrl]); }, [hidden, enabled, ayah?.id, audioBaseUrl]);
@ -41,8 +42,10 @@ export function AudioControl({
"[data-audio-base-url]", "[data-audio-base-url]",
); );
const url = el?.dataset?.audioBaseUrl; const url = el?.dataset?.audioBaseUrl;
const commit = el?.dataset?.commitId
if (url?.length) { if (url?.length) {
setAudioBaseUrl(url); setAudioBaseUrl(url);
setCommitId(commit);
} else { } else {
console.warn("audio.base_url is not set"); console.warn("audio.base_url is not set");
} }