From 35701aeb2a0c6af1deefad2f74ef0b73d8da356e Mon Sep 17 00:00:00 2001 From: vegard Date: Tue, 17 Mar 2026 18:47:50 +0100 Subject: [PATCH] =?UTF-8?q?Fullf=C3=B8r=20oppgave=207.8:=20SRT-eksport=20f?= =?UTF-8?q?ra=20transkripsjons-segmenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nytt GET /query/segments/srt-endepunkt som genererer nedlastbar SRT-fil fra transcription_segments-tabellen. Bruker RLS-verifisert tilgang. Frontend har nedlastingsknapp i TranscriptionView med autentisert fetch. Co-Authored-By: Claude Opus 4.6 --- frontend/src/lib/api.ts | 19 +++ .../lib/components/TranscriptionView.svelte | 23 +++ maskinrommet/src/main.rs | 1 + maskinrommet/src/queries.rs | 145 ++++++++++++++++++ tasks.md | 3 +- 5 files changed, 189 insertions(+), 2 deletions(-) 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} +