aboutsummaryrefslogtreecommitdiff
path: root/src/graphql/anime/resolvers.ts
blob: 5f49b3641224298eb2876be21c6b6998c1b2d73b (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])
          )
        }
      };
    }
  }
};