Skip to content

Commit 69c4ec8

Browse files
committed
Update b2AuthorizeCfWorker.py
1 parent f63c6c6 commit 69c4ec8

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

b2AuthorizeCfWorker.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,37 @@
7777
method: request.method,
7878
headers: b2Headers
7979
})
80-
const response = await fetch(modRequest)
81-
return response
82-
}"""
80+
let response
81+
let i = 3
82+
do {
83+
response = await timeoutPromise(fetch(modRequest), 2000000)
84+
if (response) {
85+
return response
86+
}
87+
sleep(100000)
88+
} while (--i)
89+
}
90+
function timeoutPromise(promise, ms) {
91+
return new Promise((resolve, reject) => {
92+
const timeoutId = setTimeout(() => {
93+
reject(new Error("promise timeout"))
94+
}, ms);
95+
promise.then(
96+
(res) => {
97+
clearTimeout(timeoutId);
98+
resolve(res);
99+
},
100+
(err) => {
101+
clearTimeout(timeoutId);
102+
reject(err);
103+
}
104+
);
105+
})
106+
}
107+
function sleep(ms) {
108+
return new Promise(resolve => setTimeout(resolve, ms));
109+
}
110+
"""
83111

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

0 commit comments

Comments
 (0)