Implement testing framework with Vitest, add unit tests for API routes and utility functions, and configure CI workflow for automated testing. Update package dependencies for testing libraries and add test scripts to package.json.
Some checks are pending
CI / test (push) Waiting to run

This commit is contained in:
2025-12-22 12:50:35 -06:00
parent f92b73c7db
commit c7e7d63be5
16 changed files with 3110 additions and 35 deletions

View File

@@ -1,33 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';
import { downloadVideo } from '@/lib/youtube';
import { isValidYouTubeUrl } from '@/lib/utils';
import type { DownloadRequest, AudioFormat, VideoFormat, FormatType } from '@/lib/types';
import { getMimeType } from '@/lib/mime';
import type { DownloadRequest } from '@/lib/types';
import { createReadStream } from 'fs';
import { stat } from 'fs/promises';
import path from 'path';
import { Readable } from 'stream';
const VIDEO_MIME: Record<VideoFormat, string> = {
mp4: 'video/mp4',
webm: 'video/webm',
mkv: 'video/x-matroska',
avi: 'video/x-msvideo',
};
const AUDIO_MIME: Record<AudioFormat, string> = {
mp3: 'audio/mpeg',
wav: 'audio/wav',
m4a: 'audio/mp4',
opus: 'audio/ogg',
};
function getMimeType(formatType: FormatType, format: VideoFormat | AudioFormat): string {
if (formatType === 'video') {
return VIDEO_MIME[format as VideoFormat] || 'application/octet-stream';
}
return AUDIO_MIME[format as AudioFormat] || 'application/octet-stream';
}
async function resolveDownloadPath(downloadUrl: string) {
const sanitized = downloadUrl.startsWith('/') ? downloadUrl.slice(1) : downloadUrl;
const filePath = path.join(process.cwd(), 'public', sanitized);