import { db } from "@/lib/db"; const escapeXml = (value: string) => value.replace(/[<>&'\"]/g, (char) => ({ "<": "<", ">": ">", "&": "&", "'": "'", '"': """ }[char] || char)); export async function GET() { const origin = (process.env.NEXT_PUBLIC_APP_URL || "http://localhost:8088").replace(/\/$/, ""); const posts = db.prepare("SELECT p.id,p.content,p.created_at,u.username FROM posts p JOIN users u ON u.id=p.author_id WHERE p.visibility='PUBLIC' AND p.hidden=0 ORDER BY COALESCE(p.remote_created_at,p.created_at) DESC LIMIT 50").all() as { id: number; content: string; created_at: string; username: string }[]; const items = posts.map((post) => `${escapeXml(`@${post.username} 的貼文`)}${origin}/posts/${post.id}${origin}/posts/${post.id}${escapeXml(post.content.slice(0, 500))}${new Date(post.created_at + "Z").toUTCString()}`).join(""); return new Response(`Mebbling${origin}公開 Memos Hub${items}`, { headers: { "Content-Type": "application/rss+xml; charset=utf-8", "Cache-Control": "public, max-age=300" } }); }