36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import RSS from "rss";
|
|
import { fetchChaptersRSS } from "@/lib/api";
|
|
import { Chapter } from "@/lib/types";
|
|
|
|
|
|
const BASE_URL = process.env.BASE_URL || "http://localhost:3000";
|
|
|
|
export async function GET(){
|
|
const data = await fetchChaptersRSS();
|
|
|
|
const feed = new RSS({
|
|
title: "Null Translation Group",
|
|
description: "Null Translation Group main hub",
|
|
site_url: BASE_URL,
|
|
feed_url: `${BASE_URL}/api/feed`,
|
|
language: "en",
|
|
});
|
|
|
|
data.forEach((chapter: Chapter) => {
|
|
feed.item({
|
|
title: chapter.book?.title + " - Chapter " + chapter.number + " " + chapter.title,
|
|
description: "Daily chapter release for " + chapter.book?.title,
|
|
url: `${BASE_URL}/books/${chapter.book?.documentId}/chapters/${chapter.documentId}`,
|
|
date: chapter.release_datetime,
|
|
});
|
|
});
|
|
|
|
const xml = feed.xml({ indent: true });
|
|
|
|
return new NextResponse(xml, {
|
|
headers: {
|
|
"Content-Type": "application/xml",
|
|
},
|
|
});
|
|
} |