Skip to content

Commit d6b08cf

Browse files
committed
mod(driver): add google retry
1 parent 9940d9f commit d6b08cf

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ <h4>隐私政策和使用条款</h4>
155155
<script src="/static/spoid.js"></script>
156156
<script src="/static/input.js"></script>
157157
<script>
158+
let callback_flag = false;
158159
// 获取select元素和输入框元素
159160
const driver_txt_input = document.getElementById('driver-txt-input');
160161
const direct_url_input = document.getElementById('direct-url-input');

public/static/event.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function onSelect() {
104104
// Google弹出隐私政策和使用条款
105105
if (driver_txt_input.value === "googleui_go") {
106106
if (server_use_input.checked)
107-
showGoogleConsent();
107+
if (!callback_flag)
108+
showGoogleConsent();
108109
}
109110
}

public/static/token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ async function getToken() {
44
const json_byte = Uint8Array.from(atob(url_hash), c => c.charCodeAt(0));
55
const json_text = new TextDecoder().decode(json_byte);
66
const json_data = JSON.parse(json_text);
7-
console.log(json_data);
87
const server_use = json_data.server_use;
98
const client_uid = json_data.client_uid;
109
const secret_key = json_data.secret_key;
@@ -13,6 +12,7 @@ async function getToken() {
1312
const access_key = json_data.access_token;
1413
const refresh_ui = json_data.refresh_token;
1514
const message_ui = json_data.message_err;
15+
callback_flag = true;
1616
// 从历史记录清除#号部分,避免隐私信息泄漏
1717
// 这只会在正常解析JSON后执行,其他的hash不会被清除
1818
// window.history.replaceState(null, null, window.location.pathname + window.location.search);

src/driver/googleui_oa.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,21 @@ export async function oneToken(c: Context) {
8888
// 执行请求 ===========================================================================
8989
try {
9090
const paramsString = new URLSearchParams(params_all).toString();
91-
const response: Response = await fetch(server_url, {
92-
method: 'POST', body: paramsString,
93-
headers: {'Content-Type': 'application/x-www-form-urlencoded',},
94-
});
91+
let try_time: number = 5;
92+
let response: Response | null = null;
93+
while (try_time > 0) {
94+
try {
95+
response = await fetch(server_url, {
96+
method: 'POST', body: paramsString,
97+
headers: {'Content-Type': 'application/x-www-form-urlencoded',},
98+
});
99+
break;
100+
} catch (error) {
101+
try_time -= 1;
102+
}
103+
}
104+
if (!try_time || !response) return c.redirect(
105+
showErr("多次尝试获取Token失败"));
95106
if (server_use == "false") {
96107
local.deleteCookie(c, 'client_uid');
97108
local.deleteCookie(c, 'client_key');

0 commit comments

Comments
 (0)