Skip to content

Commit

Permalink
If media urls missing http/https protocol then add https protocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmcmahon committed Jan 30, 2025
1 parent 12df2ba commit 7ed1568
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/client/src/components/UploadForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { authFetch } from '@/helpers';
import { addHttpsProtocol, authFetch } from '@/helpers';
import React, { useContext, useState } from 'react';
import {
SignedUrlResponseBody,
Expand Down Expand Up @@ -134,7 +134,8 @@ const checkUrlValid = (url_input: string): MediaUrlInput => {
if (url_input === '') {
return { value: url_input, status: 'empty' };
}
const url = new URL(url_input);
const cleanedUrlInput = addHttpsProtocol(url_input);
const url = new URL(cleanedUrlInput);
// we don't want people providing search results pages as yt-dlp will try and fetch every video
if (
url.pathname.includes('results') &&
Expand Down Expand Up @@ -223,8 +224,9 @@ export const UploadForm = () => {
);
setMediaUrls(urlsWithStatus);
for (const url of urls) {
const urlWithProtocol = addHttpsProtocol(url);
const success = await submitMediaUrl(
url,
urlWithProtocol,
token,
mediaFileLanguageCode,
translationRequested,
Expand Down Expand Up @@ -300,8 +302,8 @@ export const UploadForm = () => {
return (
<>
<p className={' pb-3 font-light'}>
This tool can transcribe both audio and video. You will receive an
email when the transcription is ready.
This tool can transcribe both audio and video. You will receive an email
when the transcription is ready.
</p>
<form id="media-upload-form" onSubmit={handleSubmit}>
<div className={'mb-1'}>
Expand Down
6 changes: 6 additions & 0 deletions packages/client/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ export const authFetch = async (

return await fetch(request);
};

export const addHttpsProtocol = (url: string) => {
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
} else return `https://${url}`;
};

0 comments on commit 7ed1568

Please sign in to comment.