api/core: mark request as session when bearer token is used

and pass it to match() for future consumption
This commit is contained in:
wukko 2025-05-06 16:16:29 +06:00
parent d0539118ce
commit c5acb45557
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
2 changed files with 5 additions and 2 deletions

View File

@ -181,6 +181,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
} }
req.rateLimitKey = hashHmac(token, 'rate'); req.rateLimitKey = hashHmac(token, 'rate');
req.isSession = true;
} catch { } catch {
return fail(res, "error.api.generic"); return fail(res, "error.api.generic");
} }
@ -245,6 +246,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
if (!parsed) { if (!parsed) {
return fail(res, "error.api.link.invalid"); return fail(res, "error.api.link.invalid");
} }
if ("error" in parsed) { if ("error" in parsed) {
let context; let context;
if (parsed?.context) { if (parsed?.context) {
@ -258,13 +260,14 @@ 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,
}); });
res.status(result.status).json(result.body); res.status(result.status).json(result.body);
} catch { } catch {
fail(res, "error.api.generic"); fail(res, "error.api.generic");
} }
}) });
app.use('/tunnel', cors({ app.use('/tunnel', cors({
methods: ['GET'], methods: ['GET'],

View File

@ -32,7 +32,7 @@ import xiaohongshu from "./services/xiaohongshu.js";
let freebind; let freebind;
export default async function({ host, patternMatch, params }) { export default async function({ host, patternMatch, params, isSession }) {
const { url } = params; const { url } = params;
assert(url instanceof URL); assert(url instanceof URL);
let dispatcher, requestIP; let dispatcher, requestIP;