hianimez-api / src /controllers /animeInfo.controller.js
S VIVEGANANDAN
fix: resolve 403 error and clean repo
5769f09
raw
history blame contribute delete
916 Bytes
import extractAnimeInfo from "../extractors/animeInfo.extractor.js";
import extractSeasons from "../extractors/seasons.extractor.js";
import { getCachedData, setCachedData } from "../helper/cache.helper.js";
export const getAnimeInfo = async (req, res) => {
const { id } = req.query;
const cacheKey = `animeInfo_${id}`;
try {
const cachedResponse = await getCachedData(cacheKey);
if (cachedResponse && Object.keys(cachedResponse).length > 0) {
return cachedResponse;
}
const [seasons, data] = await Promise.all([
extractSeasons(id),
extractAnimeInfo(id),
]);
const responseData = { data: data, seasons: seasons };
setCachedData(cacheKey, responseData).catch((err) => {
console.error("Failed to set cache:", err);
});
return responseData;
} catch (e) {
console.error(e);
return res.status(500).json({ error: "An error occurred" });
}
};