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:
parent
bbda4d2857
commit
020c57d40c
@ -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'
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user