同步发送fetch请求,支持设置不启用超时

This commit is contained in:
wkj 2024-12-13 16:10:34 +08:00
parent db715f7356
commit a4fe54f056
2 changed files with 6 additions and 0 deletions

View File

@ -38,6 +38,9 @@ function verify(publicKey, body, ts, nonce, signature) {
return verify2.verify(publicKey, signature, 'hex');
}
async function fetchWithTimeout(url, options, timeout = 5000) {
if (typeof AbortController === 'undefined' || timeout === 0) {
return fetch(url, options);
}
const controller = new AbortController();
const signal = controller.signal;
// 设置超时

View File

@ -63,6 +63,9 @@ function verify(publicKey: string, body: string, ts: string, nonce: string, sign
}
async function fetchWithTimeout(url: string, options: RequestInit, timeout = 5000) {
if (typeof AbortController === 'undefined' || timeout === 0) {
return fetch(url, options);
}
const controller = new AbortController();
const signal = controller.signal;