mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-29 18:08:28 +00:00
api/core: merge isApiKey and isSession into authType
cuz they can't be true at the same time
This commit is contained in:
parent
bc8c16f469
commit
d70180b23c
@ -156,7 +156,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
|||||||
return fail(res, `error.api.auth.key.${error}`);
|
return fail(res, `error.api.auth.key.${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.isApiKey = true;
|
req.authType = "key";
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.rateLimitKey = hashHmac(token, 'rate');
|
req.rateLimitKey = hashHmac(token, 'rate');
|
||||||
req.isSession = true;
|
req.authType = "session";
|
||||||
} catch {
|
} catch {
|
||||||
return fail(res, "error.api.generic");
|
return fail(res, "error.api.generic");
|
||||||
}
|
}
|
||||||
@ -267,8 +267,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
|||||||
host: parsed.host,
|
host: parsed.host,
|
||||||
patternMatch: parsed.patternMatch,
|
patternMatch: parsed.patternMatch,
|
||||||
params: normalizedRequest,
|
params: normalizedRequest,
|
||||||
isSession: req.isSession ?? false,
|
authType: req.authType ?? "none",
|
||||||
isApiKey: req.isApiKey ?? false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(result.status).json(result.body);
|
res.status(result.status).json(result.body);
|
||||||
|
@ -32,7 +32,7 @@ import xiaohongshu from "./services/xiaohongshu.js";
|
|||||||
|
|
||||||
let freebind;
|
let freebind;
|
||||||
|
|
||||||
export default async function({ host, patternMatch, params, isSession, isApiKey }) {
|
export default async function({ host, patternMatch, params, authType }) {
|
||||||
const { url } = params;
|
const { url } = params;
|
||||||
assert(url instanceof URL);
|
assert(url instanceof URL);
|
||||||
let dispatcher, requestIP;
|
let dispatcher, requestIP;
|
||||||
@ -69,7 +69,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
|
|||||||
let youtubeHLS = params.youtubeHLS;
|
let youtubeHLS = params.youtubeHLS;
|
||||||
const hlsEnv = env.enableDeprecatedYoutubeHls;
|
const hlsEnv = env.enableDeprecatedYoutubeHls;
|
||||||
|
|
||||||
if (hlsEnv === "never" || (hlsEnv === "key" && !isApiKey)) {
|
if (hlsEnv === "never" || (hlsEnv === "key" && authType !== "key")) {
|
||||||
youtubeHLS = false;
|
youtubeHLS = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ export default async function({ host, patternMatch, params, isSession, isApiKey
|
|||||||
|
|
||||||
let localProcessing = params.localProcessing;
|
let localProcessing = params.localProcessing;
|
||||||
const lpEnv = env.forceLocalProcessing;
|
const lpEnv = env.forceLocalProcessing;
|
||||||
const shouldForceLocal = lpEnv === "always" || (lpEnv === "session" && isSession);
|
const shouldForceLocal = lpEnv === "always" || (lpEnv === "session" && authType === "session");
|
||||||
const localDisabled = (!localProcessing || localProcessing === "none");
|
const localDisabled = (!localProcessing || localProcessing === "none");
|
||||||
|
|
||||||
if (shouldForceLocal && localDisabled) {
|
if (shouldForceLocal && localDisabled) {
|
||||||
|
Loading…
Reference in New Issue
Block a user