From 020c57d40c22af6e73281d73c4c2e022e1362dbb Mon Sep 17 00:00:00 2001 From: kevinwatt Date: Thu, 25 Dec 2025 03:32:26 +0800 Subject: [PATCH] fix(validation): check validateUrl return value before proceeding Previously validateUrl() was called but its boolean return value was ignored in audio.ts, metadata.ts, and video.ts. Invalid URLs would pass through and only fail later during yt-dlp execution. Now properly throw 'Invalid or unsupported URL format' error early. --- src/modules/audio.ts | 6 ++++-- src/modules/metadata.ts | 4 +++- src/modules/video.ts | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/audio.ts b/src/modules/audio.ts index 49c114b..6cf540f 100644 --- a/src/modules/audio.ts +++ b/src/modules/audio.ts @@ -31,9 +31,11 @@ import { _spawnPromise, validateUrl, getFormattedTimestamp, isYouTubeUrl } from export async function downloadAudio(url: string, config: Config): Promise { const timestamp = getFormattedTimestamp(); - try { - validateUrl(url); + if (!validateUrl(url)) { + throw new Error("Invalid or unsupported URL format"); + } + try { const outputTemplate = path.join( config.file.downloadsDir, sanitizeFilename(`%(title)s [%(id)s] ${timestamp}`, config.file) + '.%(ext)s' diff --git a/src/modules/metadata.ts b/src/modules/metadata.ts index aadc2a7..cd53cf0 100644 --- a/src/modules/metadata.ts +++ b/src/modules/metadata.ts @@ -151,7 +151,9 @@ export async function getVideoMetadata( _config?: Config ): Promise { // Validate the URL - validateUrl(url); + if (!validateUrl(url)) { + throw new Error("Invalid or unsupported URL format"); + } const args = [ "--dump-json", diff --git a/src/modules/video.ts b/src/modules/video.ts index 44b5a7b..6fbf343 100644 --- a/src/modules/video.ts +++ b/src/modules/video.ts @@ -54,8 +54,11 @@ export async function downloadVideo( ): Promise { const userDownloadsDir = config.file.downloadsDir; + if (!validateUrl(url)) { + throw new Error("Invalid or unsupported URL format"); + } + try { - validateUrl(url); const timestamp = getFormattedTimestamp(); let format: string;