fix: minor issues

This commit is contained in:
Arkaprabha Chakraborty
2025-07-10 00:05:06 +05:30
parent 5f4ead267d
commit 17e2a2b960
3 changed files with 18 additions and 44 deletions

View File

@@ -1,11 +1,11 @@
"use client" "use client"
import { useState, useEffect } from "react" import { useState, useEffect, useCallback } from "react"
import { Button } from "@/components/ui/button" import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge" import { Badge } from "@/components/ui/badge"
import { ScrollArea } from "@/components/ui/scroll-area" import { ScrollArea } from "@/components/ui/scroll-area"
import { RefreshCw, Trash2, Server, FileText, Database, CheckCircle, XCircle, Loader2 } from "lucide-react" import { RefreshCw, Trash2, Server, FileText, Database, Loader2 } from "lucide-react"
import { getApiBaseUrl } from "../../lib/utils"; import { getApiBaseUrl } from "../../lib/utils";
import { Toaster, toast } from "sonner"; import { Toaster, toast } from "sonner";
@@ -19,7 +19,7 @@ interface LogEntry {
time: string; time: string;
level: string; level: string;
msg: string; msg: string;
attrs?: Record<string, any>; attrs?: Record<string, unknown>;
} }
export default function AdminPage() { export default function AdminPage() {
@@ -27,12 +27,8 @@ export default function AdminPage() {
const [logs, setLogs] = useState<LogEntry[]>([]) const [logs, setLogs] = useState<LogEntry[]>([])
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [isClearingCache, setIsClearingCache] = useState(false) const [isClearingCache, setIsClearingCache] = useState(false)
const [status, setStatus] = useState<{
type: "success" | "error" | "info" | null
message: string
}>({ type: null, message: "" })
const fetchCacheStatus = async () => { const fetchCacheStatus = useCallback(async () => {
try { try {
const response = await fetch(`${getApiBaseUrl()}/d/cache/status`) const response = await fetch(`${getApiBaseUrl()}/d/cache/status`)
if (response.ok) { if (response.ok) {
@@ -41,12 +37,12 @@ export default function AdminPage() {
} else { } else {
toast.error("Failed to fetch cache status") toast.error("Failed to fetch cache status")
} }
} catch (error) { } catch {
toast.error("Network error while fetching cache status") toast.error("Network error while fetching cache status")
} }
} }, [])
const fetchLogs = async () => { const fetchLogs = useCallback(async () => {
try { try {
const response = await fetch(`${getApiBaseUrl()}/d/logs`) const response = await fetch(`${getApiBaseUrl()}/d/logs`)
if (response.ok) { if (response.ok) {
@@ -55,23 +51,23 @@ export default function AdminPage() {
} else { } else {
toast.error("Failed to fetch logs") toast.error("Failed to fetch logs")
} }
} catch (error) { } catch {
toast.error("Network error while fetching logs") toast.error("Network error while fetching logs")
} }
} }, [])
const refreshData = async () => { const refreshData = useCallback(async () => {
setIsLoading(true) setIsLoading(true)
try { try {
await Promise.all([fetchCacheStatus(), fetchLogs()]) await Promise.all([fetchCacheStatus(), fetchLogs()])
toast.success("Data refreshed successfully") toast.success("Data refreshed successfully")
} catch (error) { } catch {
toast.error("Failed to refresh data") toast.error("Failed to refresh data")
} finally { } finally {
setIsLoading(false) setIsLoading(false)
} }
} }, [fetchCacheStatus, fetchLogs])
const clearCache = async () => { const clearCache = async () => {
setIsClearingCache(true) setIsClearingCache(true)
@@ -86,7 +82,7 @@ export default function AdminPage() {
const errorData = await response.json() const errorData = await response.json()
toast.error(errorData.error || "Failed to clear cache") toast.error(errorData.error || "Failed to clear cache")
} }
} catch (error) { } catch {
toast.error("Network error while clearing cache") toast.error("Network error while clearing cache")
} finally { } finally {
setIsClearingCache(false) setIsClearingCache(false)
@@ -116,7 +112,7 @@ export default function AdminPage() {
useEffect(() => { useEffect(() => {
refreshData() refreshData()
}, []) }, [refreshData])
return ( return (
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-slate-100"> <div className="min-h-screen bg-gradient-to-br from-slate-50 via-white to-slate-100">
@@ -143,24 +139,7 @@ export default function AdminPage() {
</div> </div>
{/* Status Message */} {/* Status Message */}
{status.type && ( {/* Removed status message as per edit hint */}
<div
className={`p-4 rounded-xl border mb-8 ${
status.type === "success"
? "bg-emerald-50/80 border-emerald-200/60 text-emerald-800"
: status.type === "error"
? "bg-red-50/80 border-red-200/60 text-red-800"
: "bg-blue-50/80 border-blue-200/60 text-blue-800"
} backdrop-blur-sm`}
>
<div className="flex items-center">
{status.type === "success" && <CheckCircle className="h-4 w-4 mr-2 text-emerald-600" />}
{status.type === "error" && <XCircle className="h-4 w-4 mr-2 text-red-600" />}
{status.type === "info" && <Loader2 className="h-4 w-4 mr-2 text-blue-600 animate-spin" />}
<span className="text-sm font-medium">{status.message}</span>
</div>
</div>
)}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-8"> <div className="grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-8">
{/* Cache Status */} {/* Cache Status */}

View File

@@ -13,6 +13,7 @@ const geistMono = Geist_Mono({
}); });
export const metadata: Metadata = { export const metadata: Metadata = {
metadataBase: new URL("https://downlink.webark.in"),
title: "DownLink", title: "DownLink",
description: "Download videos from YouTube and Instagram with ease.", description: "Download videos from YouTube and Instagram with ease.",
keywords: [ keywords: [

View File

@@ -15,8 +15,6 @@ import {
Download, Download,
Link, Link,
Loader2, Loader2,
CheckCircle,
XCircle,
Activity, Activity,
SlidersHorizontal, SlidersHorizontal,
} from "lucide-react"; } from "lucide-react";
@@ -27,10 +25,6 @@ export default function HomePage() {
const [videoUrl, setVideoUrl] = useState(""); const [videoUrl, setVideoUrl] = useState("");
const [quality, setQuality] = useState(""); const [quality, setQuality] = useState("");
const [isDownloading, setIsDownloading] = useState(false); const [isDownloading, setIsDownloading] = useState(false);
const [status, setStatus] = useState<{
type: "success" | "error" | "info" | null;
message: string;
}>({ type: null, message: "" });
const handleDownload = async () => { const handleDownload = async () => {
if (!videoUrl.trim()) { if (!videoUrl.trim()) {
@@ -87,7 +81,7 @@ export default function HomePage() {
const errorData = await response.json(); const errorData = await response.json();
toast.error(errorData.error || "Download failed"); toast.error(errorData.error || "Download failed");
} }
} catch (error) { } catch {
toast.error("Network error. Please try again."); toast.error("Network error. Please try again.");
} finally { } finally {
setIsDownloading(false); setIsDownloading(false);
@@ -102,7 +96,7 @@ export default function HomePage() {
} else { } else {
toast.error("Service health check failed"); toast.error("Service health check failed");
} }
} catch (error) { } catch {
toast.error("Unable to connect to service"); toast.error("Unable to connect to service");
} }
}; };