"use client"; import { useState, useEffect } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Badge } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; import { motion } from "framer-motion"; import { ExternalLink, GitCommit } from "lucide-react"; export default function ApiDocsComponent() { const [activePage, setActivePage] = useState("home"); const [imageCount, setImageCount] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { setLoading(true); try { const [imageCountResponse] = await Promise.all([ fetch("/?api=total-pic") ]); const imageCountData = await imageCountResponse.json(); setImageCount(imageCountData.count); } catch (error) { console.error("Failed to fetch data:", error); setImageCount(null); } finally { setLoading(false); } }; fetchData(); }, []); const apiEndpoints = [ { id: 1, device: "手机", method: "GET", url: "/phone", description: "竖屏随机图片API", }, { id: 2, device: "电脑", method: "GET", url: "/pc", description: "横屏随机图片API", }, { id: 3, device: "All", method: "GET", url: "/favicon", description: "获取本站favicon", }, { id: 4, device: "All", method: "GET", url: "/bj", description: "获取静态页面装饰图", }, { id: 5, device: "All", method: "GET", url: "/fox", description: "获取狐狸图", }, ]; const parameters = [ { id: 1, param: "time", value: "Boolean", description: "是否区分时段,默认为false", }, { id: 2, param: "mode", value: "String", description: "填json则返回一串数组;填redirect则会重定向至图片URL;不填则返回一张图片", }, { id: 3, param: "source", value: "Boolean", description: "是否使用原图(加载较慢),默认为true", }, ]; const returnData = [ { id: 1, data: "code", description: "状态码" }, { id: 2, data: "image_url", description: "图片地址" }, { id: 3, data: "time", description: "是否分时段" }, { id: 4, data: "endpoint_type", description: "适用设备" }, { id: 5, data: "is_source", description: "是否为原图" }, { id: 6, data: "mode", description: "输出模式" }, ]; const friendlyLinks = [ { name: "mei的网络日志", url: "https://mei.lv" } ]; const HomePage = () => ( 网站简介

欢迎使用{" "} Cat API , 由 mei 开发并维护。

用于实践我最新学到的技术,也能勉强保证服务可用性(但被打了可扛不住)。

站点公告
2024-10-03

目前API已由无数据库的屎山代码重构为使用 Mysql 的高性能代码

友情链接
{friendlyLinks.map((link, index) => ( {link.name} ))}
); const RandomImagePage = () => ( 随机图片 API

此 API 提供随机二次元图片,不定期更新!

图片总数:{" "} {loading ? ( ) : ( {imageCount !== null ? imageCount : "获取失败"} )}

API 地址 参数列表 返回数据 # 适用设备 请求方式 请求地址 说明 {apiEndpoints.map((endpoint) => ( {endpoint.id} {endpoint.device} {endpoint.method} {endpoint.url} {endpoint.description} ))}
# 参数 说明 {parameters.map((param) => ( {param.id} {param.param} {param.value} {param.description} ))}
# 数据 说明 {returnData.map((data) => ( {data.id} {data.data} {data.description} ))}
); return (
{activePage === "home" ? : }
); }