diff --git a/public/index.html b/public/index.html index 616776a..69b284f 100644 --- a/public/index.html +++ b/public/index.html @@ -17,12 +17,12 @@
@@ -68,12 +68,12 @@
- +
- +
diff --git a/public/static/login.js b/public/static/login.js index 32df2b5..b641221 100644 --- a/public/static/login.js +++ b/public/static/login.js @@ -29,137 +29,137 @@ async function getLogin(refresh = false) { }); return; } - // 阿里云盘扫码v2直接调用专用API,不需要构建传统的requests路径 - if (apps_type === "alicloud_oa" && !refresh) { - await startAlicloud2Login(); + } + // 阿里云盘扫码v2直接调用专用API,不需要构建传统的requests路径 + if (apps_type === "alicloud_oa" && !refresh) { + await startAlicloud2Login(); + return; + } + // 刷新秘钥情况 ================================================= + let base_urls = "/requests?client_uid=" + if (refresh) { + if (!refresh_ui) { + Swal.fire({ + position: 'top', + icon: 'info', + title: '刷新失败', + text: '请先填写Refresh Token', + showConfirmButton: true, + }); return; } - // 刷新秘钥情况 ================================================= - let base_urls = "/requests?client_uid=" + base_urls = "/renewapi?client_uid=" + } + + + if (apps_type === "alicloud_oa") apps_subs = "alicloud2" + let post_urls = "/" + apps_subs + base_urls + apps_uuid + + "&client_key=" + apps_keys + "&apps_types=" + apps_type + + "&server_use=" + server_use + if (refresh) { + post_urls += "&refresh_ui=" + refresh_ui + } + if (apps_subs === "baiduyun") post_urls += "&secret_key=" + secret_key + try { + const response = await fetch(post_urls, { + method: 'GET', headers: {'Content-Type': 'application/json'} + }); + // 解析响应内容 =============================================== + const response_data = await response.json(); + // 刷新令牌模式 =============================================== if (refresh) { - if (!refresh_ui) { + if (response.status === 200) { + access_key = document.getElementById("access-token") + access_key.value = response_data.access_token; + refresh_ui = document.getElementById("refresh-token") + refresh_ui.value = response_data.refresh_token; Swal.fire({ - position: 'top', - icon: 'info', - title: '刷新失败', - text: '请先填写Refresh Token', - showConfirmButton: true, - }); - return; - } - base_urls = "/renewapi?client_uid=" - } - - - if (apps_type === "alicloud_oa") apps_subs = "alicloud2" - let post_urls = "/" + apps_subs + base_urls + apps_uuid - + "&client_key=" + apps_keys + "&apps_types=" + apps_type - + "&server_use=" + server_use - if (refresh) { - post_urls += "&refresh_ui=" + refresh_ui - } - if (apps_subs === "baiduyun") post_urls += "&secret_key=" + secret_key - try { - const response = await fetch(post_urls, { - method: 'GET', headers: {'Content-Type': 'application/json'} - }); - // 解析响应内容 =============================================== - const response_data = await response.json(); - // 刷新令牌模式 =============================================== - if (refresh) { - if (response.status === 200) { - access_key = document.getElementById("access-token") - access_key.value = response_data.access_token; - refresh_ui = document.getElementById("refresh-token") - refresh_ui.value = response_data.refresh_token; - Swal.fire({ - icon: 'success', - title: '刷新令牌成功:', - showConfirmButton: true, - timer: 1000 - }); - } else Swal.fire({ - icon: 'error', - title: '刷新令牌失败: ', - text: response_data.text, + icon: 'success', + title: '刷新令牌成功:', showConfirmButton: true, timer: 1000 }); - return; - } - // 申请登录模式 ================================================================ - if (response.status === 200) { - if (apps_subs === "onedrive" || apps_subs === "115cloud" - || apps_subs === "googleui" || apps_subs === "yandex" - || apps_type === "baiduyun_go" - ) { - window.location.href = response_data.text; - } - // 百度云OOB模式(手动回调) =============================================== - if (apps_type === "baiduyun_ob") { - window.open(response_data.text); - await Swal.fire({ - title: '提示', - html: '请在新打开的页面获取授权码并粘贴到下方:' + - '', - confirmButtonText: 'OK', - preConfirm: () => { - return document.getElementById('authCodeInput').value; - } - }).then(async (result) => { - if (result.isConfirmed) { - const authCode = result.value; - console.log('授权码:', authCode); - window.location.href = "/baiduyun/callback" + - "?server_oob=true" + "&secret_key=" + secret_key + - "&client_key=" + apps_keys + "&code=" + authCode; - } - }); - } - // 123网盘直接获取 =========================================================== - if (apps_subs === "123cloud") { - document.getElementById("access-token").value = response_data.text; - return; - } - if (apps_type === "alicloud_qr") { - let sid = response_data.sid; - await Swal.fire({ - position: 'top', - icon: 'info', - title: '扫码登录', - html: `
请扫码登录,完成后点确定
` + - ``, - showConfirmButton: true - }); - post_urls = "/alicloud/callback" + - "?client_id=" + apps_uuid + - "&client_secret=" + apps_keys + - "&grant_type=" + "authorization_code" + - "&code=" + sid - let auth_post = await fetch(post_urls, {method: 'GET'}); - let auth_data = await auth_post.json(); - if (auth_post.status === 200) { - window.location.href = `/?access_token=${auth_data.access_token}` - + `&refresh_token=${auth_data.refresh_token}` - + `&client_uid=${apps_uuid}` - + `&client_key=${apps_keys}`; - } - } - } else Swal.fire({ icon: 'error', - title: "获取秘钥失败: " + response_data.text, - showConfirmButton: true, - timer: 1000 - }); - } catch (error) { - Swal.fire({ - icon: 'error', - title: '获取秘钥失败: ' + error, + title: '刷新令牌失败: ', + text: response_data.text, showConfirmButton: true, timer: 1000 }); + return; } + // 申请登录模式 ================================================================ + if (response.status === 200) { + if (apps_subs === "onedrive" || apps_subs === "115cloud" + || apps_subs === "googleui" || apps_subs === "yandex" + || apps_type === "baiduyun_go" + ) { + window.location.href = response_data.text; + } + // 百度云OOB模式(手动回调) =============================================== + if (apps_type === "baiduyun_ob") { + window.open(response_data.text); + await Swal.fire({ + title: '提示', + html: '请在新打开的页面获取授权码并粘贴到下方:' + + '', + confirmButtonText: 'OK', + preConfirm: () => { + return document.getElementById('authCodeInput').value; + } + }).then(async (result) => { + if (result.isConfirmed) { + const authCode = result.value; + console.log('授权码:', authCode); + window.location.href = "/baiduyun/callback" + + "?server_oob=true" + "&secret_key=" + secret_key + + "&client_key=" + apps_keys + "&code=" + authCode; + } + }); + } + // 123网盘直接获取 =========================================================== + if (apps_subs === "123cloud") { + document.getElementById("access-token").value = response_data.text; + return; + } + if (apps_type === "alicloud_qr") { + let sid = response_data.sid; + await Swal.fire({ + position: 'top', + icon: 'info', + title: '扫码登录', + html: `
请扫码登录,完成后点确定
` + + ``, + showConfirmButton: true + }); + post_urls = "/alicloud/callback" + + "?client_id=" + apps_uuid + + "&client_secret=" + apps_keys + + "&grant_type=" + "authorization_code" + + "&code=" + sid + let auth_post = await fetch(post_urls, {method: 'GET'}); + let auth_data = await auth_post.json(); + if (auth_post.status === 200) { + window.location.href = `/?access_token=${auth_data.access_token}` + + `&refresh_token=${auth_data.refresh_token}` + + `&client_uid=${apps_uuid}` + + `&client_key=${apps_keys}`; + } + } + + } else Swal.fire({ + icon: 'error', + title: "获取秘钥失败: " + response_data.text, + showConfirmButton: true, + timer: 1000 + }); + } catch (error) { + Swal.fire({ + icon: 'error', + title: '获取秘钥失败: ' + error, + showConfirmButton: true, + timer: 1000 + }); } } \ No newline at end of file diff --git a/public/static/token.js b/public/static/token.js index fa42e58..91de3ea 100644 --- a/public/static/token.js +++ b/public/static/token.js @@ -90,6 +90,7 @@ async function getToken() { } if (siteSelect.value == "baiduyun_ob" || siteSelect.value == "123cloud_go" || + // siteSelect.value == "onedrive_go" || siteSelect.value == "onedrive_cn" || siteSelect.value == "onedrive_us" || siteSelect.value == "onedrive_de" || diff --git a/src/oneui.ts b/src/oneui.ts index 3487587..c410bcb 100644 --- a/src/oneui.ts +++ b/src/oneui.ts @@ -5,6 +5,10 @@ import * as configs from "./shares/configs"; import * as refresh from "./shares/refresh"; const driver_map: Record = { + "onedrive_pr": [ + 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', + 'https://login.microsoftonline.com/common/oauth2/v2.0/token' + ], "onedrive_go": [ 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', 'https://login.microsoftonline.com/common/oauth2/v2.0/token'