diff --git a/components/api-docs.tsx b/components/api-docs.tsx index 3146af6..1ae0e11 100644 --- a/components/api-docs.tsx +++ b/components/api-docs.tsx @@ -20,27 +20,20 @@ import { ExternalLink, GitCommit } from "lucide-react"; export default function ApiDocsComponent() { const [activePage, setActivePage] = useState("home"); const [imageCount, setImageCount] = useState(null); - const [announcements, setAnnouncements] = useState< - Array<{ date: string; content: string }> - >([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchData = async () => { setLoading(true); try { - const [imageCountResponse, announcementsResponse] = await Promise.all([ - fetch("/?api=total-pic"), - fetch("/?api=announcements"), + const [imageCountResponse] = await Promise.all([ + fetch("/?api=total-pic") ]); const imageCountData = await imageCountResponse.json(); - const announcementsData = await announcementsResponse.json(); setImageCount(imageCountData.count); - setAnnouncements(announcementsData.announcements); } catch (error) { console.error("Failed to fetch data:", error); setImageCount(null); - setAnnouncements([]); } finally { setLoading(false); } @@ -119,7 +112,7 @@ export default function ApiDocsComponent() { ]; const friendlyLinks = [ - { name: "mei的网络日志", url: "https://mmeiblog.cn" } + { name: "mei的网络日志", url: "https://mei.lv" } ]; const HomePage = () => ( @@ -144,16 +137,6 @@ export default function ApiDocsComponent() {

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

-

- 如果你觉得这个API有什么不完善的地方或者说你有什么更好的想♂法,可以发送邮箱至{" "} - - i@mmeiblog.cn - - 。 -

@@ -162,26 +145,17 @@ export default function ApiDocsComponent() { 站点公告 - {loading ? ( - - ) : announcements.length > 0 ? ( - announcements.map((announcement, index) => ( -
+ - - {announcement.date} - -

{announcement.content}

-
- )) - ) : ( -

暂无公告

- )} + 2024-10-03 + +

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

+
@@ -224,7 +198,7 @@ export default function ApiDocsComponent() {

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

图片总数:{" "} @@ -283,7 +257,7 @@ export default function ApiDocsComponent() { {endpoint.id} {endpoint.device} {endpoint.method} - {endpoint.url} + {endpoint.url} {endpoint.description} ))} diff --git a/scripts/generate-build-id.js b/scripts/generate-build-id.js index ae10a68..b0ddef8 100644 --- a/scripts/generate-build-id.js +++ b/scripts/generate-build-id.js @@ -1,12 +1,39 @@ -const fs = require('fs'); -const path = require('path'); +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 buildId = Date.now().toString(36) + Math.random().toString(36).substr(2, 5); + const projectHash = generateProjectHash(); const envFilePath = path.join(__dirname, '..', '.env.local'); - fs.appendFileSync(envFilePath, `\nNEXT_PUBLIC_BUILD_ID=${buildId}`); - console.log(`Build ID generated: ${buildId}`); + if (fs.existsSync(envFilePath)) { + fs.unlinkSync(envFilePath); + } + + fs.writeFileSync(envFilePath, `NEXT_PUBLIC_BUILD_ID=${projectHash}`); + console.log(`Build ID generated: ${projectHash}`); }; generateBuildId(); \ No newline at end of file