diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 6a4d652..efcd7d6 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -164,6 +164,25 @@ export async function fetchSegments( return res.json(); } +/** Last ned SRT-fil for en media-node. Trigger filnedlasting i nettleseren. */ +export async function downloadSrt(accessToken: string, nodeId: string): Promise { + const res = await fetch( + `${BASE_URL}/query/segments/srt?node_id=${encodeURIComponent(nodeId)}`, + { headers: { Authorization: `Bearer ${accessToken}` } } + ); + if (!res.ok) { + const body = await res.text(); + throw new Error(`SRT-eksport feilet (${res.status}): ${body}`); + } + const blob = await res.blob(); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'transcription.srt'; + a.click(); + URL.revokeObjectURL(url); +} + /** Oppdater teksten i et transkripsjons-segment. */ export function updateSegment( accessToken: string, diff --git a/frontend/src/lib/components/TranscriptionView.svelte b/frontend/src/lib/components/TranscriptionView.svelte index 73ee5ef..c2a0c29 100644 --- a/frontend/src/lib/components/TranscriptionView.svelte +++ b/frontend/src/lib/components/TranscriptionView.svelte @@ -4,6 +4,7 @@ updateSegment, fetchTranscriptionVersions, retranscribe, + downloadSrt, type Segment, type TranscriptionVersion } from '$lib/api'; @@ -168,6 +169,14 @@ polling = false; } + async function handleDownloadSrt() { + try { + await downloadSrt(accessToken, nodeId); + } catch (e) { + console.error('SRT-nedlasting feilet:', e); + } + } + function handleComparisonDone() { showCompare = false; loadSegments(nodeId, accessToken); @@ -227,6 +236,20 @@ Sammenlign versjoner {/if} +