docs: Complete documentation overhaul with live API data + bug fixes

Documentation (5800+ lines total):
- endpoints.md: All 43 endpoints documented with real response examples,
  param tables, response patterns, common workflows, error formats
- streaming.md: Complete streaming workflow guide with HLS.js/Plyr/Video.js
  integration, M3U8 proxy explanation, error handling
- examples.md: Working code examples in cURL, JS fetch, Python requests,
  Node.js axios, HTML/JS player integration (2240 lines)
- architecture.md: Full project structure, request flow diagrams, caching
  strategy, mirror failover, security, deployment notes
- index.md: Overview with quick start, feature highlights, endpoint tables

Bug fixes:
- episodeList.extractor: Parse JSON response before Cheerio (was passing
  raw JSON string as HTML, causing escaped quotes in IDs)
- episodeListAjax.extractor: Same JSON parsing fix
- topAnimeRankings.controller: Fix JSDoc and default sort from top to day
  (actual values are day/week/month, not top/newest)
- apiRoutes.js: Fix OpenAPI spec sort description for top-rankings

Tests: 35/35 passing
This commit is contained in:
Shinei Nouzen
2026-07-30 08:28:51 +05:30
parent 996cead3b1
commit 8f423bf39c
9 changed files with 4436 additions and 816 deletions
@@ -5,7 +5,7 @@
*
* @description
* Controller for top anime rankings. Returns ranked anime list
* with support for top (all-time) and newest sort modes.
* with support for day, week, and month sort modes.
*
* @exports
* getTopAnimeRankings - Express route handler for GET /api/top-rankings
@@ -28,18 +28,18 @@ import { getCache, setCache, TTL } from "../helper/cache.helper.js";
* with support for top (all-time) and newest sort modes.
*
* @param {object} req - Express request object
* @param {string} [req.query.sort="top"] - Sort mode: "top" or "newest"
* @param {string} [req.query.sort="day"] - Sort mode: "day", "week", or "month"
* @param {object} res - Express response object
* @param {Function} next - Express next middleware function
* @returns {void} Sends JSON response with ranked anime list
*
* @example
* GET /api/top-rankings?sort=top
* GET /api/top-rankings?sort=day
* Response: { success: true, results: [{ rank: 1, title: "...", ... }] }
*/
const getTopAnimeRankings = async (req, res, next) => {
try {
const { sort = "top" } = req.query;
const { sort = "day" } = req.query;
const cacheKey = `top_rankings_${sort}`;
const cached = getCache(cacheKey);
if (cached) {
+2 -1
View File
@@ -61,7 +61,8 @@ const extractEpisodeList = async (slugOrId) => {
headers: { "X-Requested-With": "XMLHttpRequest" }
});
const ajaxHtml = typeof ajaxRaw === "string" ? ajaxRaw : (ajaxRaw?.result || "");
const ajaxParsed = typeof ajaxRaw === "string" ? JSON.parse(ajaxRaw) : ajaxRaw;
const ajaxHtml = ajaxParsed?.result || "";
const $ep = cheerio.load(ajaxHtml);
const episodes = [];
+2 -1
View File
@@ -55,7 +55,8 @@ const extractEpisodeListAjax = async (animeId, style = "", vrf = "") => {
});
// NOTE: Response is JSON {status, result} where result is HTML
const html = typeof raw === "string" ? raw : (raw?.result || "");
const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
const html = parsed?.result || "";
const $ = cheerio.load(html);
// NOTE: Extract filter options (Sub/Dub, episode ranges)
+1 -1
View File
@@ -661,7 +661,7 @@ app.get("/api/openapi", (req, res) => {
"/az-list/{letter}": { get: { summary: "A-Z listing", tags: ["Discovery"] } },
"/suggestions": { get: { summary: "Anime suggestions", tags: ["Search"] } },
"/upcoming": { get: { summary: "Upcoming anime", tags: ["Discovery"] } },
"/top-rankings": { get: { summary: "Top anime rankings (top/newest)", tags: ["Rankings"] } },
"/top-rankings": { get: { summary: "Top anime rankings (day/week/month)", tags: ["Rankings"] } },
"/recently-updated": { get: { summary: "Recently updated (all/dub/sub tabs)", tags: ["Releases"] } },
"/completed": { get: { summary: "Completed anime series", tags: ["Rankings"] } },
},