mirror of
https://github.com/Shineii86/MiruroAPI.git
synced 2026-10-22 18:25:11 +00:00
Fix diagnostic sweep bugs — tags, random, 404s, security headers
- Tags: data.TagCollection→data.MediaTagCollection (was returning empty array) - Random: Math.random()*50→crypto.randomInt(1,500) for true randomness - Character/Staff: return 404 instead of 500 on not-found - Security: added X-XSS-Protection header - All 44 endpoints tested in full diagnostic sweep
This commit is contained in:
@@ -113,6 +113,7 @@ app.use((req, res, next) => {
|
|||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
res.setHeader("X-Frame-Options", "DENY");
|
res.setHeader("X-Frame-Options", "DENY");
|
||||||
res.setHeader("X-Content-Type-Options", "nosniff");
|
res.setHeader("X-Content-Type-Options", "nosniff");
|
||||||
|
res.setHeader("X-XSS-Protection", "1; mode=block");
|
||||||
res.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
|
res.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
|
||||||
res.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
|
res.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
|
||||||
res.setHeader("Permissions-Policy", "camera=(), microphone=(), geolocation=()");
|
res.setHeader("Permissions-Policy", "camera=(), microphone=(), geolocation=()");
|
||||||
|
|||||||
@@ -609,7 +609,7 @@ const getAllGenres = async () => {
|
|||||||
const getAllTags = async () => {
|
const getAllTags = async () => {
|
||||||
const gql = `query { MediaTagCollection { name description category isGeneralSpoiler isMediaSpoiler isAdult } }`;
|
const gql = `query { MediaTagCollection { name description category isGeneralSpoiler isMediaSpoiler isAdult } }`;
|
||||||
const data = await anilistQuery(gql);
|
const data = await anilistQuery(gql);
|
||||||
return data.TagCollection;
|
return data.MediaTagCollection;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ══════════════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════════════
|
||||||
|
|||||||
@@ -320,8 +320,9 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => {
|
|||||||
// ---- FEATURE: Random anime of the day ----
|
// ---- FEATURE: Random anime of the day ----
|
||||||
router.get("/random", async (req, res) => {
|
router.get("/random", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// NOTE: Get random page from trending to ensure variety
|
// NOTE: Use crypto for better randomness in serverless + wider range for variety
|
||||||
const randomPage = Math.floor(Math.random() * 50) + 1;
|
const crypto = require("crypto");
|
||||||
|
const randomPage = crypto.randomInt(1, 500);
|
||||||
const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1);
|
const data = await anilist.getCollection("POPULARITY_DESC", null, randomPage, 1);
|
||||||
const anime = data.results[0];
|
const anime = data.results[0];
|
||||||
|
|
||||||
@@ -505,7 +506,8 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => {
|
|||||||
|
|
||||||
jsonResponse(res, result);
|
jsonResponse(res, result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
jsonError(res, err.message);
|
const status = err.message.includes("not found") ? 404 : 500;
|
||||||
|
jsonError(res, err.message, status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -524,7 +526,8 @@ const createApiRoutes = (jsonResponse, jsonError, startTime) => {
|
|||||||
|
|
||||||
jsonResponse(res, result);
|
jsonResponse(res, result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
jsonError(res, err.message);
|
const status = err.message.includes("not found") ? 404 : 500;
|
||||||
|
jsonError(res, err.message, status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user