Skip to content

Commit 53a3e23

Browse files
authored
Add revision parameter when building urls (#7)
* Add revision parameter when building urls * Provide default revision value * Include revision in getMediaURL
1 parent bc6c01a commit 53a3e23

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/App.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function App() {
137137
const [editingTrack, setEditingTrack] = useState<Track | null>(null);
138138
const [advancedEditMode, setAdvancedEditMode] = useState(false);
139139
const [uuidParam, setUuidParam] = useState<string | null>(null);
140+
const [revisionParam, setRevisionParam] = useState<string | null>(null);
140141
const [selectedFile, setSelectedFile] = useState<File | null>(null);
141142
const [loadError, setLoadError] = useState<string | null>(null);
142143
const [serviceParam, setServiceParam] = useState<string>('dubbing');
@@ -163,6 +164,7 @@ function App() {
163164
useEffect(() => {
164165
const params = new URLSearchParams(window.location.search);
165166
const uuidParam = params.get('uuid');
167+
const revisionParam = params.get('revision');
166168
const serviceParam = params.get('service') as 'dubbing' | 'transcription' | null;
167169
if (serviceParam) {
168170
setAppMode(serviceParam);
@@ -172,9 +174,13 @@ function App() {
172174

173175
console.log("Initial useEffect - UUID param:", uuidParam, "Service param:", serviceParam, "App mode:", appMode);
174176

177+
if (revisionParam) {
178+
setRevisionParam(revisionParam);
179+
}
180+
175181
if (uuidParam) {
176182
setUuidParam(uuidParam);
177-
handleFileOrUUIDSelect(null, uuidParam);
183+
handleFileOrUUIDSelect(null, uuidParam, revisionParam);
178184
} else {
179185
setLoadError('errorLoadingUUID');
180186
}
@@ -241,7 +247,7 @@ function App() {
241247
i18n.changeLanguage(event.target.value);
242248
};
243249

244-
const handleFileOrUUIDSelect = useCallback(async (file: File | null, newUuid: string | null) => {
250+
const handleFileOrUUIDSelect = useCallback(async (file: File | null, newUuid: string | null, revision: string | null) => {
245251
console.log("handleFileOrUUIDSelect called with UUID:", newUuid);
246252

247253
// Revoke existing object URL if there is one
@@ -264,15 +270,15 @@ function App() {
264270
await DubbingAPIService.uuidExists(newUuid);
265271

266272
// Set initial video URL
267-
setMediaUrl(DubbingAPIService.getMediaUrl(newUuid));
273+
setMediaUrl(DubbingAPIService.getMediaUrl(newUuid, revision ?? ''));
268274
setMediaType('video/mp4');
269275
} else if (serviceParam === "transcription") {
270276
const [videoDataResponse, tracksDataResponse] = await Promise.all([
271277
TranscriptionAPIService.getMediaMetadata(newUuid),
272278
TranscriptionAPIService.loadTracksFromUUID(newUuid)
273279
]);
274280

275-
setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid));
281+
setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid, revision ?? ''));
276282
setMediaType(videoDataResponse.contentType);
277283
setMediaFileName(videoDataResponse.filename);
278284
setTracks(TranscriptionAPIService.parseTracksFromJSON(tracksDataResponse));
@@ -389,7 +395,7 @@ function App() {
389395

390396
const handleSubmit = () => {
391397
if (selectedFile) {
392-
handleFileOrUUIDSelect(selectedFile, null);
398+
handleFileOrUUIDSelect(selectedFile, null, null);
393399
}
394400
};
395401

@@ -546,8 +552,9 @@ function App() {
546552
const handleSimpleDownload = () => {
547553
const params = new URLSearchParams(window.location.search);
548554
const uuid = params.get('uuid');
555+
const revision = params.get('revision') ?? '';
549556
if (uuid) {
550-
const url = DubbingAPIService.getMediaUrl(uuid);
557+
const url = DubbingAPIService.getMediaUrl(uuid, revision);
551558
const a = document.createElement('a');
552559
a.href = url;
553560
a.download = `dubbed_video.mp4`;

src/services/APIServiceInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Track } from "../types/Track";
22

33
export interface APIServiceInterface {
4-
getMediaUrl: (uuid: string) => string;
4+
getMediaUrl: (uuid: string, revision: string) => string;
55
loadTracksFromUUID: (uuid: string) => Promise<any>;
66
parseTracksFromJSON: (json: any) => Track[];
77
}

src/services/DubbingAPIService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const uuidExists = async (uuid: string): Promise<boolean> => {
3737
return response.json();
3838
};
3939

40-
export const getMediaUrl = (uuid: string): string => {
41-
return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=dub`;
40+
export const getMediaUrl = (uuid: string, revision: string): string => {
41+
return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=dub&revision=${revision}`;
4242
};
4343

4444
export const getSilentVideoUrl = (uuid: string): string => {

src/services/TranscriptionAPIService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const API_BASE_URL =
66
process.env.TRANSCRIPTION_API_BASE_URL ||
77
"https://api.softcatala.org/transcribe-service/v1";
88

9-
export const getMediaUrl = (uuid: string): string => {
9+
export const getMediaUrl = (uuid: string, revision: string): string => {
1010
return `${API_BASE_URL}/get_file/?uuid=${uuid}&ext=bin`;
1111
};
1212

1313
export const getMediaMetadata = async (
1414
uuid: string
1515
): Promise<{ contentType: string; filename: string }> => {
16-
const response = await fetch(getMediaUrl(uuid), { method: "HEAD" });
16+
const response = await fetch(getMediaUrl(uuid, ""), { method: "HEAD" });
1717
if (!response.ok) {
1818
throw new Error("Failed to load video");
1919
}

0 commit comments

Comments
 (0)