add better feed handling

This commit is contained in:
ld3zian 2025-02-04 19:10:22 -07:00
parent b8499d90c6
commit 0daac66b26
4 changed files with 252 additions and 183 deletions

View file

@ -0,0 +1,17 @@
import type { APIRoute } from "astro";
import { validateSlugs } from "../../lib/api";
export const POST: APIRoute = async ({ request }) => {
try {
const { slugs } = await request.json();
const validSlugs = await validateSlugs(slugs);
return new Response(JSON.stringify({ validSlugs }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Validation error:', error);
return new Response("Validation failed", { status: 500 });
}
};

View file

@ -1,6 +1,6 @@
import { Feed } from 'feed';
import { getChaptersForSlugs, isValidLanguage } from "../../lib/api";
import { getFeedMapping } from "../../lib/db";
import { getFeedMapping, warmChapterCache } from "../../lib/db";
import type { APIRoute } from "astro";
export const GET: APIRoute = async ({ params, request }) => {
@ -22,6 +22,8 @@ export const GET: APIRoute = async ({ params, request }) => {
return new Response("Invalid language", { status: 400 });
}
await warmChapterCache(slugs, lang);
const chapters = await getChaptersForSlugs(slugs, lang);
if (chapters.length === 0) {