feat(getNextEpisodeSchedule): add /anime/:animeId/next-episode-schedule endpoint
This commit is contained in:
+22
-3
@@ -105,14 +105,19 @@ hianimeRouter.get("/producer/:name", async (c) => {
|
|||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/schedule?date={date}
|
// /api/v2/hianime/schedule?date={date}&tzOffset={tzOffset}
|
||||||
hianimeRouter.get("/schedule", async (c) => {
|
hianimeRouter.get("/schedule", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
|
|
||||||
const date = decodeURIComponent(c.req.query("date") || "");
|
const date = decodeURIComponent(c.req.query("date") || "");
|
||||||
|
let tzOffset = Number(
|
||||||
|
decodeURIComponent(c.req.query("tzOffset") || "-330")
|
||||||
|
);
|
||||||
|
tzOffset = isNaN(tzOffset) ? -330 : tzOffset;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedEstimatedSchedule>(
|
const data = await cache.getOrSet<HiAnime.ScrapedEstimatedSchedule>(
|
||||||
async () => hianime.getEstimatedSchedule(date),
|
async () => hianime.getEstimatedSchedule(date, tzOffset),
|
||||||
cacheConfig.key,
|
`${cacheConfig.key}_${tzOffset}`,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -218,4 +223,18 @@ hianimeRouter.get("/anime/:animeId/episodes", async (c) => {
|
|||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// /api/v2/hianime/anime/{anime-id}/next-episode-schedule
|
||||||
|
hianimeRouter.get("/anime/:animeId/next-episode-schedule", async (c) => {
|
||||||
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
|
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
||||||
|
|
||||||
|
const data = await cache.getOrSet<HiAnime.ScrapedNextEpisodeSchedule>(
|
||||||
|
async () => hianime.getNextEpisodeSchedule(animeId),
|
||||||
|
cacheConfig.key,
|
||||||
|
cacheConfig.duration
|
||||||
|
);
|
||||||
|
|
||||||
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
|
});
|
||||||
|
|
||||||
export { hianimeRouter };
|
export { hianimeRouter };
|
||||||
|
|||||||
Reference in New Issue
Block a user