"use client"
import {useMutation, useQuery} from "@tanstack/react-query"
import {ExternalLink, RefreshCw, Sparkles} from "lucide-react"
import {toast} from "sonner"
import services from "@/lib/services"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger
} from "@/components/ui/alert-dialog"
import {Badge} from "@/components/ui/badge"
import {Button} from "@/components/ui/button"
import {Card, CardContent, CardDescription, CardHeader, CardTitle} from "@/components/ui/card"
import {Spinner} from "@/components/ui/spinner"
function InfoRow({ label, value }: { label: string; value: React.ReactNode }) {
return (
{label}
{value || "-"}
)
}
export function InfoTab() {
const updateQuery = useQuery({
queryKey: ["admin", "update"],
queryFn: () => services.adminStatus.getUpdateStatus(),
refetchInterval: 30 * 60 * 1000,
staleTime: 5 * 60 * 1000,
})
const applyUpdateMutation = useMutation({
mutationFn: () => services.adminStatus.applyUpdate(),
onSuccess: () => {
toast.success("升级包已校验完成,服务正在重启")
},
onError: (error: Error) => {
toast.error(error.message || "应用升级失败")
},
})
const update = updateQuery.data
return (
应用更新
检查上游 GitHub Actions Release 并升级当前服务
{update?.update_available ? (
发现新版本
) : update ? (
已是最新
) : null}
{updateQuery.isLoading ? (
) : updateQuery.isError ? (
{updateQuery.error.message || "无法获取上游版本信息"}
) : update ? (
<>
{update.build_time && }
{update.release_notes && (
更新说明
{update.release_notes}
)}
{update.release_url && (
)}
升级到 {update.latest_version}?
服务将下载并校验 {update.asset_name},随后替换当前二进制并重启。请确保安装目录可写,且服务允许原地重启。
取消
applyUpdateMutation.mutate()}>
确认升级
{!update.can_upgrade && (
{update.current_version === "dev"
? "开发构建没有可比较的 Release 版本,不能执行自动升级。"
: update.update_available
? "当前平台暂不支持自动替换二进制,请从 Release 页面手动升级。"
: "当前版本无需升级。"}
)}
>
) : null}
)
}