aboutsummaryrefslogtreecommitdiff
path: root/src/graphql/anime/resolvers.ts
blob: 7d04082d04b108d82a30c66b0e797ab7a471246d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import type { WithIndex } from '../$types';
import type { Resolvers } from './$types';

export const resolvers: WithIndex<Resolvers> = {
	Query: {
		Anime: async (_, args) => {
			const timezone = args.timezone || 'Asia/Tokyo';

			return {
				subtitles: {
					timezone,
					schedule: Object.fromEntries(
						Object.entries(
							(await (await fetch(`https://subsplease.org/api/?f=schedule&tz=${timezone}`)).json())
								.schedule
						).map(([key, value]) => [key.toLowerCase(), value])
					)
				}
			};
		}
	}
};