mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 19:05:11 +00:00
Major Changes: - Add shared parseListItem.helper.js for unified list parsing (DRY) - Migrate all 22 extractors to use fetchWithMirror() for consistent mirror fallback - Remove unused cors dependency (custom CORS middleware handles it) - Fix middleware ordering: timeout now registered before routes - Fix CORS to allow POST for /api/mirrors/reset endpoint - Remove redundant cache check in homeInfo extractor New Features: - Request ID tracking (X-Request-Id header) for debugging - Graceful shutdown handling (SIGTERM/SIGINT) with 10s timeout - CSP and HSTS security headers - Rate limiter cleanup interval (every 5 min) to prevent memory leak - Request body size limits (10kb) via express.json() Security: - Content-Security-Policy header for XSS protection - Strict-Transport-Security for HTTPS enforcement - X-Permitted-Cross-Domain-Policies: none - Body size limits to prevent large payload attacks Code Quality: - All files follow strict documentation style (box headers, section separators, feature markers, JSDoc params/returns, inline notes, module footers) - Eliminated ~200 lines of duplicated code across 8+ extractors - Updated CHANGELOG.md with comprehensive change history
107 lines
4.3 KiB
JavaScript
107 lines
4.3 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKotoAPI — topten.extractor.js
|
|
* Repository: https://github.com/Shineii86/AniKotoAPI
|
|
*
|
|
* @description
|
|
* Extracts top 10 anime rankings from the homepage.
|
|
* Parses daily, weekly, and monthly top anime lists.
|
|
*
|
|
* @exports
|
|
* extractTopTen
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import * as cheerio from "cheerio";
|
|
import { URLS } from "../configs/dataUrl.js";
|
|
import { fetchWithMirror } from "../helper/mirror.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// TOP TEN EXTRACTION
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Extract daily, weekly, and monthly top 10 anime ----
|
|
/**
|
|
* Fetches and parses the top 10 anime rankings from the homepage.
|
|
* Returns three arrays: today, week, and month rankings.
|
|
*
|
|
* @returns {Promise<Object>} Object containing today, week, and month arrays
|
|
* @returns {Array<Object>} return.today - Daily top 10 anime
|
|
* @returns {Array<Object>} return.week - Weekly top 10 anime
|
|
* @returns {Array<Object>} return.month - Monthly top 10 anime
|
|
* @returns {string} return.today[].slug - URL slug for the anime
|
|
* @returns {number} return.today[].rank - Ranking position (1-10)
|
|
* @returns {string} return.today[].name - Anime name
|
|
* @returns {string} return.today[].poster - Poster image URL
|
|
* @returns {number} return.today[].sub - Subbed episode count
|
|
* @returns {number} return.today[].dub - Dubbed episode count
|
|
* @returns {string} return.today[].type - Anime type (TV, Movie, etc.)
|
|
*
|
|
* @example
|
|
* const topTen = await extractTopTen();
|
|
* console.log(topTen.today[0].name); // #1 anime today
|
|
*/
|
|
const extractTopTen = async () => {
|
|
try {
|
|
const { data } = await fetchWithMirror("/home");
|
|
const $ = cheerio.load(data);
|
|
|
|
const today = [];
|
|
const week = [];
|
|
const month = [];
|
|
|
|
$("#top-anime .tab-content[data-name='day'] a.item").each((i, el) => {
|
|
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
|
const poster = $(el).find(".poster img").attr("src") || "";
|
|
const name = $(el).find(".name").text().trim() || "";
|
|
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
|
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
|
const type = $(el).find(".type").text().trim() || "";
|
|
const rank = i + 1;
|
|
|
|
if (slug) {
|
|
today.push({ slug, rank, name, poster, sub, dub, type });
|
|
}
|
|
});
|
|
|
|
$("#top-anime .tab-content[data-name='week'] a.item").each((i, el) => {
|
|
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
|
const poster = $(el).find(".poster img").attr("src") || "";
|
|
const name = $(el).find(".name").text().trim() || "";
|
|
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
|
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
|
const type = $(el).find(".type").text().trim() || "";
|
|
const rank = i + 1;
|
|
|
|
if (slug) {
|
|
week.push({ slug, rank, name, poster, sub, dub, type });
|
|
}
|
|
});
|
|
|
|
$("#top-anime .tab-content[data-name='month'] a.item").each((i, el) => {
|
|
const slug = $(el).attr("href")?.split("/watch/").pop() || "";
|
|
const poster = $(el).find(".poster img").attr("src") || "";
|
|
const name = $(el).find(".name").text().trim() || "";
|
|
const sub = parseInt($(el).find(".ep-status.sub span").text().trim()) || 0;
|
|
const dub = parseInt($(el).find(".ep-status.dub span").text().trim()) || 0;
|
|
const type = $(el).find(".type").text().trim() || "";
|
|
const rank = i + 1;
|
|
|
|
if (slug) {
|
|
month.push({ slug, rank, name, poster, sub, dub, type });
|
|
}
|
|
});
|
|
|
|
return { today, week, month };
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export { extractTopTen };
|
|
|
|
// ══════════════════════════════════════════════════════════════ END: topten.extractor.js
|