aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/mangadex/chapter/+server.ts
blob: ad291e426707f60356d4549e05536e1e8481591a (plain) (blame)
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
import { checkRateLimit } from '$lib/rateLimit.js';

export const GET = async (event) => {
	const limit = await checkRateLimit(event);
	const { url } = event;

	if (limit) return limit;

	try {
		return Response.json(
			await (
				await fetch(
					`https://api.mangadex.org/chapter?manga=${url.searchParams.get(
						'id'
					)}&chapter=${url.searchParams.get(
						'chapter'
					)}&contentRating[]=safe&contentRating[]=suggestive&contentRating[]=erotica&contentRating[]=pornographic&limit=1`
				)
			).json(),
			{
				headers: {
					'Cache-Control': 'max-age=300'
				}
			}
		);
	} catch {
		return new Response('rate-limited');
	}
};