export const prerender = false;
import type { APIRoute } from "astro";
import { eq } from "drizzle-orm";
import { createDb } from "@/db";
import { events, profiles } from "@/db/schema";
export const GET: APIRoute = async ({ locals }) => {
const runtime = locals.runtime as { env: { DATABASE_URL: string } };
const db = createDb(runtime.env.DATABASE_URL);
const [allEvents, allProfiles] = await Promise.all([
db.select({ slug: events.slug, updatedAt: events.updatedAt }).from(events).where(eq(events.active, true)),
db.select({ username: profiles.username, updatedAt: profiles.updatedAt }).from(profiles).where(eq(profiles.active, true)),
]);
const base = "https://palacefate.com";
const urls = [
`${base}/daily1.0`,
`${base}/fdaily0.9`,
...allEvents.map(
(e) =>
`${base}/f/${e.slug}${e.updatedAt.toISOString().split("T")[0]}daily0.8`,
),
...allProfiles.map(
(p) =>
`${base}/p/${p.username}${p.updatedAt.toISOString().split("T")[0]}weekly0.6`,
),
];
const xml = `
${urls.join("\n")}
`;
return new Response(xml, {
headers: { "Content-Type": "application/xml" },
});
};