Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If media urls missing http/https protocol then add https protocol. #127

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`;
};
Loading