mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 10:55:10 +00:00
Added comprehensive documentation following project conventions: Box-style headers (added/fixed where missing): - All 17 files now have standard Project/Author/License headers Section headers (// == == SECTION == ==): - cache.helper.js: LRU CACHE CLASS, TTL CONFIGURATION, SINGLETON, EXPORTED HELPERS - download.controller.js: DOWNLOAD LINKS HANDLER - download.extractor.js: BASE64 DECODER, REDIRECT FOLLOWER, DOWNLOAD LINKS EXTRACTOR - seasons.extractor.js: SEASONS EXTRACTOR - watchOrder.extractor.js: WATCH ORDER EXTRACTOR - extractPages.helper.js: PAGE EXTRACTOR - pagination.helper.js: PAGINATION METADATA Feature markers (// --- FEATURE: XYZ ---): - cache.helper.js: LRU Cache, Per-Endpoint TTL, Cache Get/Set/Clear - download.controller.js: Download Links - download.extractor.js: Base64 Download Data Decoder, Redirect Chain Resolver, Download Links Extraction - seasons.extractor.js: Season Information Extraction - watchOrder.extractor.js: Watch Order / Related Anime Extraction - streamResolver.extractor.js: Server Name Normalization, Stream URL Resolution, Batch Stream URL Resolution, M3U8 Quality Parser, Subtitle Track Extractor - mirror.helper.js: Mirror Domain Configuration, Mirror Health Check, Working Mirror Discovery, Mirror Cache Reset, URL Builder, Resilient Fetch with Mirror Fallback, Mirror Status Reporter - pagination.helper.js: Pagination Metadata Generator - creatorInfo.js: Creator Attribution Object, Response Creator Injection Middleware Function-level JSDoc (added/fixed): - cache.helper.js: Full JSDoc on all 6 class methods (constructor, get, set, delete, clear, getStats, has) and 4 exported helpers Inline notes for non-obvious logic: - cache.helper.js: Lazy expiration, LRU re-insertion, singleton pattern - download.extractor.js: HTML/JSON hybrid response handling, multiple selectors for different mirrors, redirect fallback - random.extractor.js: maxRedirects, validateStatus, responseURL extraction - schedule.extractor.js: Dual selector pattern for different mirror layouts - animeInfo.extractor.js: Positional .bmeta selector fragility - homeInfo.extractor.js: Dual selector for different layouts - mirror.helper.js: 404 vs connection error handling - animeInfo.controller.js: Accept both id and slug params Footers (added where missing): - cache.helper.js, download.controller.js, download.extractor.js, seasons.extractor.js, watchOrder.extractor.js, extractPages.helper.js, mirror.helper.js All 68 source files now have complete documentation coverage (6/6 checks).
67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKotoAPI — download.controller.js
|
|
* Repository: https://github.com/Shineii86/AniKotoAPI
|
|
*
|
|
* @description
|
|
* Controller for download links endpoint. Returns streaming server
|
|
* URLs for downloading anime episodes.
|
|
*
|
|
* @exports
|
|
* getDownloadLinks - Express route handler for GET /api/download
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import { extractDownloadLinks } from "../extractors/download.extractor.js";
|
|
import { getCache, setCache, TTL } from "../helper/cache.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// DOWNLOAD LINKS HANDLER
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Download Links ----
|
|
/**
|
|
* Handles GET /api/download requests. Returns download links
|
|
* for the specified anime episode.
|
|
*
|
|
* @param {object} req - Express request object
|
|
* @param {string} req.query.slug - Anime slug (required)
|
|
* @param {number} req.query.ep - Episode number (required)
|
|
* @param {object} res - Express response object
|
|
* @param {Function} next - Express next middleware function
|
|
* @returns {void} Sends JSON response with download links
|
|
*
|
|
* @example
|
|
* GET /api/download?slug=naruto-shippuden-c8gov&ep=1
|
|
* Response: { success: true, results: { slug, episode, downloads[] } }
|
|
*/
|
|
const getDownloadLinks = async (req, res, next) => {
|
|
try {
|
|
const { slug, ep } = req.query;
|
|
if (!slug || !ep) {
|
|
return res.status(400).json({
|
|
success: false,
|
|
message: "Both slug and ep parameters are required"
|
|
});
|
|
}
|
|
|
|
const cacheKey = `download_${slug}_${ep}`;
|
|
const cached = getCache(cacheKey);
|
|
if (cached) {
|
|
return res.json({ success: true, results: cached });
|
|
}
|
|
|
|
const data = await extractDownloadLinks(slug, parseInt(ep));
|
|
setCache(cacheKey, data, TTL.stream);
|
|
res.json({ success: true, results: data });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
export { getDownloadLinks };
|
|
// ══════════════════════════════════════════════════════════════ END: download.controller.js
|