docs: Add box-style headers, section headers, feature markers, JSDoc, inline notes, footers

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).
This commit is contained in:
Shinei Nouzen
2026-07-28 21:55:14 +05:30
parent fb62184688
commit 7df5bbcc54
17 changed files with 205 additions and 29 deletions
+32 -12
View File
@@ -26,10 +26,17 @@ import axios from "axios";
import { fetchWithMirror } from "../helper/mirror.helper.js";
import { headers } from "../configs/header.config.js";
// ══════════════════════════════════════════════════════════════
// BASE64 DECODER
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Base64 Download Data Decoder ----
/**
* Decodes base64 download data from the website
* Decodes base64 download data from the website.
* The source site encodes download server URLs as base64 JSON.
*
* @param {string} encoded - Base64 encoded string
* @returns {Object} Decoded download data
* @returns {Object|null} Decoded download data, or null on failure
*/
function decodeDownloadData(encoded) {
try {
@@ -40,8 +47,15 @@ function decodeDownloadData(encoded) {
}
}
// ══════════════════════════════════════════════════════════════
// REDIRECT FOLLOWER
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Redirect Chain Resolver ----
/**
* Follows redirect chain to get the final URL
* Follows redirect chain to get the final URL.
* Uses axios maxRedirects to auto-follow up to 5 redirects.
*
* @param {string} url - Starting URL
* @returns {Promise<string>} Final URL after redirects
*/
@@ -52,9 +66,10 @@ async function followRedirects(url) {
maxRedirects: 5,
timeout: 10000
});
// NOTE: response.request.res.responseUrl contains the final URL after all redirects
return response.request?.res?.responseUrl || response.config?.url || url;
} catch (error) {
// If we get a redirect error, try to extract the location
// NOTE: On redirect errors, axios throws — extract Location header manually
if (error.response?.headers?.location) {
return error.response.headers.location;
}
@@ -62,6 +77,11 @@ async function followRedirects(url) {
}
}
// ══════════════════════════════════════════════════════════════
// DOWNLOAD LINKS EXTRACTOR
// ══════════════════════════════════════════════════════════════
// ---- FEATURE: Download Links Extraction ----
/**
* Fetches and parses download links for a specific episode.
* Scrapes the watch page to extract download-data attributes
@@ -84,7 +104,7 @@ const extractDownloadLinks = async (slug, ep) => {
try {
const { data } = await fetchWithMirror(`/watch/${slug}/ep-${ep}`);
// Handle both string HTML and JSON responses
// NOTE: Response may be raw HTML string or JSON-wrapped HTML
let html = "";
if (typeof data === "string") {
try {
@@ -105,8 +125,7 @@ const extractDownloadLinks = async (slug, ep) => {
const downloads = [];
// Find all download buttons with download-data attribute
// Multiple selectors to handle different HTML structures
// NOTE: Multiple selectors to handle different HTML structures across mirrors
const selectors = [
"[download-data]",
"li.download-icon",
@@ -124,13 +143,13 @@ const extractDownloadLinks = async (slug, ep) => {
if (encoded && encoded.length > 10) {
const decoded = decodeDownloadData(encoded);
if (decoded) {
// Extract URLs from the decoded data
// NOTE: Decoded data is a nested object: { serverGroup: { serverName: url } }
for (const [serverGroup, servers] of Object.entries(decoded)) {
for (const [serverName, url] of Object.entries(servers)) {
// Avoid duplicates
// Avoid duplicates by URL
const exists = downloads.some(d => d.url === url);
if (!exists) {
// Construct worker URL from nekostream.site URL
// NOTE: nekostream.site URLs need Cloudflare Worker proxy
const workerUrl = url.includes("nekostream.site")
? url.replace("https://pahe.nekostream.site/", "https://proud-dew-d754.download992.workers.dev/")
: null;
@@ -155,7 +174,7 @@ const extractDownloadLinks = async (slug, ep) => {
if (downloads.length > 0) break;
}
// Try to follow redirects for each download URL
// NOTE: Follow redirects for each download URL to resolve kwik.cx links
for (const download of downloads) {
if (download.workerUrl) {
try {
@@ -164,7 +183,7 @@ const extractDownloadLinks = async (slug, ep) => {
download.kwikUrl = finalUrl;
}
} catch (error) {
// If redirect fails, construct a placeholder kwik URL
// NOTE: Redirect may fail due to Cloudflare — construct placeholder
download.kwikUrl = "https://kwik.cx/f/[requires-browser]";
}
}
@@ -185,3 +204,4 @@ const extractDownloadLinks = async (slug, ep) => {
};
export { extractDownloadLinks };
// ══════════════════════════════════════════════════════════════ END: download.extractor.js