Remove useless helper
All checks were successful
Bump deps (only minor versions) / ci (push) Successful in 21s

This commit is contained in:
0d0 2025-02-23 06:37:13 +01:00
parent 5d0fa4e951
commit 6f93574e8a
2 changed files with 7 additions and 16 deletions

View file

@ -11,12 +11,3 @@ export const isURLValid = (url: string) => {
return true;
}
export const mimeTypeMap = formatMime;
export const contentTypeFromFormat = (format: string): string => {
const toReturn: string | undefined = formatMime.get(format)
if (!toReturn) {
throw new Error("Unsupported format")
}
return toReturn;
}

View file

@ -1,9 +1,9 @@
import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getYouTubeMetadata, streamYouTube, ytdl } from '$lib/server/ytdlp';
import { contentTypeFromFormat, isURLValid, mimeTypeMap } from '$lib/server/helpers';
import { isURLValid, mimeTypeMap } from '$lib/server/helpers';
const validateRequest = (url) => {
const validateRequest = (url: URL) => {
// Get query params
const link = url.searchParams.get('link');
const format = url.searchParams.get('format'); // mp3, mp4
@ -35,11 +35,11 @@ export const GET: RequestHandler = async ({ url }) => {
const { format, source, metadata, link } = validateRequest(url)
let filename = `you-clicked-no-metadata-so-i-cant-put-a-correct-name.${format}`;
if (metadata) {
if (!!metadata) {
try {
// Fetch metadata for filename
const metadata = await getYouTubeMetadata(link);
const { title, uploader } = metadata;
const ytMetadata = await getYouTubeMetadata(link);
const { title, uploader } = ytMetadata;
const safeTitle = `${uploader} - ${title}`;
filename = `${safeTitle}.${format}`;
} catch (err) {
@ -54,7 +54,7 @@ export const GET: RequestHandler = async ({ url }) => {
// Stream video/audio
return new Response(streamYouTube(link, format), {
headers: {
'Content-Type': contentTypeFromFormat(format),
'Content-Type': "text/event-stream",
'Content-Disposition': `attachment; filename="${filename}"`,
'Set-Cookie': 'downloading=0'
}