mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(feishu): 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
7882701e1f
commit
061e045a39
1 file changed
+7
@@ -11,6 +11,11 @@ interface FeishuResponse {
|
|||||||
data?: { message_id?: string } & Record<string, unknown>;
|
data?: { message_id?: string } & Record<string, unknown>;
|
||||||
error?: { message?: string };
|
error?: { message?: string };
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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 feishuRequest(
|
async function feishuRequest(
|
||||||
url: string,
|
url: string,
|
||||||
@@ -33,6 +38,7 @@ async function feishuRequest(
|
|||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||||
});
|
});
|
||||||
lastStatus = res.status;
|
lastStatus = res.status;
|
||||||
|
|
||||||
@@ -135,6 +141,7 @@ export async function getTenantAccessToken(env: Env): Promise<TokenResult> {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ app_id: appId, app_secret: appSecret }),
|
body: JSON.stringify({ app_id: appId, app_secret: appSecret }),
|
||||||
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
||||||
});
|
});
|
||||||
const data = (await res.json().catch(() => null)) as {
|
const data = (await res.json().catch(() => null)) as {
|
||||||
code?: number;
|
code?: number;
|
||||||
|
|||||||
Reference in new issue
Block a user