"use client"; import { useParams, notFound } from "next/navigation"; import Link from "next/link"; import { useEffect, useState } from "react"; import { Card, Badge } from "@/shared/components"; import ProviderIcon from "@/shared/components/ProviderIcon"; import { MEDIA_PROVIDER_KINDS, AI_PROVIDERS, getProvidersByKind } from "@/shared/constants/providers"; function getEffectiveStatus(conn) { const isCooldown = Object.entries(conn).some( ([k, v]) => k.startsWith("modelLock_") && v && new Date(v).getTime() > Date.now() ); return conn.testStatus === "unavailable" && !isCooldown ? "active" : conn.testStatus; } function MediaProviderCard({ provider, kind, connections }) { const providerInfo = AI_PROVIDERS[provider.id]; const isNoAuth = !!providerInfo?.noAuth; const providerConns = connections.filter((c) => c.provider === provider.id); const connected = providerConns.filter((c) => { const s = getEffectiveStatus(c); return s === "active" || s === "success"; }).length; const error = providerConns.filter((c) => { const s = getEffectiveStatus(c); return s === "error" || s === "expired" || s === "unavailable"; }).length; const total = providerConns.length; const allDisabled = total > 0 && providerConns.every((c) => c.isActive === false); const renderStatus = () => { if (isNoAuth) return Ready; if (allDisabled) return Disabled; if (total === 0) return No connections; return ( <> {connected > 0 && {connected} Connected} {error > 0 && {error} Error} {connected === 0 && error === 0 && {total} Added} ); }; return (
7 ? provider.color : (provider.color ?? "#888") + "15"}` }} >

{provider.name}

{renderStatus()}
); } export default function MediaProviderKindPage() { const { kind } = useParams(); const [connections, setConnections] = useState([]); const kindConfig = MEDIA_PROVIDER_KINDS.find((k) => k.id === kind); if (!kindConfig) return notFound(); const providers = getProvidersByKind(kind); useEffect(() => { fetch("/api/providers", { cache: "no-store" }) .then((r) => r.json()) .then((d) => setConnections(d.connections || [])) .catch(() => {}); }, []); return (
{providers.length === 0 ? (
No providers support {kindConfig.label} yet.
) : (
{providers.map((provider) => ( ))}
)}
); }