"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Card, CardContent } from "@/components/ui/card"; import { Download, Link, Loader2, Activity, SlidersHorizontal, } from "lucide-react"; import { getApiBaseUrl } from "../lib/utils"; import { Toaster, toast } from "sonner"; export default function HomePage() { const [videoUrl, setVideoUrl] = useState(""); const [quality, setQuality] = useState(""); const [isDownloading, setIsDownloading] = useState(false); const handleDownload = async () => { if (!videoUrl.trim()) { toast.error("Please enter a video URL"); return; } if (!quality) { toast.error("Please select a quality"); return; } setIsDownloading(true); try { const response = await fetch(`${getApiBaseUrl()}/d/download`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ url: videoUrl, quality: quality, }), }); if (response.ok) { const contentType = response.headers.get("content-type"); if (contentType && (contentType.includes("application/octet-stream") || contentType.includes("video/mp4"))) { const blob = await response.blob(); const url = window.URL.createObjectURL(blob); // Try to get filename from Content-Disposition header const contentDisposition = response.headers.get("content-disposition"); let filename = `video_${quality}.mp4`; if (contentDisposition) { const match = contentDisposition.match(/filename="?([^";]+)"?/); if (match && match[1]) { filename = match[1]; } } const a = document.createElement("a"); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); document.body.removeChild(a); toast.success("Download completed successfully!"); } else { const data = await response.json(); toast.success(data.message || "Download initiated successfully!"); } } else { const errorData = await response.json(); toast.error(errorData.error || "Download failed"); } } catch { toast.error("Network error. Please try again."); } finally { setIsDownloading(false); } }; const checkHealth = async () => { try { const response = await fetch(`${getApiBaseUrl()}/d/`); if (response.ok) { toast.success("Service is healthy and running!"); } else { toast.error("Service health check failed"); } } catch { toast.error("Unable to connect to service"); } }; return (
{/* Header */}

DownLink

Download Your Links With Ease

{/* Main Card */}
{/* URL Input */}
setVideoUrl(e.target.value)} className="h-12 bg-slate-50/80 border-slate-200/60 rounded-xl text-slate-900 placeholder:text-slate-500 focus:bg-white focus:border-slate-300 transition-all duration-200" />
{/* Quality Selector */}
{/* Download Button */}
{/* Health Check */}
); }