mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 19:05:11 +00:00
- Add multi-mirror fallback system with 5 mirror domains - Add LRU cache with configurable TTL per endpoint - Add response compression (gzip) - Add Seasons endpoint (/api/seasons/:id) - Add Watch Order endpoint (/api/watch-order/:id) - Add Latest Updated endpoint (/api/latest-updated) - Add Download endpoint (/api/download) - Add cache stats endpoint (/api/cache/stats) - Add mirror status/reset endpoints (/api/mirrors, /api/mirrors/reset) - Add configurable rate limiting with X-RateLimit headers - Add request timeouts and entity too large handling - Update documentation with all new endpoints - Update CHANGELOG.md with v2.0.0 entry - Update package.json version to 2.0.0 - Add 6 AI agent prompts for development
57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKotoAPI — trending.controller.js
|
|
* Repository: https://github.com/Shineii86/AniKotoAPI
|
|
*
|
|
* @description
|
|
* Controller for currently trending anime data. Returns a list
|
|
* of anime that are currently popular/trending on the source site.
|
|
* No parameters required - returns fixed trending content.
|
|
*
|
|
* @exports
|
|
* getTrending - Express route handler for GET /api/trending
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import { extractTrending } from "../extractors/trending.extractor.js";
|
|
import { getCache, setCache, TTL } from "../helper/cache.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// CONTROLLER: TRENDING
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Trending anime endpoint ----
|
|
/**
|
|
* Handles GET /api/trending requests. Returns currently trending
|
|
* anime from the source site.
|
|
*
|
|
* @param {object} req - Express request object
|
|
* @param {object} res - Express response object
|
|
* @param {Function} next - Express next middleware function
|
|
* @returns {void} Sends JSON response with trending anime list
|
|
*
|
|
* @example
|
|
* GET /api/trending
|
|
* Response: { success: true, results: [{ title, rank, ... }] }
|
|
*/
|
|
const getTrending = async (req, res, next) => {
|
|
try {
|
|
const cacheKey = "trending";
|
|
const cached = getCache(cacheKey);
|
|
if (cached) {
|
|
return res.json({ success: true, results: cached });
|
|
}
|
|
const data = await extractTrending();
|
|
setCache(cacheKey, data, TTL.trending);
|
|
res.json({ success: true, results: data });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
export { getTrending };
|
|
|
|
// ══════════════════════════════════════════════════════════════ END: trending.controller.js
|