From d70180b23c090eaeb0d6240cdfc31ccf203bd986 Mon Sep 17 00:00:00 2001 From: wukko Date: Sat, 28 Jun 2025 17:05:18 +0600 Subject: [PATCH] api/core: merge isApiKey and isSession into authType cuz they can't be true at the same time --- api/src/core/api.js | 7 +++---- api/src/processing/match.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/src/core/api.js b/api/src/core/api.js index 0487ad7a..248f9357 100644 --- a/api/src/core/api.js +++ b/api/src/core/api.js @@ -156,7 +156,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => { return fail(res, `error.api.auth.key.${error}`); } - req.isApiKey = true; + req.authType = "key"; return next(); }); @@ -185,7 +185,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => { } req.rateLimitKey = hashHmac(token, 'rate'); - req.isSession = true; + req.authType = "session"; } catch { return fail(res, "error.api.generic"); } @@ -267,8 +267,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => { host: parsed.host, patternMatch: parsed.patternMatch, params: normalizedRequest, - isSession: req.isSession ?? false, - isApiKey: req.isApiKey ?? false, + authType: req.authType ?? "none", }); res.status(result.status).json(result.body); diff --git a/api/src/processing/match.js b/api/src/processing/match.js index f963512b..360ed532 100644 --- a/api/src/processing/match.js +++ b/api/src/processing/match.js @@ -32,7 +32,7 @@ import xiaohongshu from "./services/xiaohongshu.js"; let freebind; -export default async function({ host, patternMatch, params, isSession, isApiKey }) { +export default async function({ host, patternMatch, params, authType }) { const { url } = params; assert(url instanceof URL); let dispatcher, requestIP; @@ -69,7 +69,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey let youtubeHLS = params.youtubeHLS; const hlsEnv = env.enableDeprecatedYoutubeHls; - if (hlsEnv === "never" || (hlsEnv === "key" && !isApiKey)) { + if (hlsEnv === "never" || (hlsEnv === "key" && authType !== "key")) { youtubeHLS = false; } @@ -313,7 +313,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey let localProcessing = params.localProcessing; const lpEnv = env.forceLocalProcessing; - const shouldForceLocal = lpEnv === "always" || (lpEnv === "session" && isSession); + const shouldForceLocal = lpEnv === "always" || (lpEnv === "session" && authType === "session"); const localDisabled = (!localProcessing || localProcessing === "none"); if (shouldForceLocal && localDisabled) {