Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add /recordings/<id> deep links that pre-select the recording and keep the URL in sync for shareable links (#301)
Murtaza Nasire6aaf09fd5fb
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex 579187a1..1aeb0e46 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -1372,8 +1372,11 @@ def reset_status(recording_id):@recordings_bp.route('/')+@recordings_bp.route('/recordings/<int:recording_id>')@login_required-def index():+def index(recording_id=None):+ # recording_id is a deep link (#301): the server just serves the SPA shell+ # here; the frontend reads it from the path and pre-selects the recording.# Check if user is a group adminis_team_admin = GroupMembership.query.filter_by(user_id=current_user.id,diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex 2a991b48..b12f6db4 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -3267,6 +3267,19 @@ document.addEventListener('DOMContentLoaded', async () => {}});+ // Keep the address bar in sync with the open recording so links are+ // shareable/bookmarkable (#301). replaceState avoids history spam;+ // the path is only changed (query + hash preserved). Incognito (id+ // 'incognito') and the list view map back to '/'.+ watch(selectedRecording, (rec) => {+ try {+ const path = (rec && typeof rec.id === 'number') ? `/recordings/${rec.id}` : '/';+ if (window.location.pathname !== path) {+ window.history.replaceState({}, '', path + window.location.search + window.location.hash);+ }+ } catch (_) { /* best-effort */ }+ });+watch(sortBy, (newValue) => {localStorage.setItem('recordingsSortBy', newValue);recordingsComposable.loadRecordings(1, false, searchQuery.value);@@ -3564,6 +3577,14 @@ document.addEventListener('DOMContentLoaded', async () => {}} catch (_) { /* no-op: param parsing/replaceState are best-effort */ }+ // Deep link to a specific recording: /recordings/<id> (#301).+ // Captured before load; selected once recordings are in.+ let deepLinkRecordingId = null;+ try {+ const m = window.location.pathname.match(/^\/recordings\/(\d+)\/?$/);+ if (m) deepLinkRecordingId = m[1];+ } catch (_) { /* best-effort */ }+// Load initial dataawait Promise.all([recordingsComposable.loadRecordings(),@@ -3579,6 +3600,9 @@ document.addEventListener('DOMContentLoaded', async () => {if (wantUploadDeepLink) {await nextTick();uiComposable.switchToUploadView();+ } else if (deepLinkRecordingId) {+ // Honour the /recordings/<id> deep link now that data is loaded.+ await recordingsComposable.selectRecordingById(deepLinkRecordingId);}// Clean up orphaned incognito data if we're not viewing incognito recordingdiff --git a/static/js/modules/composables/recordings.js b/static/js/modules/composables/recordings.jsindex cc6e1aae..60e6a11f 100644--- a/static/js/modules/composables/recordings.js+++ b/static/js/modules/composables/recordings.js@@ -287,6 +287,27 @@ export function useRecordings(state, utils, reprocessComposable) {}};+ // Select a recording by ID, used by the /recordings/<id> deep link (#301).+ // Resolves from the loaded list when possible, otherwise fetches it so the+ // target works even when it isn't on the current page or is a shared one.+ // Returns true if the recording was found and selected.+ const selectRecordingById = async (id) => {+ if (id == null) return false;+ const existing = recordings.value.find(r => String(r.id) === String(id));+ if (existing) {+ await selectRecording(existing);+ return true;+ }+ try {+ const resp = await fetch(`/api/recordings/${id}`);+ if (resp.ok) {+ await selectRecording(await resp.json());+ return true;+ }+ } catch (_) { /* unknown / inaccessible id — stay on the list */ }+ return false;+ };+const hasUnsavedRecording = () => {return isRecording.value || audioBlobURL.value;};@@ -483,6 +504,7 @@ export function useRecordings(state, utils, reprocessComposable) {loadFolders,loadSpeakers,selectRecording,+ selectRecordingById,hasUnsavedRecording,toggleInbox,toggleHighlight,