From efab5ee9b0a8b8bbecc20bdb5b7473f8870060f6 Mon Sep 17 00:00:00 2001 From: pikachuim Date: Fri, 13 Jun 2025 19:26:04 +0800 Subject: [PATCH] deal google & 123 pan --- .gitignore | 1 + .idea/workspace.xml | 29 +++-- package-lock.json | 280 ++++++++++++++++++++++++++++++++++++++++- package.json | 3 +- public/index.html | 158 ++++++++++++++--------- src/115ui.ts | 4 +- src/123ui.ts | 48 +++++++ src/goapi.ts | 59 +++++---- src/index.ts | 11 ++ wrangler.jsonc | 15 --- wrangler.jsonc.example | 27 ++++ 11 files changed, 515 insertions(+), 120 deletions(-) create mode 100644 src/123ui.ts delete mode 100644 wrangler.jsonc create mode 100644 wrangler.jsonc.example diff --git a/.gitignore b/.gitignore index aeb439e..9e88612 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ yarn-error.log* .vscode/* .wrangler/* +wrangler.jsonc \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0e0a308..3e4ba10 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,20 +5,14 @@ - - - - - - - - + + - + - + + @@ -88,7 +83,7 @@ 1749696640494 - + - diff --git a/package-lock.json b/package-lock.json index 5d0256f..c5cfa25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "@cloudflare/workers-types": "^4.20250610.0", "@google-cloud/local-auth": "^2.1.0", "googleapis": "^105.0.0", - "hono": "^4.7.11" + "hono": "^4.7.11", + "http-server": "^14.1.1" }, "devDependencies": { "wrangler": "^4.4.0" @@ -1052,6 +1053,21 @@ "node": ">= 6.0.0" } }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/arrify": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", @@ -1071,6 +1087,12 @@ "printable-characters": "^1.0.42" } }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -1091,6 +1113,24 @@ ], "license": "MIT" }, + "node_modules/basic-auth": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", + "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.1.2" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/basic-auth/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, "node_modules/bignumber.js": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.0.tgz", @@ -1142,6 +1182,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/color": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", @@ -1160,7 +1216,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "license": "MIT", "dependencies": { "color-name": "~1.1.4" @@ -1173,7 +1228,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, "license": "MIT" }, "node_modules/color-string": { @@ -1197,6 +1251,15 @@ "node": ">= 0.6" } }, + "node_modules/corser": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz", + "integrity": "sha512-utCYNzRSQIZNPIcGZdQc92UVJYAhtGAteCFg0yRaFm8f0P+CPtyGyHXJcGXnffjCybUCEx3FQ2G7U3/o9eIkVQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/data-uri-to-buffer": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-2.0.2.tgz", @@ -1332,6 +1395,12 @@ "@esbuild/win32-x64": "0.25.4" } }, + "node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "license": "MIT" + }, "node_modules/exit-hook": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/exit-hook/-/exit-hook-2.2.1.tgz", @@ -1364,6 +1433,26 @@ "integrity": "sha512-VhXlQgj9ioXCqGstD37E/HBeqEGV/qOD/kmbVG8h5xKBYvM1L3lR1Zn4555cQ8GkYbJa8aJSipLPndE1k6zK2w==", "license": "Apache-2.0" }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1563,6 +1652,15 @@ "node": ">=12.0.0" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", @@ -1587,6 +1685,15 @@ "node": ">= 0.4" } }, + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "license": "MIT", + "bin": { + "he": "bin/he" + } + }, "node_modules/hono": { "version": "4.7.11", "resolved": "https://registry.npmjs.org/hono/-/hono-4.7.11.tgz", @@ -1596,6 +1703,71 @@ "node": ">=16.9.0" } }, + "node_modules/html-encoding-sniffer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-3.0.0.tgz", + "integrity": "sha512-oWv4T4yJ52iKrufjnyZPkrN0CH3QnrUqdB6In1g5Fe1mia8GmF36gnfNySxoZtxD5+NmYw1EElVXiBk93UeskA==", + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/http-proxy": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", + "license": "MIT", + "dependencies": { + "eventemitter3": "^4.0.0", + "follow-redirects": "^1.0.0", + "requires-port": "^1.0.0" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/http-server": { + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/http-server/-/http-server-14.1.1.tgz", + "integrity": "sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A==", + "license": "MIT", + "dependencies": { + "basic-auth": "^2.0.1", + "chalk": "^4.1.2", + "corser": "^2.0.1", + "he": "^1.2.0", + "html-encoding-sniffer": "^3.0.0", + "http-proxy": "^1.18.1", + "mime": "^1.6.0", + "minimist": "^1.2.6", + "opener": "^1.5.1", + "portfinder": "^1.0.28", + "secure-compare": "3.0.1", + "union": "~0.5.0", + "url-join": "^4.0.1" + }, + "bin": { + "http-server": "bin/http-server" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/http-server/node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -1609,6 +1781,18 @@ "node": ">= 6" } }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-arrayish": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", @@ -1746,6 +1930,15 @@ "node": ">=18.0.0" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -1826,6 +2019,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/opener": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", + "integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==", + "license": "(WTFPL OR MIT)", + "bin": { + "opener": "bin/opener-bin.js" + } + }, "node_modules/path-to-regexp": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", @@ -1840,6 +2042,19 @@ "dev": true, "license": "MIT" }, + "node_modules/portfinder": { + "version": "1.0.37", + "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.37.tgz", + "integrity": "sha512-yuGIEjDAYnnOex9ddMnKZEMFE0CcGo6zbfzDklkmT1m5z734ss6JMzN9rNB3+RR7iS+F10D4/BVIaXOyh8PQKw==", + "license": "MIT", + "dependencies": { + "async": "^3.2.6", + "debug": "^4.3.6" + }, + "engines": { + "node": ">= 10.12" + } + }, "node_modules/printable-characters": { "version": "1.0.42", "resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz", @@ -1862,6 +2077,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "license": "MIT" + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -1882,6 +2103,18 @@ ], "license": "MIT" }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/secure-compare": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/secure-compare/-/secure-compare-3.0.1.tgz", + "integrity": "sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==", + "license": "MIT" + }, "node_modules/semver": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", @@ -2055,6 +2288,18 @@ "npm": ">=6" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -2103,6 +2348,23 @@ "ufo": "^1.6.1" } }, + "node_modules/union": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/union/-/union-0.5.0.tgz", + "integrity": "sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==", + "dependencies": { + "qs": "^6.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", + "license": "MIT" + }, "node_modules/url-template": { "version": "2.0.8", "resolved": "https://registry.npmjs.org/url-template/-/url-template-2.0.8.tgz", @@ -2128,6 +2390,18 @@ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", "license": "BSD-2-Clause" }, + "node_modules/whatwg-encoding": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-2.0.0.tgz", + "integrity": "sha512-p41ogyeMUrw3jWclHWTQg1k05DSVXPLcVxRTYsXUk+ZooOCZLcoYgPZ/HL/D/N+uQPOtcp1me1WhBEaX02mhWg==", + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", diff --git a/package.json b/package.json index 3686314..b98b93b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "@cloudflare/workers-types": "^4.20250610.0", "@google-cloud/local-auth": "^2.1.0", "googleapis": "^105.0.0", - "hono": "^4.7.11" + "hono": "^4.7.11", + "http-server": "^14.1.1" }, "devDependencies": { "wrangler": "^4.4.0" diff --git a/public/index.html b/public/index.html index 76777a2..c964f6c 100644 --- a/public/index.html +++ b/public/index.html @@ -103,66 +103,68 @@ - -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- -
- -
- - -
- -
- - -
- -
-

- 本工具所有信息只以Cookie形式存储于浏览器本地
- 开源于 GitHub | By OpenListTeam -

-
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+

+ 本工具所有信息只以Cookie形式存储于浏览器本地
+ 开源于 GitHub | By OpenListTeam +

+
+ diff --git a/src/115ui.ts b/src/115ui.ts index 8d83f52..9ad541f 100644 --- a/src/115ui.ts +++ b/src/115ui.ts @@ -21,7 +21,7 @@ export async function oneLogin(c: Context) { client_id: client_uid, state: random_key, response_type: 'code', - redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback' + redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback' }; const urlWithParams = new URL(driver_map[0]); Object.keys(params_all).forEach(key => { @@ -58,7 +58,7 @@ export async function oneToken(c: Context) { params_all = { client_id: client_uid, client_secret: client_key, - redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback', + redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback', code: login_data, grant_type: 'authorization_code' }; diff --git a/src/123ui.ts b/src/123ui.ts new file mode 100644 index 0000000..e03a7e5 --- /dev/null +++ b/src/123ui.ts @@ -0,0 +1,48 @@ +import * as local from "hono/cookie"; +import {Context} from "hono"; +import {showErr} from "./error"; + + +const driver_map: string[] = [ + "https://open-api.123pan.com/api/v1/access_token", + "https://open-api.123pan.com/api/v1/access_token" +] + +// 登录申请 ############################################################################## +export async function oneLogin(c: Context) { + const client_uid = c.req.query('client_uid'); + const client_key = c.req.query('client_key'); + const driver_txt = c.req.query('apps_types'); + if (!driver_txt || !client_uid || !client_key) + return c.json({text: "参数缺少"}, 500); + // 请求参数 ========================================================================== + const params_all: Record = { + client_id: client_uid, + clientSecret: client_key, + + }; + // 执行请求 =========================================================================== + try { + const paramsString = new URLSearchParams(params_all).toString(); + const response: Response = await fetch(driver_map[0], { + method: 'POST', body: paramsString, + headers: { + 'Platform': "open_platform", + 'Content-Type': 'application/x-www-form-urlencoded' + }, + }); + const json: Record = await response.json(); + local.setCookie(c, 'client_uid', client_uid); + local.setCookie(c, 'client_key', client_key); + local.setCookie(c, 'driver_txt', driver_txt); + console.log(json); + return c.json({text: json.data.accessToken}, 200); + } catch (error) { + return c.json({text: error}, 500); + } +} + +// 令牌申请 ############################################################################## +export async function oneToken(c: Context) { + return await oneLogin(c); +} diff --git a/src/goapi.ts b/src/goapi.ts index b5556f7..5689604 100644 --- a/src/goapi.ts +++ b/src/goapi.ts @@ -4,8 +4,8 @@ import {showErr} from "./error"; const driver_map: string[] = [ - "https://passportapi.115.com/open/authorize", - "https://passportapi.115.com/open/authCodeToToken" + "https://accounts.google.com/o/oauth2/v2/auth", + "https://oauth2.googleapis.com/token" ] // 登录申请 ############################################################################## @@ -15,27 +15,28 @@ export async function oneLogin(c: Context) { const driver_txt = c.req.query('apps_types'); if (!driver_txt || !client_uid || !client_key) return c.json({text: "参数缺少"}, 500); - const random_key = getRandomString(64); + const random_key = getRandomString(32); // 请求参数 ========================================================================== const params_all: Record = { - client_id: client_uid, - state: random_key, - response_type: 'code', - redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback' + 'client_id': client_uid, + 'redirect_uri': 'https://' + c.env.MAIN_URLS + '/googleui/callback', + 'scope': "https://www.googleapis.com/auth/drive", + 'response_type': 'code', + 'state': random_key, + 'access_type': 'offline', + 'prompt': 'consent' }; + local.setCookie(c, 'client_uid', client_uid); + local.setCookie(c, 'client_key', client_key); + local.setCookie(c, 'driver_txt', driver_txt); + local.setCookie(c, 'random_key', random_key); const urlWithParams = new URL(driver_map[0]); Object.keys(params_all).forEach(key => { urlWithParams.searchParams.append(key, params_all[key]); }); // 执行请求 =========================================================================== try { - const response = await fetch(urlWithParams.href, {method: 'GET',}); - local.setCookie(c, 'client_uid', client_uid); - local.setCookie(c, 'client_key', client_key); - local.setCookie(c, 'driver_txt', driver_txt); - local.setCookie(c, 'random_key', random_key); - console.log(response); - return c.json({text: response.url}, 200); + return c.json({text: urlWithParams}, 200); } catch (error) { return c.json({text: error}, 500); } @@ -44,7 +45,7 @@ export async function oneLogin(c: Context) { // 令牌申请 ############################################################################## export async function oneToken(c: Context) { let login_data, client_uid, client_key, random_key; - let driver_txt, client_url, params_all, random_uid; + let driver_txt, params_all, random_uid; try { // 请求参数 ==================================================================== login_data = c.req.query('code'); random_uid = c.req.query('state'); @@ -52,39 +53,37 @@ export async function oneToken(c: Context) { client_key = local.getCookie(c, 'client_key') random_key = local.getCookie(c, 'random_key') driver_txt = local.getCookie(c, 'driver_txt') + // console.log(login_data, random_uid, client_uid, client_key, random_key, driver_txt) if (!client_uid || !client_key || random_uid !== random_key || !client_uid || !client_key) return c.redirect(showErr("Cookie无效", "", "")); - client_url = driver_map[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' + 'client_id': client_uid, + 'client_secret': client_key, + 'code': login_data, + 'grant_type': 'authorization_code', + 'redirect_uri': 'https://' + c.env.MAIN_URLS + '/googleui/callback', }; } catch (error) { return c.redirect(showErr(error, "", "")); } - // console.log(login_data); - + console.log(params_all); // 执行请求 =========================================================================== try { const paramsString = new URLSearchParams(params_all).toString(); - const response: Response = await fetch(client_url, { + const response: Response = await fetch(driver_map[1], { method: 'POST', body: paramsString, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, + headers: {'Content-Type': 'application/x-www-form-urlencoded',}, }); local.deleteCookie(c, 'client_uid'); local.deleteCookie(c, 'client_key'); local.deleteCookie(c, 'random_key'); local.deleteCookie(c, 'driver_txt'); let json: Record = await response.json(); - if (json.state == 1) { + console.log(json); + if (json.token_type == "Bearer") { return c.redirect( - `/?access_token=${json.data.access_token}` - + `&refresh_token=${json.data.refresh_token}` + `/?access_token=${json.access_token}` + + `&refresh_token=${json.refresh_token}` + `&client_uid=${client_uid}` + `&client_key=${client_key}` + `&driver_txt=${driver_txt}` diff --git a/src/index.ts b/src/index.ts index 0e08f16..2f7ff1a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import * as local from "hono/cookie"; import * as oneui from './oneui'; import * as aliui from './aliui'; import * as ui115 from './115ui'; +import * as ui123 from './123ui'; import * as baidu from './baidu'; import * as goapi from './goapi'; export type Bindings = { @@ -53,6 +54,16 @@ app.get('/115cloud/callback', async (c: Context) => { return ui115.oneToken(c); }); +// 登录申请 ############################################################################## +app.get('/123cloud/requests', async (c: Context) => { + return ui123.oneLogin(c); +}); + +// 令牌申请 ############################################################################## +app.get('/123cloud/callback', async (c: Context) => { + return ui123.oneToken(c); +}); + // 登录申请 ############################################################################## app.get('/googleui/requests', async (c: Context) => { return goapi.oneLogin(c); diff --git a/wrangler.jsonc b/wrangler.jsonc deleted file mode 100644 index 243ac9a..0000000 --- a/wrangler.jsonc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "node_modules/wrangler/config-schema.json", - "name": "cf-worker-api", - "main": "src/index.ts", - "compatibility_date": "2025-05-25", - "compatibility_flags": [ - "nodejs_compat" - ], - "vars": { - "MAIN_URLS": "api.oplist.org" - }, - "site": { - "bucket": "./public" - }, -} diff --git a/wrangler.jsonc.example b/wrangler.jsonc.example new file mode 100644 index 0000000..505bc7a --- /dev/null +++ b/wrangler.jsonc.example @@ -0,0 +1,27 @@ +{ + "$schema": "node_modules/wrangler/config-schema.json", + "name": "cf-worker-api", + "main": "src/index.ts", + "compatibility_date": "2025-05-25", + "compatibility_flags": [ + "nodejs_compat" + ], + "vars": { + "MAIN_URLS": "api.oplist.org", + "onedrive_uid": "", + "onedrive_key": "", + "alicloud_uid": "", + "alicloud_key": "", + "baiduyun_uid": "", + "baiduyun_key": "", + "115cloud_uid": "", + "115cloud_key": "", + "123cloud_uid": "", + "123cloud_key": "", + "googleui_uid": "", + "googleui_key": "" + }, + "site": { + "bucket": "./public" + } +}