-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroute.ts
More file actions
73 lines (64 loc) · 1.92 KB
/
Copy pathroute.ts
File metadata and controls
73 lines (64 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { db } from "@/lib/db";
import { shortifyString } from "@/lib/utils";
import { unstable_cache } from "next/cache";
import RSS from "rss";
const getLatestChapters = async (time: Date) => {
return await db.query.chapter.findMany({
where: (chapter, { gte, and, eq }) => and(gte(chapter.publishedAt, time), eq(chapter.premium, false)),
columns: {
slug: true,
publishedAt: true,
number: true
},
with: {
richText: {
columns: {
text: true,
}
},
volume: {
columns: {
number: true,
}
},
novel: {
columns: {
title: true,
slug: true
}
}
}
})
}
const getCache = unstable_cache(getLatestChapters, [], {
tags: ["chapter:update:free"],
revalidate: 3600*12
});
export async function GET(req: Request) {
const time = new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000);
const url = new URL(req.url);
const chapters = await getCache(new Date(time.getFullYear(), time.getMonth(), time.getDate(), 0, 0, 0, 0));
const feed = new RSS({
title: "Quaslation",
description: "Quality ai translations.",
site_url: url.origin,
feed_url: url.href,
image_url: `${url.origin}/icon.jpg`,
categories: chapters.map(chap => chap.novel.slug).filter((value, index, array) => array.indexOf(value) === index),
});
for (const chapter of chapters) {
feed.item({
title: `${chapter.novel.title} ${chapter.volume.number > 0 ? `Volume ${chapter.volume.number} ` : ""}Chapter ${chapter.number}`,
description: shortifyString(chapter.richText.text, 255),
url: `${url.origin}/novels/${chapter.novel.slug}/${chapter.slug}`,
guid: chapter.slug,
date: new Date(chapter.publishedAt || ""),
categories: [chapter.novel.slug],
})
}
return new Response(feed.xml({ indent: true }), {
headers: {
"Content-Type": "text/xml",
},
});
}