2025-08-28 11:34:44 +08:00

52 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Link from "next/link";
import { readdir, stat } from "node:fs/promises";
import { WEBSITE_FILE_DIR } from "@/lib/config";
export const dynamic = "force-dynamic";
export default async function SitesPage() {
let sites: string[] = [];
try {
const entries = await readdir(WEBSITE_FILE_DIR, { withFileTypes: true });
for (const e of entries) {
if (e.isDirectory()) {
try {
const s = await stat(`${WEBSITE_FILE_DIR}/${e.name}/log/access.log`);
if (s.isFile()) sites.push(e.name);
} catch {}
}
}
} catch (error) {
// 显示错误信息
return (
<div className="max-w-5xl mx-auto py-10">
<h1 className="text-3xl font-semibold mb-6">Site </h1>
<p className="text-red-500">{String(error)}</p>
</div>
);
}
sites.sort();
return (
<div className="max-w-5xl mx-auto py-10">
<h1 className="text-3xl font-semibold mb-6">Site </h1>
<ul className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{sites.map((s) => (
<li key={s} className="border rounded-lg p-4 hover:shadow">
<div className="font-mono text-sm text-gray-500 mb-2">{s}</div>
<div className="flex gap-3">
<Link className="text-blue-600 hover:underline" href={`/sites/${encodeURIComponent(s)}`}>
</Link>
<a className="text-blue-600 hover:underline" href={`/api/sites/${encodeURIComponent(s)}/raw`} target="_blank">
</a>
</div>
</li>
))}
</ul>
</div>
);
}