mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 02:45:10 +00:00
- 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>
56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKatoAPI — homeInfo.controller.js
|
|
* Repository: https://github.com/Shineii86/AniKatoAPI
|
|
*
|
|
* @description
|
|
* Controller for the homepage data endpoint. Extracts featured
|
|
* anime, spotlight, trending, and other homepage sections.
|
|
* Uses in-memory caching to avoid repeated scraping.
|
|
*
|
|
* @exports
|
|
* getHomeInfo - Express route handler for GET /api/
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import { extractHomeInfo } from "../extractors/homeInfo.extractor.js";
|
|
import { getCache, setCache } from "../helper/cache.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// CONTROLLER: HOME INFO
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Homepage data endpoint ----
|
|
/**
|
|
* Handles GET /api/ requests by extracting homepage data
|
|
* from the source site. Returns cached data if available.
|
|
*
|
|
* @param {object} req - Express request object
|
|
* @param {object} res - Express response object
|
|
* @param {Function} next - Express next middleware function
|
|
*
|
|
* @example
|
|
* GET /api/
|
|
* Response: { success: true, results: { spotlight, trending, ... } }
|
|
*/
|
|
const getHomeInfo = async (req, res, next) => {
|
|
try {
|
|
const cacheKey = "home";
|
|
const cached = getCache(cacheKey);
|
|
if (cached) {
|
|
return res.json({ success: true, results: cached });
|
|
}
|
|
const data = await extractHomeInfo();
|
|
setCache(cacheKey, data);
|
|
res.json({ success: true, results: data });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
export { getHomeInfo };
|
|
|
|
// ══════════════════════════════════════════════════════════════ END: homeInfo.controller.js
|