feat(getNextEpisodeSchedule): add /anime/:animeId/next-episode-schedule endpoint
This commit is contained in:
+148
-129
@@ -11,211 +11,230 @@ hianimeRouter.get("/", (c) => c.redirect("/", 301));
|
|||||||
|
|
||||||
// /api/v2/hianime/home
|
// /api/v2/hianime/home
|
||||||
hianimeRouter.get("/home", async (c) => {
|
hianimeRouter.get("/home", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedHomePage>(
|
const data = await cache.getOrSet<HiAnime.ScrapedHomePage>(
|
||||||
hianime.getHomePage,
|
hianime.getHomePage,
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/azlist/{sortOption}?page={page}
|
// /api/v2/hianime/azlist/{sortOption}?page={page}
|
||||||
hianimeRouter.get("/azlist/:sortOption", async (c) => {
|
hianimeRouter.get("/azlist/:sortOption", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
|
|
||||||
const sortOption = decodeURIComponent(
|
const sortOption = decodeURIComponent(
|
||||||
c.req.param("sortOption").trim().toLowerCase()
|
c.req.param("sortOption").trim().toLowerCase()
|
||||||
) as HiAnime.AZListSortOptions;
|
) as HiAnime.AZListSortOptions;
|
||||||
const page: number =
|
const page: number =
|
||||||
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeAZList>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeAZList>(
|
||||||
async () => hianime.getAZList(sortOption, page),
|
async () => hianime.getAZList(sortOption, page),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/qtip/{animeId}
|
// /api/v2/hianime/qtip/{animeId}
|
||||||
hianimeRouter.get("/qtip/:animeId", async (c) => {
|
hianimeRouter.get("/qtip/:animeId", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeQtipInfo>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeQtipInfo>(
|
||||||
async () => hianime.getQtipInfo(animeId),
|
async () => hianime.getQtipInfo(animeId),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/category/{name}?page={page}
|
// /api/v2/hianime/category/{name}?page={page}
|
||||||
hianimeRouter.get("/category/:name", async (c) => {
|
hianimeRouter.get("/category/:name", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const categoryName = decodeURIComponent(
|
const categoryName = decodeURIComponent(
|
||||||
c.req.param("name").trim()
|
c.req.param("name").trim()
|
||||||
) as HiAnime.AnimeCategories;
|
) as HiAnime.AnimeCategories;
|
||||||
const page: number =
|
const page: number =
|
||||||
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeCategory>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeCategory>(
|
||||||
async () => hianime.getCategoryAnime(categoryName, page),
|
async () => hianime.getCategoryAnime(categoryName, page),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/genre/{name}?page={page}
|
// /api/v2/hianime/genre/{name}?page={page}
|
||||||
hianimeRouter.get("/genre/:name", async (c) => {
|
hianimeRouter.get("/genre/:name", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const genreName = decodeURIComponent(c.req.param("name").trim());
|
const genreName = decodeURIComponent(c.req.param("name").trim());
|
||||||
const page: number =
|
const page: number =
|
||||||
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedGenreAnime>(
|
const data = await cache.getOrSet<HiAnime.ScrapedGenreAnime>(
|
||||||
async () => hianime.getGenreAnime(genreName, page),
|
async () => hianime.getGenreAnime(genreName, page),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/producer/{name}?page={page}
|
// /api/v2/hianime/producer/{name}?page={page}
|
||||||
hianimeRouter.get("/producer/:name", async (c) => {
|
hianimeRouter.get("/producer/:name", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const producerName = decodeURIComponent(c.req.param("name").trim());
|
const producerName = decodeURIComponent(c.req.param("name").trim());
|
||||||
const page: number =
|
const page: number =
|
||||||
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
Number(decodeURIComponent(c.req.query("page") || "")) || 1;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedProducerAnime>(
|
const data = await cache.getOrSet<HiAnime.ScrapedProducerAnime>(
|
||||||
async () => hianime.getProducerAnimes(producerName, page),
|
async () => hianime.getProducerAnimes(producerName, page),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
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 data = await cache.getOrSet<HiAnime.ScrapedEstimatedSchedule>(
|
const date = decodeURIComponent(c.req.query("date") || "");
|
||||||
async () => hianime.getEstimatedSchedule(date),
|
let tzOffset = Number(
|
||||||
cacheConfig.key,
|
decodeURIComponent(c.req.query("tzOffset") || "-330")
|
||||||
cacheConfig.duration
|
);
|
||||||
);
|
tzOffset = isNaN(tzOffset) ? -330 : tzOffset;
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
const data = await cache.getOrSet<HiAnime.ScrapedEstimatedSchedule>(
|
||||||
|
async () => hianime.getEstimatedSchedule(date, tzOffset),
|
||||||
|
`${cacheConfig.key}_${tzOffset}`,
|
||||||
|
cacheConfig.duration
|
||||||
|
);
|
||||||
|
|
||||||
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/search?q={query}&page={page}&filters={...filters}
|
// /api/v2/hianime/search?q={query}&page={page}&filters={...filters}
|
||||||
hianimeRouter.get("/search", async (c) => {
|
hianimeRouter.get("/search", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
let { q: query, page, ...filters } = c.req.query();
|
let { q: query, page, ...filters } = c.req.query();
|
||||||
|
|
||||||
query = decodeURIComponent(query || "");
|
query = decodeURIComponent(query || "");
|
||||||
const pageNo = Number(decodeURIComponent(page || "")) || 1;
|
const pageNo = Number(decodeURIComponent(page || "")) || 1;
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeSearchResult>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeSearchResult>(
|
||||||
async () => hianime.search(query, pageNo, filters),
|
async () => hianime.search(query, pageNo, filters),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/search/suggestion?q={query}
|
// /api/v2/hianime/search/suggestion?q={query}
|
||||||
hianimeRouter.get("/search/suggestion", async (c) => {
|
hianimeRouter.get("/search/suggestion", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const query = decodeURIComponent(c.req.query("q") || "");
|
const query = decodeURIComponent(c.req.query("q") || "");
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeSearchSuggestion>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeSearchSuggestion>(
|
||||||
async () => hianime.searchSuggestions(query),
|
async () => hianime.searchSuggestions(query),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/anime/{animeId}
|
// /api/v2/hianime/anime/{animeId}
|
||||||
hianimeRouter.get("/anime/:animeId", async (c) => {
|
hianimeRouter.get("/anime/:animeId", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeAboutInfo>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeAboutInfo>(
|
||||||
async () => hianime.getInfo(animeId),
|
async () => hianime.getInfo(animeId),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/episode/servers?animeEpisodeId={id}
|
// /api/v2/hianime/episode/servers?animeEpisodeId={id}
|
||||||
hianimeRouter.get("/episode/servers", async (c) => {
|
hianimeRouter.get("/episode/servers", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const animeEpisodeId = decodeURIComponent(
|
const animeEpisodeId = decodeURIComponent(
|
||||||
c.req.query("animeEpisodeId") || ""
|
c.req.query("animeEpisodeId") || ""
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedEpisodeServers>(
|
const data = await cache.getOrSet<HiAnime.ScrapedEpisodeServers>(
|
||||||
async () => hianime.getEpisodeServers(animeEpisodeId),
|
async () => hianime.getEpisodeServers(animeEpisodeId),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// episodeId=steinsgate-3?ep=230
|
// episodeId=steinsgate-3?ep=230
|
||||||
// /api/v2/hianime/episode/sources?animeEpisodeId={episodeId}?server={server}&category={category (dub or sub)}
|
// /api/v2/hianime/episode/sources?animeEpisodeId={episodeId}?server={server}&category={category (dub or sub)}
|
||||||
hianimeRouter.get("/episode/sources", async (c) => {
|
hianimeRouter.get("/episode/sources", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const animeEpisodeId = decodeURIComponent(
|
const animeEpisodeId = decodeURIComponent(
|
||||||
c.req.query("animeEpisodeId") || ""
|
c.req.query("animeEpisodeId") || ""
|
||||||
);
|
);
|
||||||
const server = decodeURIComponent(
|
const server = decodeURIComponent(
|
||||||
c.req.query("server") || HiAnime.Servers.VidStreaming
|
c.req.query("server") || HiAnime.Servers.VidStreaming
|
||||||
) as HiAnime.AnimeServers;
|
) as HiAnime.AnimeServers;
|
||||||
const category = decodeURIComponent(c.req.query("category") || "sub") as
|
const category = decodeURIComponent(c.req.query("category") || "sub") as
|
||||||
| "sub"
|
| "sub"
|
||||||
| "dub"
|
| "dub"
|
||||||
| "raw";
|
| "raw";
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeEpisodesSources>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeEpisodesSources>(
|
||||||
async () => hianime.getEpisodeSources(animeEpisodeId, server, category),
|
async () => hianime.getEpisodeSources(animeEpisodeId, server, category),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
return c.json({ success: true, data }, { status: 200 });
|
return c.json({ success: true, data }, { status: 200 });
|
||||||
});
|
});
|
||||||
|
|
||||||
// /api/v2/hianime/anime/{anime-id}/episodes
|
// /api/v2/hianime/anime/{anime-id}/episodes
|
||||||
hianimeRouter.get("/anime/:animeId/episodes", async (c) => {
|
hianimeRouter.get("/anime/:animeId/episodes", async (c) => {
|
||||||
const cacheConfig = c.get("CACHE_CONFIG");
|
const cacheConfig = c.get("CACHE_CONFIG");
|
||||||
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
const animeId = decodeURIComponent(c.req.param("animeId").trim());
|
||||||
|
|
||||||
const data = await cache.getOrSet<HiAnime.ScrapedAnimeEpisodes>(
|
const data = await cache.getOrSet<HiAnime.ScrapedAnimeEpisodes>(
|
||||||
async () => hianime.getEpisodes(animeId),
|
async () => hianime.getEpisodes(animeId),
|
||||||
cacheConfig.key,
|
cacheConfig.key,
|
||||||
cacheConfig.duration
|
cacheConfig.duration
|
||||||
);
|
);
|
||||||
|
|
||||||
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