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
Some checks are pending
CI / test (push) Waiting to run
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user