feat(episodeServers): added getEpisodeServers controller
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { RequestHandler } from "express";
|
||||||
|
import { scrapeEpisodeServers } from "../parsers";
|
||||||
|
import { EpisodeServersQueryParams } from "../models/controllers";
|
||||||
|
|
||||||
|
// /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;
|
||||||
Reference in New Issue
Block a user