mirror of
https://github.com/Shineii86/AniKotoAPI.git
synced 2026-10-22 02:45:10 +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
76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
/*
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
* AniKotoAPI — schedule.extractor.js
|
|
* Repository: https://github.com/Shineii86/AniKotoAPI
|
|
*
|
|
* @description
|
|
* Extracts anime schedule for a specific date.
|
|
* Returns airing times and episode numbers for scheduled anime.
|
|
*
|
|
* @exports
|
|
* extractSchedule
|
|
*
|
|
* @author Shinei Nouzen
|
|
* @license MIT
|
|
* ======= • ======= • ======= • ======= • =======• =======
|
|
*/
|
|
|
|
import * as cheerio from "cheerio";
|
|
import { URLS } from "../configs/dataUrl.js";
|
|
import { fetchWithMirror } from "../helper/mirror.helper.js";
|
|
|
|
// ══════════════════════════════════════════════════════════════
|
|
// SCHEDULE EXTRACTION
|
|
// ══════════════════════════════════════════════════════════════
|
|
|
|
// ---- FEATURE: Extract anime schedule for a specific date ----
|
|
/**
|
|
* Fetches and parses the anime schedule for a given date.
|
|
* Returns airing times and episode numbers for scheduled anime.
|
|
*
|
|
* @param {string} date - Date to fetch schedule for (format: YYYY-MM-DD)
|
|
* @returns {Promise<Array<Object>>} Array of scheduled anime objects
|
|
* @returns {string} return.slug - URL slug for the anime
|
|
* @returns {string} return.title - Anime title
|
|
* @returns {string} return.time - Airing time
|
|
* @returns {number} return.episode_no - Episode number
|
|
*
|
|
* @example
|
|
* const schedule = await extractSchedule("2024-01-15");
|
|
* console.log(schedule[0].time); // Airing time
|
|
* console.log(schedule[0].episode_no); // Episode number
|
|
*/
|
|
const extractSchedule = async (date) => {
|
|
try {
|
|
const path = `/?date=${date}`;
|
|
const { data } = await fetchWithMirror(path);
|
|
const $ = cheerio.load(data);
|
|
|
|
const schedule = [];
|
|
|
|
$(".schedule-item, .anime-schedule .item").each((i, el) => {
|
|
const slug = $(el).find("a").attr("href")?.split("/watch/").pop() || "";
|
|
const title = $(el).find(".film-name a, .name").text().trim() || "";
|
|
const time = $(el).find(".time, .schedule-time").text().trim() || "";
|
|
const episodeNo = parseInt($(el).find(".episode-no, .ep-num").text().trim()) || 0;
|
|
|
|
if (slug) {
|
|
schedule.push({
|
|
slug,
|
|
title,
|
|
time,
|
|
episode_no: episodeNo
|
|
});
|
|
}
|
|
});
|
|
|
|
return schedule;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
export { extractSchedule };
|
|
|
|
// ══════════════════════════════════════════════════════════════ END: schedule.extractor.js
|