Files
AniKotoAPI/src/controllers/trending.controller.js
T
Sʜɪɴᴇɪ Nᴏᴜᴢᴇɴ 0034617c3b v1.5.0: Complete documentation rewrite - 50+ files with AlisaReactionBot style
- Box-style header comments (Project, Author, License) on every file
- Section headers using double-line box decorators
- Feature markers (// ---- FEATURE: XYZ ----) before every major function
- JSDoc comments for EVERY function with @param, @returns, @example
- Inline notes (NOTE, WARNING, TIP) for non-obvious logic
- Footer END markers on every module
- Matched code style to AlisaReactionBot repository
- All files now searchable by feature name via grep

Author: Shinei Nouzen <157171073+Shineii86@users.noreply.github.com>
2026-06-08 16:14:01 +05:30

57 lines
2.2 KiB
JavaScript

/*
* ======= • ======= • ======= • ======= • =======• =======
* AniKatoAPI — trending.controller.js
* Repository: https://github.com/Shineii86/AniKatoAPI
*
* @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 } 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);
res.json({ success: true, results: data });
} catch (error) {
next(error);
}
};
export { getTrending };
// ══════════════════════════════════════════════════════════════ END: trending.controller.js