File size: 856 Bytes
11acfd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import createHttpError from "http-errors";
import { type RequestHandler } from "express";
import { scrapeEpisodeServers } from "../parsers/index.js";
import { type EpisodeServersQueryParams } from "../types/controllers/index.js";

// /anime/servers?episodeId=${id}
const getEpisodeServers: RequestHandler<
  unknown,
  Awaited<ReturnType<typeof scrapeEpisodeServers>>,
  unknown,
  EpisodeServersQueryParams
> = async (req, res, next) => {
  try {
    const episodeId = req.query.episodeId
      ? decodeURIComponent(req.query?.episodeId as string)
      : null;

    if (episodeId === null) {
      throw createHttpError.BadRequest("Episode id required");
    }

    const data = await scrapeEpisodeServers(episodeId);
    res.status(200).json(data);
  } catch (err: any) {
    console.error(err);
    next(err);
  }
};

export default getEpisodeServers;