mirror of
https://github.com/ld3z/new-manga.git
synced 2026-11-09 20:23:45 -07:00
add covers to custom feeds as well as implement uniqueIds
This commit is contained in:
parent
5d4802607e
commit
16993baa78
4 changed files with 106 additions and 2 deletions
34
src/pages/api/create-feed.ts
Normal file
34
src/pages/api/create-feed.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import type { APIRoute } from "astro";
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
// In-memory storage (replace with database in production)
|
||||
const feedMappings = new Map<string, { slugs: string[], lang: string }>();
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const { slugs, lang } = await request.json();
|
||||
|
||||
if (!Array.isArray(slugs) || slugs.length === 0) {
|
||||
return new Response("Invalid slugs array", { status: 400 });
|
||||
}
|
||||
|
||||
// Create a unique hash based on slugs and language
|
||||
const dataString = `${slugs.sort().join(',')}:${lang}`;
|
||||
const hash = createHash('md5').update(dataString).digest('hex').slice(0, 8);
|
||||
|
||||
// Store the mapping
|
||||
feedMappings.set(hash, { slugs, lang });
|
||||
|
||||
return new Response(JSON.stringify({ feedId: hash }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response("Invalid request", { status: 400 });
|
||||
}
|
||||
};
|
||||
|
||||
// Export the mappings for use in other files
|
||||
export { feedMappings };
|
||||
46
src/pages/rss/[feedId].xml.ts
Normal file
46
src/pages/rss/[feedId].xml.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import rss from "@astrojs/rss";
|
||||
import { getChaptersForSlugs, isValidLanguage } from "../../lib/api";
|
||||
import type { APIRoute } from "astro";
|
||||
import { feedMappings } from "../api/create-feed";
|
||||
|
||||
export const GET: APIRoute = async ({ params }) => {
|
||||
const feedId = params.feedId?.replace('.xml', '');
|
||||
|
||||
if (!feedId || !feedMappings.has(feedId)) {
|
||||
return new Response("Feed not found", { status: 404 });
|
||||
}
|
||||
|
||||
const { slugs, lang } = feedMappings.get(feedId)!;
|
||||
|
||||
if (!isValidLanguage(lang)) {
|
||||
return new Response("Invalid language", { status: 400 });
|
||||
}
|
||||
|
||||
const chapters = await getChaptersForSlugs(slugs, lang);
|
||||
|
||||
if (chapters.length === 0) {
|
||||
return new Response("No chapters found for the provided comics", { status: 404 });
|
||||
}
|
||||
|
||||
return rss({
|
||||
title: `ComicK - Custom Feed (${lang.toUpperCase()})`,
|
||||
description: `Custom RSS feed for selected comics: ${slugs.join(', ')}`,
|
||||
site: "https://github.com/ld3z/manga-rss",
|
||||
items: chapters.map((chapter) => ({
|
||||
title: `${chapter.md_comics.title} - Chapter ${chapter.chap}`,
|
||||
link: `https://comick.io/comic/${chapter.md_comics.slug}`,
|
||||
pubDate: new Date(chapter.updated_at),
|
||||
description: `
|
||||
<div>
|
||||
${
|
||||
chapter.md_comics.md_covers?.[0]
|
||||
? `<img src="https://meo.comick.pictures/${chapter.md_comics.md_covers[0].b2key}"
|
||||
alt="Cover" style="max-width: 300px; margin-bottom: 1rem;" />`
|
||||
: ""
|
||||
}
|
||||
<p>New chapter available: Chapter ${chapter.chap}</p>
|
||||
</div>
|
||||
`,
|
||||
})),
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue