add onedrive area: cn us de

This commit is contained in:
pikachuim 2025-06-12 15:08:01 +08:00
parent da5b4e5e6c
commit 2a715270d0
2 changed files with 32 additions and 13 deletions

View File

@ -19,8 +19,10 @@
<div class="input-group"> <div class="input-group">
<label for="site-select">网盘名称</label> <label for="site-select">网盘名称</label>
<select id="site-select"> <select id="site-select">
<option value="official" selected>OneDrive 官方站点</option> <option value="onedrive_go" selected>OneDrive 官方站点</option>
<!-- <option value="cn">OneDrive 世纪互联</option>--> <option value="onedrive_cn">OneDrive 世纪互联</option>
<option value="onedrive_us">OneDrive 美国版本</option>
<option value="onedrive_de">OneDrive 德国版本</option>
</select> </select>
</div> </div>
@ -55,7 +57,7 @@
</div> </div>
<div class="input-group"> <div class="input-group">
获取工具不存储任何用户信息,开源于<a href="https://github.com/OpenListTeam/cf-worker-api">CF-Worker-API</a> 工具所有信息只以Cookie形式存储于浏览器本地,开源于<a href="https://github.com/OpenListTeam/cf-worker-api">CF-Worker-API</a>
</div> </div>
</div> </div>
</div> </div>
@ -68,6 +70,7 @@
async function getLogin() { async function getLogin() {
let apps_uuid = document.getElementById("client-id").value; let apps_uuid = document.getElementById("client-id").value;
let apps_keys = document.getElementById("app-secret").value; let apps_keys = document.getElementById("app-secret").value;
let apps_type = document.getElementById("site-select").value;
if (apps_uuid === "" || apps_keys === "") { if (apps_uuid === "" || apps_keys === "") {
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
@ -79,7 +82,7 @@
return; return;
} }
let post_urls = "/onedrive/requests?client_uid=" + apps_uuid let post_urls = "/onedrive/requests?client_uid=" + apps_uuid
+ "&client_key=" + apps_keys; + "&client_key=" + apps_keys + "&apps_type=" + apps_type;
try { try {
const response = await fetch(post_urls, { const response = await fetch(post_urls, {
method: 'GET', headers: {'Content-Type': 'application/json'} method: 'GET', headers: {'Content-Type': 'application/json'}

View File

@ -9,13 +9,31 @@ export type Bindings = {
} }
const app = new Hono<{ Bindings: Bindings }>() const app = new Hono<{ Bindings: Bindings }>()
app.use("*", serveStatic({manifest: manifest, root: "./"})); app.use("*", serveStatic({manifest: manifest, root: "./"}));
const driver_map: Record<string, string[]> = {
"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) => { app.get('/onedrive/requests', async (c) => {
const client_uid = <string>c.req.query('client_uid'); const client_uid = <string>c.req.query('client_uid');
const client_key = <string>c.req.query('client_key'); const client_key = <string>c.req.query('client_key');
const driver_txt = <string>c.req.query('apps_type');
const scopes_all = 'offline_access Files.ReadWrite.All'; 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<string, any> = { const params_all: Record<string, any> = {
client_id: client_uid, 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_uid', client_uid);
local.setCookie(c, 'client_key', client_key); local.setCookie(c, 'client_key', client_key);
local.setCookie(c, 'apps_types', driver_txt);
return c.json({text: response.url}, 200); return c.json({text: response.url}, 200);
} catch (error) { } catch (error) {
return c.json({text: error}, 500); return c.json({text: error}, 500);
@ -42,9 +61,10 @@ app.get('/onedrive/requests', async (c) => {
// 令牌申请 ############################################################################## // 令牌申请 ##############################################################################
app.get('/onedrive/callback', async (c) => { app.get('/onedrive/callback', async (c) => {
const login_data = <string>c.req.query('code'); const login_data = <string>c.req.query('code');
const client_uid: string | undefined = local.getCookie(c, 'client_uid') const client_uid: string = <string>local.getCookie(c, 'client_uid')
const client_key: string | undefined = local.getCookie(c, 'client_key') const client_key: string = <string>local.getCookie(c, 'client_key')
const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token'; const driver_txt: string = <string>local.getCookie(c, 'apps_types')
const client_url: string = driver_map[driver_txt][1];
console.log(login_data); console.log(login_data);
// 请求参数 ========================================================================== // 请求参数 ==========================================================================
const params_all = { const params_all = {
@ -74,10 +94,6 @@ app.get('/onedrive/callback', async (c) => {
+ `&refresh_token=${json.refresh_token}` + `&refresh_token=${json.refresh_token}`
+ `&client_uid=${client_uid}` + `&client_uid=${client_uid}`
+ `&client_key=${client_key}`); + `&client_key=${client_key}`);
// return c.json({
// access_token: json.access_token,
// refresh_token: json.refresh_token,
// });
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);