2026-02-25 10:06:50 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2026-03-01 13:08:58 +01:00
|
|
|
import { SliderRow } from '@/components/ui/slider-row';
|
2026-02-25 10:06:50 +01:00
|
|
|
import { FileUpload } from './FileUpload';
|
|
|
|
|
import { ConversionPreview } from './ConversionPreview';
|
|
|
|
|
import { toast } from 'sonner';
|
|
|
|
|
import {
|
|
|
|
|
getFormatByExtension,
|
|
|
|
|
getFormatByMimeType,
|
|
|
|
|
getCompatibleFormats,
|
|
|
|
|
} from '@/lib/media/utils/formatMappings';
|
|
|
|
|
import { convertWithFFmpeg } from '@/lib/media/converters/ffmpegService';
|
|
|
|
|
import { convertWithImageMagick } from '@/lib/media/converters/imagemagickService';
|
|
|
|
|
import { addToHistory } from '@/lib/media/storage/history';
|
|
|
|
|
import { downloadBlobsAsZip, generateOutputFilename } from '@/lib/media/utils/fileUtils';
|
|
|
|
|
import type { ConversionJob, ConversionFormat, ConversionOptions } from '@/types/media';
|
2026-03-01 08:22:17 +01:00
|
|
|
import { ShieldCheck, Download, RotateCcw, Loader2 } from 'lucide-react';
|
|
|
|
|
import { cn } from '@/lib/utils';
|
|
|
|
|
|
|
|
|
|
type MobileTab = 'upload' | 'convert';
|
|
|
|
|
|
|
|
|
|
const actionBtn =
|
|
|
|
|
'flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs glass rounded-md border border-border/30 text-muted-foreground hover:text-primary hover:border-primary/30 hover:bg-primary/10 transition-all disabled:opacity-40 disabled:cursor-not-allowed';
|
2026-02-25 10:06:50 +01:00
|
|
|
|
2026-03-01 13:08:58 +01:00
|
|
|
const selectCls =
|
|
|
|
|
'w-full bg-transparent border border-border/40 rounded-lg px-2.5 py-1.5 text-xs font-mono outline-none focus:border-primary/50 transition-colors text-foreground/80 cursor-pointer disabled:opacity-40';
|
|
|
|
|
|
2026-02-25 10:06:50 +01:00
|
|
|
export function FileConverter() {
|
|
|
|
|
const [selectedFiles, setSelectedFiles] = React.useState<File[]>([]);
|
|
|
|
|
const [inputFormat, setInputFormat] = React.useState<ConversionFormat | undefined>();
|
|
|
|
|
const [outputFormat, setOutputFormat] = React.useState<ConversionFormat | undefined>();
|
|
|
|
|
const [compatibleFormats, setCompatibleFormats] = React.useState<ConversionFormat[]>([]);
|
|
|
|
|
const [conversionJobs, setConversionJobs] = React.useState<ConversionJob[]>([]);
|
|
|
|
|
const [conversionOptions, setConversionOptions] = React.useState<ConversionOptions>({});
|
2026-03-01 08:22:17 +01:00
|
|
|
const [mobileTab, setMobileTab] = React.useState<MobileTab>('upload');
|
2026-02-25 10:06:50 +01:00
|
|
|
const fileInputRef = React.useRef<HTMLInputElement>(null);
|
|
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
// Detect format when files change
|
2026-02-25 10:06:50 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (selectedFiles.length === 0) {
|
|
|
|
|
setInputFormat(undefined);
|
|
|
|
|
setOutputFormat(undefined);
|
|
|
|
|
setCompatibleFormats([]);
|
|
|
|
|
setConversionJobs([]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-01 08:22:17 +01:00
|
|
|
const first = selectedFiles[0];
|
|
|
|
|
const ext = first.name.split('.').pop()?.toLowerCase();
|
|
|
|
|
const fmt = (ext ? getFormatByExtension(ext) : undefined) ?? getFormatByMimeType(first.type);
|
|
|
|
|
if (fmt) {
|
|
|
|
|
setInputFormat(fmt);
|
|
|
|
|
const compat = getCompatibleFormats(fmt);
|
|
|
|
|
setCompatibleFormats(compat);
|
|
|
|
|
if (compat.length > 0 && !outputFormat) setOutputFormat(compat[0]);
|
|
|
|
|
toast.success(`Detected: ${fmt.name} · ${selectedFiles.length} file${selectedFiles.length > 1 ? 's' : ''}`);
|
|
|
|
|
setMobileTab('convert');
|
2026-02-25 10:06:50 +01:00
|
|
|
} else {
|
|
|
|
|
toast.error('Could not detect file format');
|
|
|
|
|
setInputFormat(undefined);
|
|
|
|
|
setCompatibleFormats([]);
|
|
|
|
|
}
|
2026-03-01 08:22:17 +01:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2026-02-25 10:06:50 +01:00
|
|
|
}, [selectedFiles]);
|
|
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
const runConversion = async (
|
|
|
|
|
jobIndex: number,
|
|
|
|
|
jobs: ConversionJob[],
|
|
|
|
|
outFmt: ConversionFormat
|
|
|
|
|
) => {
|
|
|
|
|
const job = jobs[jobIndex];
|
|
|
|
|
const updateJob = (patch: Partial<ConversionJob>) =>
|
|
|
|
|
setConversionJobs((prev) => prev.map((j, i) => (i === jobIndex ? { ...j, ...patch } : j)));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
updateJob({ status: 'loading' });
|
|
|
|
|
updateJob({ status: 'processing', progress: 10 });
|
|
|
|
|
|
|
|
|
|
const onProgress = (progress: number) => updateJob({ progress });
|
|
|
|
|
const result =
|
|
|
|
|
outFmt.converter === 'ffmpeg'
|
|
|
|
|
? await convertWithFFmpeg(job.inputFile, outFmt.extension, conversionOptions, onProgress)
|
|
|
|
|
: await convertWithImageMagick(job.inputFile, outFmt.extension, conversionOptions, onProgress);
|
|
|
|
|
|
|
|
|
|
if (result.success && result.blob) {
|
|
|
|
|
updateJob({ status: 'completed', progress: 100, result: result.blob, endTime: Date.now() });
|
|
|
|
|
addToHistory({
|
|
|
|
|
inputFileName: job.inputFile.name,
|
|
|
|
|
inputFormat: job.inputFormat.name,
|
|
|
|
|
outputFormat: outFmt.name,
|
|
|
|
|
outputFileName: generateOutputFilename(job.inputFile.name, outFmt.extension),
|
|
|
|
|
fileSize: result.blob.size,
|
|
|
|
|
result: result.blob,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
updateJob({ status: 'error', error: result.error || 'Unknown error', endTime: Date.now() });
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
updateJob({ status: 'error', error: err instanceof Error ? err.message : 'Unknown error', endTime: Date.now() });
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-25 10:06:50 +01:00
|
|
|
const handleConvert = async () => {
|
2026-03-01 08:22:17 +01:00
|
|
|
if (!selectedFiles.length || !inputFormat || !outputFormat) {
|
|
|
|
|
toast.error('Please select files and an output format');
|
2026-02-25 10:06:50 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const jobs: ConversionJob[] = selectedFiles.map((file) => ({
|
2026-03-01 08:22:17 +01:00
|
|
|
id: Math.random().toString(36).slice(2, 9),
|
2026-02-25 10:06:50 +01:00
|
|
|
inputFile: file,
|
2026-03-01 08:22:17 +01:00
|
|
|
inputFormat: inputFormat!,
|
2026-02-25 10:06:50 +01:00
|
|
|
outputFormat,
|
|
|
|
|
options: conversionOptions,
|
|
|
|
|
status: 'pending',
|
|
|
|
|
progress: 0,
|
|
|
|
|
startTime: Date.now(),
|
|
|
|
|
}));
|
|
|
|
|
setConversionJobs(jobs);
|
|
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
let ok = 0;
|
2026-02-25 10:06:50 +01:00
|
|
|
for (let i = 0; i < jobs.length; i++) {
|
2026-03-01 08:22:17 +01:00
|
|
|
const success = await runConversion(i, jobs, outputFormat);
|
|
|
|
|
if (success) ok++;
|
2026-02-25 10:06:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
if (ok === jobs.length) toast.success(`All ${jobs.length} file${jobs.length > 1 ? 's' : ''} converted!`);
|
|
|
|
|
else if (ok > 0) toast.info(`${ok}/${jobs.length} files converted`);
|
|
|
|
|
else toast.error('All conversions failed');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRetry = async (jobId: string) => {
|
|
|
|
|
const idx = conversionJobs.findIndex((j) => j.id === jobId);
|
|
|
|
|
if (idx === -1 || !outputFormat) return;
|
|
|
|
|
setConversionJobs((prev) =>
|
|
|
|
|
prev.map((j, i) =>
|
|
|
|
|
i === idx ? { ...j, status: 'loading', progress: 0, error: undefined, startTime: Date.now() } : j
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
const success = await runConversion(idx, conversionJobs, outputFormat);
|
|
|
|
|
if (success) toast.success('Conversion completed!');
|
|
|
|
|
else toast.error('Retry failed');
|
2026-02-25 10:06:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleReset = () => {
|
|
|
|
|
setSelectedFiles([]);
|
|
|
|
|
setInputFormat(undefined);
|
|
|
|
|
setOutputFormat(undefined);
|
|
|
|
|
setCompatibleFormats([]);
|
|
|
|
|
setConversionJobs([]);
|
|
|
|
|
setConversionOptions({});
|
2026-03-01 08:22:17 +01:00
|
|
|
setMobileTab('upload');
|
2026-02-25 10:06:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDownloadAll = async () => {
|
|
|
|
|
if (!outputFormat) return;
|
2026-03-01 08:22:17 +01:00
|
|
|
const done = conversionJobs.filter((j) => j.status === 'completed' && j.result);
|
|
|
|
|
if (!done.length) { toast.error('No completed files'); return; }
|
|
|
|
|
if (done.length === 1) {
|
|
|
|
|
const url = URL.createObjectURL(done[0].result!);
|
2026-02-25 10:06:50 +01:00
|
|
|
const a = document.createElement('a');
|
|
|
|
|
a.href = url;
|
2026-03-01 08:22:17 +01:00
|
|
|
a.download = generateOutputFilename(done[0].inputFile.name, outputFormat.extension);
|
2026-02-25 10:06:50 +01:00
|
|
|
a.click();
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-03-01 08:22:17 +01:00
|
|
|
await downloadBlobsAsZip(
|
|
|
|
|
done.map((j) => ({ blob: j.result!, filename: generateOutputFilename(j.inputFile.name, outputFormat.extension) })),
|
|
|
|
|
'converted-files.zip'
|
|
|
|
|
);
|
|
|
|
|
toast.success(`Downloaded ${done.length} files as ZIP`);
|
2026-02-25 10:06:50 +01:00
|
|
|
};
|
|
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
const isConverting = conversionJobs.some((j) => j.status === 'loading' || j.status === 'processing');
|
|
|
|
|
const completedCount = conversionJobs.filter((j) => j.status === 'completed').length;
|
|
|
|
|
const setOpt = (patch: Partial<ConversionOptions>) =>
|
|
|
|
|
setConversionOptions((prev) => ({ ...prev, ...patch }));
|
2026-02-25 10:06:50 +01:00
|
|
|
|
|
|
|
|
return (
|
2026-03-01 08:22:17 +01:00
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
|
|
|
|
|
|
{/* ── Mobile tab switcher ─────────────────────────────── */}
|
|
|
|
|
<div className="flex lg:hidden glass rounded-xl p-1 gap-1">
|
|
|
|
|
{(['upload', 'convert'] as MobileTab[]).map((t) => (
|
|
|
|
|
<button
|
|
|
|
|
key={t}
|
|
|
|
|
onClick={() => setMobileTab(t)}
|
|
|
|
|
className={cn(
|
|
|
|
|
'flex-1 py-2.5 rounded-lg text-sm font-medium capitalize transition-all',
|
|
|
|
|
mobileTab === t
|
|
|
|
|
? 'bg-primary text-primary-foreground shadow-sm'
|
|
|
|
|
: 'text-muted-foreground hover:text-foreground'
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{t === 'upload' ? 'Upload' : 'Convert'}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* ── Main layout ─────────────────────────────────────── */}
|
|
|
|
|
<div
|
|
|
|
|
className="grid grid-cols-1 lg:grid-cols-5 gap-4"
|
2026-03-01 16:05:14 +01:00
|
|
|
style={{ height: 'calc(100svh - 120px)' }}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
|
|
|
|
|
|
|
|
|
{/* Left: upload zone */}
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
'lg:col-span-2 flex flex-col overflow-hidden',
|
|
|
|
|
mobileTab !== 'upload' && 'hidden lg:flex'
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="glass rounded-xl p-4 flex flex-col flex-1 min-h-0 overflow-hidden">
|
|
|
|
|
<div className="flex items-center justify-between mb-3 shrink-0">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">
|
|
|
|
|
Upload
|
|
|
|
|
</span>
|
|
|
|
|
<span className="flex items-center gap-1 text-[10px] text-emerald-400/60 font-mono">
|
|
|
|
|
<ShieldCheck className="w-3 h-3" />
|
|
|
|
|
Zero uploads
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-02-25 19:59:22 +01:00
|
|
|
<FileUpload
|
2026-03-01 08:22:17 +01:00
|
|
|
onFileSelect={(files) => setSelectedFiles((prev) => [...prev, ...files])}
|
|
|
|
|
onFileRemove={(i) => setSelectedFiles((prev) => prev.filter((_, idx) => idx !== i))}
|
2026-02-25 19:59:22 +01:00
|
|
|
selectedFiles={selectedFiles}
|
2026-02-25 10:06:50 +01:00
|
|
|
disabled={isConverting}
|
2026-02-25 19:59:22 +01:00
|
|
|
inputRef={fileInputRef}
|
|
|
|
|
inputFormat={inputFormat}
|
2026-02-25 10:06:50 +01:00
|
|
|
/>
|
2026-03-01 08:22:17 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right: options + results */}
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
'lg:col-span-3 flex flex-col gap-3 overflow-hidden',
|
|
|
|
|
mobileTab !== 'convert' && 'hidden lg:flex'
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{inputFormat && compatibleFormats.length > 0 ? (
|
|
|
|
|
<div className="glass rounded-xl p-4 shrink-0">
|
|
|
|
|
{/* Detected format */}
|
|
|
|
|
<div className="flex items-center justify-between mb-3">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">
|
|
|
|
|
Output Format
|
|
|
|
|
</span>
|
|
|
|
|
{inputFormat && (
|
|
|
|
|
<span className="px-2 py-0.5 rounded-md bg-primary/10 text-primary text-[10px] font-mono border border-primary/20">
|
|
|
|
|
{inputFormat.name}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Format pill grid */}
|
|
|
|
|
<div className="flex flex-wrap gap-1.5 mb-4">
|
|
|
|
|
{compatibleFormats.map((fmt) => (
|
|
|
|
|
<button
|
|
|
|
|
key={fmt.id}
|
|
|
|
|
onClick={() => setOutputFormat(fmt)}
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
className={cn(
|
|
|
|
|
'px-2.5 py-1 rounded-lg border text-xs font-mono transition-all',
|
|
|
|
|
outputFormat?.id === fmt.id
|
|
|
|
|
? 'bg-primary/10 border-primary/40 text-primary'
|
|
|
|
|
: 'border-border/30 text-muted-foreground hover:border-primary/30 hover:text-foreground',
|
|
|
|
|
isConverting && 'opacity-40 cursor-not-allowed'
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
.{fmt.extension}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
2026-02-25 19:59:22 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{outputFormat && (
|
|
|
|
|
<>
|
2026-03-01 08:22:17 +01:00
|
|
|
<div className="border-t border-border/25 pt-3 space-y-3">
|
|
|
|
|
|
|
|
|
|
{/* Video options */}
|
|
|
|
|
{outputFormat.category === 'video' && (
|
|
|
|
|
<>
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">Video Codec</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.videoCodec || 'default'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ videoCodec: e.target.value === 'default' ? undefined : e.target.value })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="default">Auto (Recommended)</option>
|
|
|
|
|
<option value="libx264">H.264</option>
|
|
|
|
|
<option value="libx265">H.265</option>
|
|
|
|
|
<option value="libvpx">VP8 (WebM)</option>
|
|
|
|
|
<option value="libvpx-vp9">VP9 (WebM)</option>
|
|
|
|
|
</select>
|
2026-02-25 19:59:22 +01:00
|
|
|
</div>
|
2026-03-01 08:22:17 +01:00
|
|
|
|
2026-03-01 13:08:58 +01:00
|
|
|
<SliderRow
|
|
|
|
|
label="Video Bitrate"
|
|
|
|
|
display={conversionOptions.videoBitrate || '2M'}
|
|
|
|
|
value={parseFloat(conversionOptions.videoBitrate?.replace('M', '') || '2')}
|
|
|
|
|
min={0.5} max={10} step={0.5}
|
|
|
|
|
onChange={(v) => setOpt({ videoBitrate: `${v}M` })}
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
/>
|
2026-03-01 08:22:17 +01:00
|
|
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">Resolution</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.videoResolution || 'original'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ videoResolution: e.target.value === 'original' ? undefined : e.target.value })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="original">Original</option>
|
|
|
|
|
<option value="1920x-1">1080p</option>
|
|
|
|
|
<option value="1280x-1">720p</option>
|
|
|
|
|
<option value="854x-1">480p</option>
|
|
|
|
|
<option value="640x-1">360p</option>
|
|
|
|
|
</select>
|
2026-03-01 08:22:17 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">FPS</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.videoFps?.toString() || 'original'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ videoFps: e.target.value === 'original' ? undefined : parseInt(e.target.value) })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="original">Original</option>
|
|
|
|
|
<option value="60">60 fps</option>
|
|
|
|
|
<option value="30">30 fps</option>
|
|
|
|
|
<option value="24">24 fps</option>
|
|
|
|
|
<option value="15">15 fps</option>
|
|
|
|
|
</select>
|
2026-03-01 08:22:17 +01:00
|
|
|
</div>
|
2026-02-25 19:59:22 +01:00
|
|
|
</div>
|
2026-03-01 08:22:17 +01:00
|
|
|
|
2026-03-01 13:08:58 +01:00
|
|
|
<SliderRow
|
|
|
|
|
label="Audio Bitrate"
|
|
|
|
|
display={conversionOptions.audioBitrate || '128k'}
|
|
|
|
|
value={parseInt(conversionOptions.audioBitrate?.replace('k', '') || '128')}
|
|
|
|
|
min={64} max={320} step={32}
|
|
|
|
|
onChange={(v) => setOpt({ audioBitrate: `${v}k` })}
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
/>
|
2026-03-01 08:22:17 +01:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Audio options */}
|
|
|
|
|
{outputFormat.category === 'audio' && (
|
|
|
|
|
<>
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">Codec</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.audioCodec || 'default'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ audioCodec: e.target.value === 'default' ? undefined : e.target.value })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="default">Auto</option>
|
|
|
|
|
<option value="libmp3lame">MP3 (LAME)</option>
|
|
|
|
|
<option value="aac">AAC</option>
|
|
|
|
|
<option value="libvorbis">Vorbis</option>
|
|
|
|
|
<option value="libopus">Opus</option>
|
|
|
|
|
<option value="flac">FLAC</option>
|
|
|
|
|
</select>
|
2026-02-25 19:59:22 +01:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-01 13:08:58 +01:00
|
|
|
<SliderRow
|
|
|
|
|
label="Bitrate"
|
|
|
|
|
display={conversionOptions.audioBitrate || '192k'}
|
|
|
|
|
value={parseInt(conversionOptions.audioBitrate?.replace('k', '') || '192')}
|
|
|
|
|
min={64} max={320} step={32}
|
|
|
|
|
onChange={(v) => setOpt({ audioBitrate: `${v}k` })}
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
/>
|
2026-02-25 19:59:22 +01:00
|
|
|
|
2026-03-01 08:22:17 +01:00
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">Sample Rate</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.audioSampleRate?.toString() || 'original'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ audioSampleRate: e.target.value === 'original' ? undefined : parseInt(e.target.value) })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="original">Original</option>
|
|
|
|
|
<option value="48000">48 kHz</option>
|
|
|
|
|
<option value="44100">44.1 kHz</option>
|
|
|
|
|
<option value="22050">22 kHz</option>
|
|
|
|
|
</select>
|
2026-03-01 08:22:17 +01:00
|
|
|
</div>
|
|
|
|
|
<div className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">Channels</span>
|
2026-03-01 13:08:58 +01:00
|
|
|
<select
|
2026-03-01 08:22:17 +01:00
|
|
|
value={conversionOptions.audioChannels?.toString() || 'original'}
|
2026-03-01 13:08:58 +01:00
|
|
|
onChange={(e) => setOpt({ audioChannels: e.target.value === 'original' ? undefined : parseInt(e.target.value) })}
|
2026-03-01 08:22:17 +01:00
|
|
|
disabled={isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={selectCls}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
2026-03-01 13:08:58 +01:00
|
|
|
<option value="original">Original</option>
|
|
|
|
|
<option value="2">Stereo</option>
|
|
|
|
|
<option value="1">Mono</option>
|
|
|
|
|
</select>
|
2026-03-01 08:22:17 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Image options */}
|
|
|
|
|
{outputFormat.category === 'image' && (
|
|
|
|
|
<>
|
2026-03-01 13:08:58 +01:00
|
|
|
<SliderRow
|
|
|
|
|
label="Quality"
|
|
|
|
|
display={`${conversionOptions.imageQuality ?? 85}%`}
|
|
|
|
|
value={conversionOptions.imageQuality ?? 85}
|
|
|
|
|
min={1} max={100} step={1}
|
|
|
|
|
onChange={(v) => setOpt({ imageQuality: v })}
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
/>
|
2026-03-01 08:22:17 +01:00
|
|
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-2">
|
|
|
|
|
{(['imageWidth', 'imageHeight'] as const).map((key) => (
|
|
|
|
|
<div key={key} className="space-y-1.5">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">
|
|
|
|
|
{key === 'imageWidth' ? 'Width (px)' : 'Height (px)'}
|
|
|
|
|
</span>
|
|
|
|
|
<input
|
|
|
|
|
type="number"
|
|
|
|
|
value={conversionOptions[key] ?? ''}
|
|
|
|
|
onChange={(e) => setOpt({ [key]: e.target.value ? parseInt(e.target.value) : undefined })}
|
|
|
|
|
placeholder="Original"
|
|
|
|
|
disabled={isConverting}
|
|
|
|
|
className="w-full bg-transparent border border-border/40 rounded-lg px-2.5 py-1.5 text-xs font-mono outline-none focus:border-primary/50 transition-colors placeholder:text-muted-foreground/30 disabled:opacity-40"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Action buttons */}
|
|
|
|
|
<div className="flex gap-2 mt-4 pt-3 border-t border-border/25">
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleConvert}
|
|
|
|
|
disabled={!selectedFiles.length || !outputFormat || isConverting}
|
2026-03-01 13:08:58 +01:00
|
|
|
className={cn(actionBtn, 'flex-1 py-2')}
|
2026-03-01 08:22:17 +01:00
|
|
|
>
|
|
|
|
|
{isConverting
|
|
|
|
|
? <><Loader2 className="w-3 h-3 animate-spin" />Converting…</>
|
|
|
|
|
: `Convert ${selectedFiles.length} file${selectedFiles.length !== 1 ? 's' : ''}`
|
|
|
|
|
}
|
|
|
|
|
</button>
|
|
|
|
|
<button onClick={handleReset} className={actionBtn} title="Reset">
|
|
|
|
|
<RotateCcw className="w-3 h-3" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
/* No files yet — right panel placeholder */
|
|
|
|
|
<div className="glass rounded-xl p-4 flex flex-col items-center justify-center flex-1 min-h-0 text-center">
|
|
|
|
|
<div className="w-12 h-12 rounded-full bg-primary/8 flex items-center justify-center mb-3">
|
|
|
|
|
<ShieldCheck className="w-5 h-5 text-primary/30" />
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-xs text-muted-foreground/30 font-mono">
|
|
|
|
|
Upload files to see conversion options
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Results panel */}
|
|
|
|
|
{conversionJobs.length > 0 && (
|
|
|
|
|
<div className="glass rounded-xl p-3 flex flex-col flex-1 min-h-0 overflow-hidden">
|
|
|
|
|
<div className="flex items-center justify-between mb-3 shrink-0">
|
|
|
|
|
<span className="text-[10px] font-semibold text-muted-foreground uppercase tracking-widest">
|
|
|
|
|
Results
|
|
|
|
|
</span>
|
|
|
|
|
{completedCount > 0 && (
|
|
|
|
|
<button onClick={handleDownloadAll} className={actionBtn}>
|
|
|
|
|
<Download className="w-3 h-3" />
|
|
|
|
|
{completedCount > 1 ? `Download all (${completedCount}) as ZIP` : 'Download'}
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1 min-h-0 overflow-y-auto scrollbar-thin scrollbar-thumb-primary/20 scrollbar-track-transparent space-y-2 pr-0.5">
|
|
|
|
|
{conversionJobs.map((job) => (
|
|
|
|
|
<ConversionPreview
|
|
|
|
|
key={job.id}
|
|
|
|
|
job={job}
|
|
|
|
|
onRetry={() => handleRetry(job.id)}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-02-25 19:59:22 +01:00
|
|
|
</div>
|
2026-02-25 10:06:50 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|