Skip to content

Commit 387998d

Browse files
authored
Update b2AuthorizeCfWorker.py
1 parent f63c6c6 commit 387998d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

b2AuthorizeCfWorker.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,29 @@
7777
method: request.method,
7878
headers: b2Headers
7979
})
80-
const response = await fetch(modRequest)
80+
let response
81+
let i = 3
82+
do {
83+
response = await timeoutPromise(fetch(modRequest), 2000000)
84+
} while ((!response || !response.ok) && --i)
8185
return response
86+
function timeoutPromise(promise, ms) {
87+
return new Promise((resolve, reject) => {
88+
const timeoutId = setTimeout(() => {
89+
reject(new Error("promise timeout"))
90+
}, ms);
91+
promise.then(
92+
(res) => {
93+
clearTimeout(timeoutId);
94+
resolve(res);
95+
},
96+
(err) => {
97+
clearTimeout(timeoutId);
98+
reject(err);
99+
}
100+
);
101+
})
102+
}
82103
}"""
83104

84105
workerCode = workerTemplate.replace('<B2_DOWNLOAD_TOKEN>', bDownAuToken)

0 commit comments

Comments
 (0)