From 53a3e237df2e3d734b6156266a496f451160acd9 Mon Sep 17 00:00:00 2001 From: Jordi Mas Date: Sun, 29 Dec 2024 10:21:19 +0100 Subject: [PATCH] Add revision parameter when building urls (#7) * Add revision parameter when building urls * Provide default revision value * Include revision in getMediaURL --- src/App.tsx | 19 +++++++++++++------ src/services/APIServiceInterface.ts | 2 +- src/services/DubbingAPIService.ts | 4 ++-- src/services/TranscriptionAPIService.ts | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index dff3864..4dd573c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -137,6 +137,7 @@ function App() { const [editingTrack, setEditingTrack] = useState(null); const [advancedEditMode, setAdvancedEditMode] = useState(false); const [uuidParam, setUuidParam] = useState(null); + const [revisionParam, setRevisionParam] = useState(null); const [selectedFile, setSelectedFile] = useState(null); const [loadError, setLoadError] = useState(null); const [serviceParam, setServiceParam] = useState('dubbing'); @@ -163,6 +164,7 @@ function App() { useEffect(() => { const params = new URLSearchParams(window.location.search); const uuidParam = params.get('uuid'); + const revisionParam = params.get('revision'); const serviceParam = params.get('service') as 'dubbing' | 'transcription' | null; if (serviceParam) { setAppMode(serviceParam); @@ -172,9 +174,13 @@ function App() { console.log("Initial useEffect - UUID param:", uuidParam, "Service param:", serviceParam, "App mode:", appMode); + if (revisionParam) { + setRevisionParam(revisionParam); + } + if (uuidParam) { setUuidParam(uuidParam); - handleFileOrUUIDSelect(null, uuidParam); + handleFileOrUUIDSelect(null, uuidParam, revisionParam); } else { setLoadError('errorLoadingUUID'); } @@ -241,7 +247,7 @@ function App() { i18n.changeLanguage(event.target.value); }; - const handleFileOrUUIDSelect = useCallback(async (file: File | null, newUuid: string | null) => { + const handleFileOrUUIDSelect = useCallback(async (file: File | null, newUuid: string | null, revision: string | null) => { console.log("handleFileOrUUIDSelect called with UUID:", newUuid); // Revoke existing object URL if there is one @@ -264,7 +270,7 @@ function App() { await DubbingAPIService.uuidExists(newUuid); // Set initial video URL - setMediaUrl(DubbingAPIService.getMediaUrl(newUuid)); + setMediaUrl(DubbingAPIService.getMediaUrl(newUuid, revision ?? '')); setMediaType('video/mp4'); } else if (serviceParam === "transcription") { const [videoDataResponse, tracksDataResponse] = await Promise.all([ @@ -272,7 +278,7 @@ function App() { TranscriptionAPIService.loadTracksFromUUID(newUuid) ]); - setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid)); + setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid, revision ?? '')); setMediaType(videoDataResponse.contentType); setMediaFileName(videoDataResponse.filename); setTracks(TranscriptionAPIService.parseTracksFromJSON(tracksDataResponse)); @@ -389,7 +395,7 @@ function App() { const handleSubmit = () => { if (selectedFile) { - handleFileOrUUIDSelect(selectedFile, null); + handleFileOrUUIDSelect(selectedFile, null, null); } }; @@ -546,8 +552,9 @@ function App() { const handleSimpleDownload = () => { const params = new URLSearchParams(window.location.search); const uuid = params.get('uuid'); + const revision = params.get('revision') ?? ''; if (uuid) { - const url = DubbingAPIService.getMediaUrl(uuid); + const url = DubbingAPIService.getMediaUrl(uuid, revision); const a = document.createElement('a'); a.href = url; a.download = `dubbed_video.mp4`; diff --git a/src/services/APIServiceInterface.ts b/src/services/APIServiceInterface.ts index 1f82006..2eb9617 100644 --- a/src/services/APIServiceInterface.ts +++ b/src/services/APIServiceInterface.ts @@ -1,7 +1,7 @@ import { Track } from "../types/Track"; export interface APIServiceInterface { - getMediaUrl: (uuid: string) => string; + getMediaUrl: (uuid: string, revision: string) => string; loadTracksFromUUID: (uuid: string) => Promise; parseTracksFromJSON: (json: any) => Track[]; } diff --git a/src/services/DubbingAPIService.ts b/src/services/DubbingAPIService.ts index d4e4923..718ac2a 100644 --- a/src/services/DubbingAPIService.ts +++ b/src/services/DubbingAPIService.ts @@ -37,8 +37,8 @@ export const uuidExists = async (uuid: string): Promise => { return response.json(); }; -export const getMediaUrl = (uuid: string): string => { - return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=dub`; +export const getMediaUrl = (uuid: string, revision: string): string => { + return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=dub&revision=${revision}`; }; export const getSilentVideoUrl = (uuid: string): string => { diff --git a/src/services/TranscriptionAPIService.ts b/src/services/TranscriptionAPIService.ts index 4b6366d..e8d0cdb 100644 --- a/src/services/TranscriptionAPIService.ts +++ b/src/services/TranscriptionAPIService.ts @@ -6,14 +6,14 @@ const API_BASE_URL = process.env.TRANSCRIPTION_API_BASE_URL || "https://api.softcatala.org/transcribe-service/v1"; -export const getMediaUrl = (uuid: string): string => { +export const getMediaUrl = (uuid: string, revision: string): string => { return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=bin`; }; export const getMediaMetadata = async ( uuid: string ): Promise<{ contentType: string; filename: string }> => { - const response = await fetch(getMediaUrl(uuid), { method: "HEAD" }); + const response = await fetch(getMediaUrl(uuid, ""), { method: "HEAD" }); if (!response.ok) { throw new Error("Failed to load video"); }