mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 19:05:11 +00:00
feat: v2.2.0 — Modularize codebase, unify mirror fallback, harden security
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
This commit is contained in:
@@ -16,9 +16,8 @@
|
||||
*/
|
||||
|
||||
import * as cheerio from "cheerio";
|
||||
import axios from "axios";
|
||||
import { headers } from "../configs/header.config.js";
|
||||
import { URLS } from "../configs/dataUrl.js";
|
||||
import { fetchWithMirror } from "../helper/mirror.helper.js";
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// TRENDING SIDEBAR EXTRACTION
|
||||
@@ -49,15 +48,13 @@ import { URLS } from "../configs/dataUrl.js";
|
||||
*/
|
||||
const extractTrendingSidebar = async () => {
|
||||
try {
|
||||
// NOTE: The sidebar content is embedded in the homepage HTML
|
||||
const { data } = await axios.get(URLS.home, { headers });
|
||||
const { data } = await fetchWithMirror("/home");
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const day = [];
|
||||
const week = [];
|
||||
const month = [];
|
||||
|
||||
// NOTE: Daily rankings use the 'day' tab content
|
||||
$("#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") || "";
|
||||
@@ -67,13 +64,11 @@ const extractTrendingSidebar = async () => {
|
||||
const type = $(el).find(".type").text().trim() || "";
|
||||
const rank = i + 1;
|
||||
|
||||
// NOTE: Only include items with valid slugs
|
||||
if (slug) {
|
||||
day.push({ slug, rank, name, poster, sub, dub, type });
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE: Weekly rankings use the 'week' tab content
|
||||
$("#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") || "";
|
||||
@@ -88,7 +83,6 @@ const extractTrendingSidebar = async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE: Monthly rankings use the 'month' tab content
|
||||
$("#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") || "";
|
||||
@@ -103,7 +97,6 @@ const extractTrendingSidebar = async () => {
|
||||
}
|
||||
});
|
||||
|
||||
// NOTE: Latest episodes section provides recently updated content
|
||||
const latestEpisodes = [];
|
||||
$("#recent-update .item, .section-updated .item").each((i, el) => {
|
||||
const slug = $(el).find("a.name.d-title").attr("href")?.split("/watch/").pop() || "";
|
||||
|
||||
Reference in New Issue
Block a user