From be38793c5150bd2d24c9c1ae9739e06f8ac449ed Mon Sep 17 00:00:00 2001 From: pikachuim Date: Mon, 16 Jun 2025 17:53:29 +0800 Subject: [PATCH] fix google drive cookie issue add aliyun2 refresh add yandex refresh add baiduyun oob mode --- public/static/token.js | 2 +- src/index.ts | 2 +- src/yandex.ts | 35 +++++++++++++++++++++++++++-------- wrangler.jsonc.example | 4 +++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/public/static/token.js b/public/static/token.js index 07b66aa..fa42e58 100644 --- a/public/static/token.js +++ b/public/static/token.js @@ -80,7 +80,7 @@ async function getToken() { if (siteSelect.value == "baiduyun_ob") { document.getElementById("app-secret").value = "NqOMXF6XGhGRIGemsQ9nG0Na"; document.getElementById("secret-key").value = "SVT6xpMdLcx6v4aCR4wT8BBOTbzFO8LM"; - + document.getElementById("callback-url").value = "oob"; } } else { document.getElementById('client-id-view').hidden = false; diff --git a/src/index.ts b/src/index.ts index c0dbe6e..08dda26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ export type Bindings = { baiduyun_uid: string, baiduyun_key: string, cloud115_uid: string, cloud115_key: string, googleui_uid: string, googleui_key: string, - YANDEX_CLIENT_ID: string, YANDEX_CLIENT_SECRET: string, + yandexui_uid: string, yandexui_key: string, } const app = new Hono<{ Bindings: Bindings }>() diff --git a/src/yandex.ts b/src/yandex.ts index 45a11d8..013f6df 100644 --- a/src/yandex.ts +++ b/src/yandex.ts @@ -1,6 +1,9 @@ import {Context} from "hono"; import {showErr} from "./error"; import * as local from "hono/cookie"; +import * as refresh from "./shares/refresh" +import * as configs from "./shares/configs" + interface Token { token_type?: string; access_token?: string; @@ -13,14 +16,18 @@ interface Token { export async function yandexLogin(c: Context) { const env = c.env - const client_uid: string = c.req.query('client_uid'); - const client_key: string = c.req.query('client_key'); - const server_use: string = c.req.query('server_use'); - if (server_use == "false" && (!client_uid || !client_key)) + let client_uid: string | undefined = c.req.query('client_uid'); + let client_key: string | undefined = c.req.query('client_key'); + let server_use: string | undefined = c.req.query('server_use'); + if(!server_use) return c.json({text: "参数缺少"}, 500); + if (!client_uid || !client_key) + if (server_use == "false") + return c.json({text: "参数缺少"}, 500); + client_uid = client_key = "" const params_all: Record = { response_type: 'code', - client_id: server_use == "true" ? env.YANDEX_CLIENT_ID : client_uid, + client_id: server_use == "true" ? env.yandexui_uid : client_uid, }; if (server_use == "false") { local.setCookie(c, 'client_uid', client_uid); @@ -48,8 +55,8 @@ export async function yandexCallBack(c: Context) { const getToken = async (): Promise => { const params = new URLSearchParams(); params.append("grant_type", "authorization_code"); - params.append("client_id", env.YANDEX_CLIENT_ID); - params.append("client_secret", env.YANDEX_CLIENT_SECRET); + params.append("client_id", env.yandexui_uid); + params.append("client_secret", env.yandexui_key); params.append("code", code); const resp = await fetch("https://oauth.yandex.com/token", { @@ -102,5 +109,17 @@ export async function yandexCallBack(c: Context) { // 刷新令牌 ############################################################################## export async function genToken(c: Context) { - return c.json({text: "此网盘不支持"}, 500); + const clients_info: configs.Clients | undefined = configs.getInfo(c); + const refresh_text: string | undefined = c.req.query('refresh_ui'); + if (!clients_info) return c.json({text: "传入参数缺少"}, 500); + if (!refresh_text) return c.json({text: "缺少刷新令牌"}, 500); + // 请求参数 ========================================================================== + const params: Record = { + grant_type: "refresh_token", + refresh_token: refresh_text, + client_id: clients_info.servers ? c.env.alicloud_uid : clients_info.app_uid, + client_secret: clients_info.servers ? c.env.alicloud_key : clients_info.app_key, + }; + return await refresh.genToken(c, "https://oauth.yandex.com/token", params, "POST", + "data.access_token", "data.refresh_token", "error"); } \ No newline at end of file diff --git a/wrangler.jsonc.example b/wrangler.jsonc.example index 9f0ab76..9cbb121 100644 --- a/wrangler.jsonc.example +++ b/wrangler.jsonc.example @@ -18,7 +18,9 @@ "115cloud_uid": "", "115cloud_key": "", "googleui_uid": "", - "googleui_key": "" + "googleui_key": "", + "yandexui_uid": "", + "yandexui_key": "" }, "site": { "bucket": "./public"