Compare commits
No commits in common. "main" and "v0.1" have entirely different histories.
@ -20,20 +20,27 @@ import { ExternalLink, GitCommit } from "lucide-react";
|
|||||||
export default function ApiDocsComponent() {
|
export default function ApiDocsComponent() {
|
||||||
const [activePage, setActivePage] = useState("home");
|
const [activePage, setActivePage] = useState("home");
|
||||||
const [imageCount, setImageCount] = useState<number | null>(null);
|
const [imageCount, setImageCount] = useState<number | null>(null);
|
||||||
|
const [announcements, setAnnouncements] = useState<
|
||||||
|
Array<{ date: string; content: string }>
|
||||||
|
>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const [imageCountResponse] = await Promise.all([
|
const [imageCountResponse, announcementsResponse] = await Promise.all([
|
||||||
fetch("/?api=total-pic")
|
fetch("/?api=total-pic"),
|
||||||
|
fetch("/?api=announcements"),
|
||||||
]);
|
]);
|
||||||
const imageCountData = await imageCountResponse.json();
|
const imageCountData = await imageCountResponse.json();
|
||||||
|
const announcementsData = await announcementsResponse.json();
|
||||||
setImageCount(imageCountData.count);
|
setImageCount(imageCountData.count);
|
||||||
|
setAnnouncements(announcementsData.announcements);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch data:", error);
|
console.error("Failed to fetch data:", error);
|
||||||
setImageCount(null);
|
setImageCount(null);
|
||||||
|
setAnnouncements([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@ -112,7 +119,7 @@ export default function ApiDocsComponent() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const friendlyLinks = [
|
const friendlyLinks = [
|
||||||
{ name: "mei的网络日志", url: "https://mei.lv" }
|
{ name: "mei的网络日志", url: "https://mmeiblog.cn" }
|
||||||
];
|
];
|
||||||
|
|
||||||
const HomePage = () => (
|
const HomePage = () => (
|
||||||
@ -137,6 +144,16 @@ export default function ApiDocsComponent() {
|
|||||||
<p className="mt-4 text-gray-600">
|
<p className="mt-4 text-gray-600">
|
||||||
用于实践我最新学到的技术,也能勉强保证服务可用性(但被打了可扛不住)。
|
用于实践我最新学到的技术,也能勉强保证服务可用性(但被打了可扛不住)。
|
||||||
</p>
|
</p>
|
||||||
|
<p className="mt-4 text-gray-600">
|
||||||
|
如果你觉得这个API有什么不完善的地方或者说你有什么更好的想♂法,可以发送邮箱至{" "}
|
||||||
|
<a
|
||||||
|
href="mailto:i@mmeiblog.cn"
|
||||||
|
className="text-blue-600 hover:underline"
|
||||||
|
>
|
||||||
|
i@mmeiblog.cn
|
||||||
|
</a>
|
||||||
|
。
|
||||||
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@ -145,17 +162,26 @@ export default function ApiDocsComponent() {
|
|||||||
<CardTitle className="text-2xl font-bold">站点公告</CardTitle>
|
<CardTitle className="text-2xl font-bold">站点公告</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<div
|
{loading ? (
|
||||||
className="mb-4 last:mb-0 bg-gray-50 p-4 rounded-lg"
|
<Skeleton className="h-20 w-full" />
|
||||||
>
|
) : announcements.length > 0 ? (
|
||||||
<Badge
|
announcements.map((announcement, index) => (
|
||||||
variant="outline"
|
<div
|
||||||
className="bg-teal-100 text-teal-800 mb-2"
|
key={index}
|
||||||
|
className="mb-4 last:mb-0 bg-gray-50 p-4 rounded-lg"
|
||||||
>
|
>
|
||||||
2024-10-03
|
<Badge
|
||||||
</Badge>
|
variant="outline"
|
||||||
<p className="text-gray-700">目前API已由无数据库的屎山代码重构为使用 Mysql 的高性能代码</p>
|
className="bg-teal-100 text-teal-800 mb-2"
|
||||||
</div>
|
>
|
||||||
|
{announcement.date}
|
||||||
|
</Badge>
|
||||||
|
<p className="text-gray-700">{announcement.content}</p>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<p className="text-gray-500 italic">暂无公告</p>
|
||||||
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@ -198,7 +224,7 @@ export default function ApiDocsComponent() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<p className="text-gray-700">
|
<p className="text-gray-700">
|
||||||
此 API 提供随机二次元图片,不定期更新!
|
此 API 提供随机二次元图片,不定期更新!
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-4 text-gray-600">
|
<p className="mt-4 text-gray-600">
|
||||||
图片总数:{" "}
|
图片总数:{" "}
|
||||||
@ -257,7 +283,7 @@ export default function ApiDocsComponent() {
|
|||||||
<TableCell>{endpoint.id}</TableCell>
|
<TableCell>{endpoint.id}</TableCell>
|
||||||
<TableCell>{endpoint.device}</TableCell>
|
<TableCell>{endpoint.device}</TableCell>
|
||||||
<TableCell>{endpoint.method}</TableCell>
|
<TableCell>{endpoint.method}</TableCell>
|
||||||
<TableCell><a href = {endpoint.url}>{endpoint.url}</a></TableCell>
|
<TableCell>{endpoint.url}</TableCell>
|
||||||
<TableCell>{endpoint.description}</TableCell>
|
<TableCell>{endpoint.description}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
@ -348,11 +374,14 @@ export default function ApiDocsComponent() {
|
|||||||
<div className="container mx-auto px-6 py-4">
|
<div className="container mx-auto px-6 py-4">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<p className="text-gray-600">
|
<p className="text-gray-600">
|
||||||
© 2024 mei. All rights reserved.
|
© 2024 Cat API. All rights reserved.
|
||||||
</p>
|
</p>
|
||||||
<div className="flex items-center text-gray-500">
|
<div className="flex items-center text-gray-500">
|
||||||
<GitCommit className="w-5 h-5 mr-2" />
|
<GitCommit className="w-5 h-5 mr-2" />
|
||||||
<span className="text-sm">{process.env.NEXT_PUBLIC_BUILD_ID || 'dev'}</span>
|
<span className="text-sm">
|
||||||
|
{process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA?.slice(0, 7) ||
|
||||||
|
"dev"}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {};
|
||||||
output: 'export'
|
|
||||||
};
|
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "node scripts/generate-build-id.js",
|
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import crypto from 'crypto';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
||||||
|
|
||||||
const generateProjectHash = () => {
|
|
||||||
const hash = crypto.createHash('sha256');
|
|
||||||
const walk = (dir) => {
|
|
||||||
const files = fs.readdirSync(dir);
|
|
||||||
files.forEach(file => {
|
|
||||||
const filePath = path.join(dir, file);
|
|
||||||
const stat = fs.statSync(filePath);
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
walk(filePath);
|
|
||||||
} else {
|
|
||||||
hash.update(fs.readFileSync(filePath));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
walk(path.join(__dirname, '..'));
|
|
||||||
return hash.digest('hex').substring(0, 7); // 使用前10个字符作为短哈希
|
|
||||||
};
|
|
||||||
|
|
||||||
const generateBuildId = () => {
|
|
||||||
const projectHash = generateProjectHash();
|
|
||||||
const envFilePath = path.join(__dirname, '..', '.env.local');
|
|
||||||
|
|
||||||
if (fs.existsSync(envFilePath)) {
|
|
||||||
fs.unlinkSync(envFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(envFilePath, `NEXT_PUBLIC_BUILD_ID=${projectHash}`);
|
|
||||||
console.log(`Build ID generated: ${projectHash}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
generateBuildId();
|
|
Loading…
Reference in New Issue
Block a user