diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f9f2cce..744779b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,16 +4,10 @@
-
-
-
-
-
-
+
+
-
-
@@ -23,6 +17,9 @@
+
+
+
{
"associatedIndex": 4
}
@@ -69,8 +66,41 @@
1749696640494
-
+
+
+
+ 1749704488857
+
+
+
+ 1749704488857
+
+
+
+ 1749705341327
+
+
+
+ 1749705341327
+
+
+
+ 1749712084921
+
+
+
+ 1749712084921
+
+
+
+ 1749712420228
+
+
+
+ 1749712420228
+
+
@@ -78,6 +108,9 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/public/index.html b/public/index.html
index b423f61..7386955 100644
--- a/public/index.html
+++ b/public/index.html
@@ -105,8 +105,9 @@
本工具所有信息只以Cookie形式存储于浏览器本地
- 开源于 GitHub | by OpenListTeam
+ 开源于 GitHub | by OpenListTeam
@@ -139,7 +140,6 @@
// 解析响应内容 ===============================================
const response_data = await response.json();
if (response.status === 200) {
- // window.open(response_data.text)
window.location.href = response_data.text;
} else Swal.fire({
icon: 'error',
@@ -189,6 +189,17 @@
const client_key = urlParams.get("client_key");
const access_token = urlParams.get("access_token");
const refresh_token = urlParams.get("refresh_token");
+ const message_err = urlParams.get("message_err");
+ console.log(message_err);
+ if (message_err && client_uid) {
+ Swal.fire({
+ position: 'top',
+ icon: 'error',
+ title: '授权失败',
+ html: message_err,
+ showConfirmButton: true,
+ });
+ }
document.getElementById("client-id").value = client_uid;
document.getElementById("app-secret").value = client_key;
document.getElementById("access-token").value = access_token;
diff --git a/src/index.ts b/src/index.ts
index 081da8b..b8e78fa 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -60,20 +60,33 @@ app.get('/onedrive/requests', async (c) => {
})
// 令牌申请 ##############################################################################
app.get('/onedrive/callback', async (c) => {
- const login_data = c.req.query('code');
- const client_uid: string = local.getCookie(c, 'client_uid')
- const client_key: string = local.getCookie(c, 'client_key')
- const driver_txt: string = local.getCookie(c, 'apps_types')
- const client_url: string = driver_map[driver_txt][1];
- console.log(login_data);
- // 请求参数 ==========================================================================
- const params_all = {
- client_id: client_uid,
- client_secret: client_key,
- redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback',
- code: login_data,
- grant_type: 'authorization_code'
- };
+ let login_data, client_uid, client_key, driver_txt, client_url, params_all;
+ try { // 请求参数 ====================================================================
+ login_data = c.req.query('code');
+ client_uid = local.getCookie(c, 'client_uid')
+ client_key = local.getCookie(c, 'client_key')
+ driver_txt = local.getCookie(c, 'apps_types')
+ client_url = driver_map[driver_txt][1];
+ params_all = {
+ client_id: client_uid,
+ client_secret: client_key,
+ redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback',
+ code: login_data,
+ grant_type: 'authorization_code'
+ };
+ } catch (error) {
+ return c.redirect(
+ `/?message_err=${"授权失败,请检查:
" +
+ "1、应用ID和应用机密是否正确
" +
+ "2、登录账号是否具有应用权限
" +
+ "3、回调地址是否包括上面地址
" +
+ "4、登录可能过期,请重新登录
" +
+ "错误信息:
" + error}`
+ + `&client_uid=NULL`
+ + `&client_key=`);
+ }
+ // console.log(login_data);
+
// 执行请求 ===========================================================================
try {
const paramsString = new URLSearchParams(params_all).toString();
@@ -84,9 +97,19 @@ app.get('/onedrive/callback', async (c) => {
},
body: paramsString,
});
- console.log(response);
+ // console.log(response);
+ local.deleteCookie(c, 'client_uid');
+ local.deleteCookie(c, 'client_key');
+ local.deleteCookie(c, 'apps_types');
if (!response.ok)
- return c.json({text: response.text()}, 403);
+ return c.redirect(
+ `/?message_err=${"授权失败,请检查:
" +
+ "1、应用ID和应用机密是否正确
" +
+ "2、登录账号是否具有应用权限
" +
+ "3、回调地址是否包括上面地址
" +
+ "错误信息:
" + response.text()}`
+ + `&client_uid=${client_uid}`
+ + `&client_key=${client_key}`);
const json: Record = await response.json();
if (json.token_type === 'Bearer') {
return c.redirect(
@@ -96,8 +119,14 @@ app.get('/onedrive/callback', async (c) => {
+ `&client_key=${client_key}`);
}
} catch (error) {
- console.error(error);
- return c.json({text: error}, 500);
+ return c.redirect(
+ `/?message_err=${"授权失败,请检查:
" +
+ "1、应用ID和应用机密是否正确
" +
+ "2、登录账号是否具有应用权限
" +
+ "3、回调地址是否包括上面地址
" +
+ "错误信息:
" + error}`
+ + `&client_uid=${client_uid}`
+ + `&client_key=${client_key}`);
}
})