Skip to content

Commit

Permalink
Add revision parameter when building urls (#7)
Browse files Browse the repository at this point in the history
* Add revision parameter when building urls

* Provide default revision value

* Include revision in getMediaURL
  • Loading branch information
jordimas authored Dec 29, 2024
1 parent bc6c01a commit 53a3e23
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function App() {
const [editingTrack, setEditingTrack] = useState<Track | null>(null);
const [advancedEditMode, setAdvancedEditMode] = useState(false);
const [uuidParam, setUuidParam] = useState<string | null>(null);
const [revisionParam, setRevisionParam] = useState<string | null>(null);
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [loadError, setLoadError] = useState<string | null>(null);
const [serviceParam, setServiceParam] = useState<string>('dubbing');
Expand All @@ -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);
Expand All @@ -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');
}
Expand Down Expand Up @@ -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
Expand All @@ -264,15 +270,15 @@ 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([
TranscriptionAPIService.getMediaMetadata(newUuid),
TranscriptionAPIService.loadTracksFromUUID(newUuid)
]);

setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid));
setMediaUrl(TranscriptionAPIService.getMediaUrl(newUuid, revision ?? ''));
setMediaType(videoDataResponse.contentType);
setMediaFileName(videoDataResponse.filename);
setTracks(TranscriptionAPIService.parseTracksFromJSON(tracksDataResponse));
Expand Down Expand Up @@ -389,7 +395,7 @@ function App() {

const handleSubmit = () => {
if (selectedFile) {
handleFileOrUUIDSelect(selectedFile, null);
handleFileOrUUIDSelect(selectedFile, null, null);
}
};

Expand Down Expand Up @@ -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`;
Expand Down
2 changes: 1 addition & 1 deletion src/services/APIServiceInterface.ts
Original file line number Diff line number Diff line change
@@ -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<any>;
parseTracksFromJSON: (json: any) => Track[];
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/DubbingAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const uuidExists = async (uuid: string): Promise<boolean> => {
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 => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/TranscriptionAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 53a3e23

Please sign in to comment.