mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(telegram): bound individual api requests
Bound individual platform calls so they cannot outlive the lock protecting a message update or stall a whole delivery invocation.
This commit is contained in:
1 parent
0bf18fe2ca
commit
03021f7c2b
1 file changed
+7
@@ -9,6 +9,12 @@ interface TelegramResponse {
|
|||||||
result?: { message_id?: number };
|
result?: { message_id?: number };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Longest a single API call may take. Bounded, so a message edit always ends
|
||||||
|
* well within the update-chain lock it runs under (see `deliverUpdate`).
|
||||||
|
*/
|
||||||
|
export const REQUEST_TIMEOUT_MS = 15_000;
|
||||||
|
|
||||||
async function post(
|
async function post(
|
||||||
token: string,
|
token: string,
|
||||||
method: string,
|
method: string,
|
||||||
@@ -25,6 +31,7 @@ async function post(
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||||
});
|
});
|
||||||
lastStatus = res.status;
|
lastStatus = res.status;
|
||||||
const data = (await res.json().catch(() => null)) as TelegramResponse | null;
|
const data = (await res.json().catch(() => null)) as TelegramResponse | null;
|
||||||
|
|||||||
Reference in new issue
Block a user