From 2a715270d02cb7195282b55f171b8d4ae6f991fa Mon Sep 17 00:00:00 2001 From: pikachuim Date: Thu, 12 Jun 2025 15:08:01 +0800 Subject: [PATCH] add onedrive area: cn us de --- public/index.html | 11 +++++++---- src/index.ts | 34 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/public/index.html b/public/index.html index 2562f5e..816ca0f 100644 --- a/public/index.html +++ b/public/index.html @@ -19,8 +19,10 @@
@@ -55,7 +57,7 @@
- 本获取工具不存储任何用户信息,开源于CF-Worker-API + 本工具所有信息只以Cookie形式存储于浏览器本地,开源于CF-Worker-API
@@ -68,6 +70,7 @@ async function getLogin() { let apps_uuid = document.getElementById("client-id").value; let apps_keys = document.getElementById("app-secret").value; + let apps_type = document.getElementById("site-select").value; if (apps_uuid === "" || apps_keys === "") { Swal.fire({ position: 'top', @@ -79,7 +82,7 @@ return; } let post_urls = "/onedrive/requests?client_uid=" + apps_uuid - + "&client_key=" + apps_keys; + + "&client_key=" + apps_keys + "&apps_type=" + apps_type; try { const response = await fetch(post_urls, { method: 'GET', headers: {'Content-Type': 'application/json'} diff --git a/src/index.ts b/src/index.ts index 073c099..081da8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,13 +9,31 @@ export type Bindings = { } const app = new Hono<{ Bindings: Bindings }>() app.use("*", serveStatic({manifest: manifest, root: "./"})); - +const driver_map: Record = { + "onedrive_go": [ + 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', + 'https://login.microsoftonline.com/common/oauth2/v2.0/token' + ], + "onedrive_cn": [ + 'https://login.chinacloudapi.cn/common/oauth2/v2.0/authorize', + 'https://microsoftgraph.chinacloudapi.cn/common/oauth2/v2.0/token' + ], + "onedrive_de": [ + 'https://login.microsoftonline.de/common/oauth2/v2.0/authorize', + 'https://graph.microsoft.de/common/oauth2/v2.0/token' + ], + "onedrive_us": [ + 'https://login.microsoftonline.us/common/oauth2/v2.0/authorize', + 'https://graph.microsoft.us/common/oauth2/v2.0/token' + ], +} // 登录申请 ############################################################################## app.get('/onedrive/requests', async (c) => { const client_uid = c.req.query('client_uid'); const client_key = c.req.query('client_key'); + const driver_txt = c.req.query('apps_type'); const scopes_all = 'offline_access Files.ReadWrite.All'; - const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'; + const client_url: string = driver_map[driver_txt][0]; // 请求参数 ========================================================================== const params_all: Record = { client_id: client_uid, @@ -34,6 +52,7 @@ app.get('/onedrive/requests', async (c) => { }); local.setCookie(c, 'client_uid', client_uid); local.setCookie(c, 'client_key', client_key); + local.setCookie(c, 'apps_types', driver_txt); return c.json({text: response.url}, 200); } catch (error) { return c.json({text: error}, 500); @@ -42,9 +61,10 @@ app.get('/onedrive/requests', async (c) => { // 令牌申请 ############################################################################## app.get('/onedrive/callback', async (c) => { const login_data = c.req.query('code'); - const client_uid: string | undefined = local.getCookie(c, 'client_uid') - const client_key: string | undefined = local.getCookie(c, 'client_key') - const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; + 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 = { @@ -74,10 +94,6 @@ app.get('/onedrive/callback', async (c) => { + `&refresh_token=${json.refresh_token}` + `&client_uid=${client_uid}` + `&client_key=${client_key}`); - // return c.json({ - // access_token: json.access_token, - // refresh_token: json.refresh_token, - // }); } } catch (error) { console.error(error);