Skip to content

Commit

Permalink
Download button doesn't work cause of cors
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jul 11, 2024
1 parent 9d983a6 commit 67c576f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/components/audio-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,18 @@ async function fetchWhishperRecording(searchId: string, whishperURL: string) {
}

async function downloadWhishperRecording(url: string, name: string) {
const [recordingUrl, setRecordingUrl] = useState("");
const response = await fetch(url);
if (response.ok) {
const blob = await response.blob();
setRecordingUrl(URL.createObjectURL(blob));
const recordingUrl = URL.createObjectURL(blob);
const link = document.createElement("a");
link.download = name;
link.href = recordingUrl;
link.click();
} else {
console.error("Failed to download");
return null;
}
const link = document.createElement("a");
link.download = name;

link.href = recordingUrl;

link.click();
}

type AudioInfoProps = {
Expand Down Expand Up @@ -197,7 +194,16 @@ function AudioInfo({ id }: AudioInfoProps) {
>
Download
</a>

<Button
onClick={async () => {
await downloadWhishperRecording(
`${userData.whishperURL}/api/video/${recordingData.fileName}`,
recordingData.fileName,
);
}}
>
Download
</Button>
<TooltipProvider delayDuration={50}>
<Tooltip>
<TooltipTrigger asChild>
Expand Down

0 comments on commit 67c576f

Please sign in to comment.