diff --git a/src/lib/api.ts b/src/lib/api.ts index 83fd793..0c409de 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -214,16 +214,26 @@ export async function getChaptersByHid( for (const chap of rawChapters) { try { - if (!chap.id || !chap.chap || !chap.updated_at) { + // Add created_at check + if (!chap.id || !chap.chap || !chap.created_at) { console.warn(`Skipping chapter with missing fields in ${hid}:`, chap); continue; } + // Validate both dates + const isValidCreated = !isNaN(Date.parse(chap.created_at)); + const isValidUpdated = !isNaN(Date.parse(chap.updated_at)); + + if (!isValidCreated || !isValidUpdated) { + console.warn(`Invalid dates for chapter ${chap.id}`); + continue; + } + chapters.push({ id: chap.id, chap: chap.chap.toString(), title: chap.title || `Chapter ${chap.chap}`, - updated_at: chap.updated_at, + created_at: new Date(chap.created_at).toISOString(), // Use created_at md_comics: { title: comicTitle, slug: slug, @@ -231,7 +241,7 @@ export async function getChaptersByHid( } }); } catch (e) { - console.error(`Error processing chapter ${chap.id} for ${hid}:`, e); + console.error(`Error processing chapter ${chap.id}:`, e); } } @@ -352,7 +362,7 @@ export async function getChaptersForSlugs( const deduplicatedChapters = deduplicateChapters(allChapters); return deduplicatedChapters.sort((a, b) => parseFloat(b.chap) - parseFloat(a.chap) || - new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime() + new Date(b.created_at).getTime() - new Date(a.created_at).getTime() ); } diff --git a/src/lib/types.ts b/src/lib/types.ts index e9df151..3aea2a7 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -38,4 +38,16 @@ export interface Announcement { text: string; url: string; }; +} + +export interface ChapterDetail { + id: string; + chap: string; + title: string; + created_at: string; + md_comics: { + title: string; + slug: string; + md_covers?: ComicCover[]; + }; } \ No newline at end of file diff --git a/src/pages/rss/[feedId].xml.ts b/src/pages/rss/[feedId].xml.ts index b2d16dd..8b04eaa 100644 --- a/src/pages/rss/[feedId].xml.ts +++ b/src/pages/rss/[feedId].xml.ts @@ -48,7 +48,19 @@ export const GET: APIRoute = async ({ params, request }) => { }); chapters.forEach((chapter) => { + if (!chapter?.created_at) { + console.error('Chapter missing created_at:', chapter); + return; + } + const chapterUrl = `https://comick.io/comic/${chapter.md_comics.slug}`; + + const rawDate = chapter.created_at.endsWith('Z') + ? chapter.created_at + : `${chapter.created_at}Z`; + + const pubDate = isValidDate(rawDate) ? new Date(rawDate) : new Date(); + feed.addItem({ title: `${chapter.md_comics.title} - Chapter ${chapter.chap}`, id: `${chapter.md_comics.slug}-${chapter.chap}`, @@ -64,7 +76,7 @@ export const GET: APIRoute = async ({ params, request }) => {

New chapter available: Chapter ${chapter.chap}

`, - date: new Date(chapter.updated_at), + date: pubDate, }); }); @@ -73,4 +85,8 @@ export const GET: APIRoute = async ({ params, request }) => { 'Content-Type': 'application/xml; charset=utf-8', }, }); -}; \ No newline at end of file +}; + +function isValidDate(dateString: string): boolean { + return !isNaN(Date.parse(dateString)); +} \ No newline at end of file