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:
Shinei Nouzen
2026-07-28 19:28:21 +05:30
parent 7f07833c14
commit a8f1917ce7
22 changed files with 269 additions and 418 deletions
+2 -8
View File
@@ -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";
// ══════════════════════════════════════════════════════════════
// TOP TEN EXTRACTION
@@ -47,15 +46,13 @@ import { URLS } from "../configs/dataUrl.js";
*/
const extractTopTen = async () => {
try {
// NOTE: The top 10 section uses tabbed content with data-name attributes
const { data } = await axios.get(URLS.home, { headers });
const { data } = await fetchWithMirror("/home");
const $ = cheerio.load(data);
const today = [];
const week = [];
const month = [];
// NOTE: Each tab contains a list of anime items with ranking data
$("#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") || "";
@@ -65,13 +62,11 @@ const extractTopTen = async () => {
const type = $(el).find(".type").text().trim() || "";
const rank = i + 1;
// NOTE: Only include items with valid slugs
if (slug) {
today.push({ slug, rank, name, poster, sub, dub, type });
}
});
// NOTE: Weekly rankings follow the same structure as daily
$("#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") || "";
@@ -86,7 +81,6 @@ const extractTopTen = async () => {
}
});
// NOTE: Monthly rankings follow the same structure
$("#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") || "";