Initial commit

This commit is contained in:
mxdyeah committed 2026-07-08 01:15:18 +08:00
commit acadc92e68
780 files changed
+468285

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
import { getRequestURL } from "h3";
import db from "../db";
export default defineEventHandler((event) => {
const requestUrl = getRequestURL(event);
const siteUrl = requestUrl.origin;
// 查询所有 playable = 1 的歌曲
const songs = db.prepare(
"SELECT id, filename FROM songs WHERE playable = 1"
).all() as Array<{ id: number; filename: string }>;
// 生成 XML 内容
const urls: string[] = [];
// 添加首页
urls.push(`
<url>
<loc>${siteUrl}/</loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>`);
// 循环添加歌曲页面
for (const song of songs) {
const encodedName = encodeURIComponent(song.filename);
const loc = `${siteUrl}/song/${song.id}/${encodedName}`;
urls.push(`
<url>
<loc>${loc}</loc>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>`);
}
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls.join("")}
</urlset>`;
setHeader(event, "Content-Type", "application/xml; charset=utf-8");
return sitemapXml;
});