mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
streamingController: bail early if limited
This commit is contained in:
parent
44dfd15502
commit
53e7e856c1
1 changed files with 9 additions and 1 deletions
|
|
@ -57,12 +57,19 @@ const streamingController: AppController = async (c) => {
|
|||
return c.json({ error: 'Invalid access token' }, 401);
|
||||
}
|
||||
|
||||
const ip = c.req.header('x-real-ip');
|
||||
if (ip) {
|
||||
const count = limiter.get(ip) ?? 0;
|
||||
if (count > LIMITER_LIMIT) {
|
||||
return c.json({ error: 'Rate limit exceeded' }, 429);
|
||||
}
|
||||
}
|
||||
|
||||
const { socket, response } = Deno.upgradeWebSocket(c.req.raw, { protocol: token, idleTimeout: 30 });
|
||||
|
||||
const store = await Storages.db();
|
||||
const pubsub = await Storages.pubsub();
|
||||
|
||||
const ip = c.req.header('x-real-ip');
|
||||
const policy = pubkey ? new MuteListPolicy(pubkey, await Storages.admin()) : undefined;
|
||||
|
||||
function send(name: string, payload: object) {
|
||||
|
|
@ -139,6 +146,7 @@ const streamingController: AppController = async (c) => {
|
|||
|
||||
if (typeof e.data !== 'string') {
|
||||
socket.close(1003, 'Invalid message');
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue