mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-09 18:24:27 +02:00
api/core: mark request as session when bearer token is used
and pass it to match() for future consumption
This commit is contained in:
parent
d0539118ce
commit
c5acb45557
@ -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'],
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user