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.
This commit is contained in:
kevinwatt 2025-12-25 03:32:26 +08:00
parent bbda4d2857
commit 020c57d40c
3 changed files with 11 additions and 4 deletions

View File

@ -31,9 +31,11 @@ import { _spawnPromise, validateUrl, getFormattedTimestamp, isYouTubeUrl } from
export async function downloadAudio(url: string, config: Config): Promise<string> {
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'

View File

@ -151,7 +151,9 @@ export async function getVideoMetadata(
_config?: Config
): Promise<string> {
// Validate the URL
validateUrl(url);
if (!validateUrl(url)) {
throw new Error("Invalid or unsupported URL format");
}
const args = [
"--dump-json",

View File

@ -54,8 +54,11 @@ export async function downloadVideo(
): Promise<string> {
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;