add server app
This commit is contained in:
parent
efab5ee9b0
commit
a9da119ab1
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,4 +10,5 @@ yarn-error.log*
|
||||
|
||||
.vscode/*
|
||||
.wrangler/*
|
||||
wrangler.jsonc
|
||||
wrangler.jsonc
|
||||
.idea
|
25
.idea/workspace.xml
generated
25
.idea/workspace.xml
generated
@ -4,15 +4,17 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="987ac7e2-ceaa-49a2-b5c9-aed65a7c598d" name="更改" comment="deal 115 baidu cloud">
|
||||
<list default="true" id="987ac7e2-ceaa-49a2-b5c9-aed65a7c598d" name="更改" comment="deal google & 123 pan">
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/package-lock.json" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/public/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/public/index.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/115ui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/115ui.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/123ui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/123ui.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/aliui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/aliui.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/baidu.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/baidu.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/goapi.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/goapi.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/index.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/wrangler.jsonc" beforeDir="false" afterPath="$PROJECT_DIR$/wrangler.jsonc" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/oneui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/oneui.ts" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -83,7 +85,7 @@
|
||||
<updated>1749696640494</updated>
|
||||
<workItem from="1749696641557" duration="119000" />
|
||||
<workItem from="1749696773818" duration="18000" />
|
||||
<workItem from="1749696801474" duration="51180000" />
|
||||
<workItem from="1749696801474" duration="54159000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="fin onedrive official token">
|
||||
<option name="closed" value="true" />
|
||||
@ -141,7 +143,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1749806487624</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="8" />
|
||||
<task id="LOCAL-00008" summary="deal google & 123 pan">
|
||||
<option name="closed" value="true" />
|
||||
<created>1749813968987</created>
|
||||
<option name="number" value="00008" />
|
||||
<option name="presentableId" value="LOCAL-00008" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1749813968987</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="9" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@ -154,6 +164,7 @@
|
||||
<MESSAGE value="deal merge issue" />
|
||||
<MESSAGE value="deal ali cloud scan login" />
|
||||
<MESSAGE value="deal 115 baidu cloud" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="deal 115 baidu cloud" />
|
||||
<MESSAGE value="deal google & 123 pan" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="deal google & 123 pan" />
|
||||
</component>
|
||||
</project>
|
@ -177,7 +177,8 @@
|
||||
let apps_keys = document.getElementById("app-secret").value;
|
||||
let apps_type = document.getElementById("site-select").value;
|
||||
let secret_key = document.getElementById("secret-key").value;
|
||||
if (apps_uuid === "" || apps_keys === "") {
|
||||
console.log(server_use);
|
||||
if (server_use === "off" && (apps_uuid === "" || apps_keys === "")) {
|
||||
Swal.fire({
|
||||
position: 'top',
|
||||
icon: 'info',
|
||||
@ -316,13 +317,14 @@
|
||||
const appSecretInput = document.getElementById('app-secret');
|
||||
const secretKeyInput = document.getElementById('secret-key');
|
||||
const server_flag = document.getElementById('server_use');
|
||||
if (siteSelect.value === "alicloud_qr" && server_flag.checked) {
|
||||
if ((siteSelect.value === "alicloud_qr"
|
||||
|| siteSelect.value === "123cloud_go") && server_flag.checked) {
|
||||
server_flag.checked = false;
|
||||
Swal.fire({
|
||||
position: 'top',
|
||||
icon: 'error',
|
||||
title: '暂不支持',
|
||||
html: "阿里云暂不支持",
|
||||
html: "阿里云和123云盘暂不支持使用官方密钥",
|
||||
showConfirmButton: true,
|
||||
});
|
||||
return;
|
||||
|
45
src/115ui.ts
45
src/115ui.ts
@ -10,15 +10,16 @@ const driver_map: string[] = [
|
||||
|
||||
// 登录申请 ##############################################################################
|
||||
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)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
const random_key = getRandomString(64);
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
client_id: client_uid,
|
||||
client_id: server_use == "on" ? c.env.cloud115_uid : client_uid,
|
||||
state: random_key,
|
||||
response_type: 'code',
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback'
|
||||
@ -30,10 +31,13 @@ export async function oneLogin(c: Context) {
|
||||
// 执行请求 ===========================================================================
|
||||
try {
|
||||
const response = await fetch(urlWithParams.href, {method: 'GET',});
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
if (server_use !== "on") {
|
||||
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);
|
||||
local.setCookie(c, 'server_use', server_use);
|
||||
console.log(response);
|
||||
return c.json({text: response.url}, 200);
|
||||
} catch (error) {
|
||||
@ -43,21 +47,27 @@ export async function oneLogin(c: Context) {
|
||||
|
||||
// 令牌申请 ##############################################################################
|
||||
export async function oneToken(c: Context) {
|
||||
let login_data, client_uid, client_key, random_key, client_url, params_all, random_uid, driver_txt;
|
||||
let login_data, client_uid, client_key, random_key, client_url;
|
||||
let server_use, params_all, random_uid, driver_txt;
|
||||
try { // 请求参数 ====================================================================
|
||||
login_data = c.req.query('code');
|
||||
random_uid = c.req.query('state');
|
||||
client_uid = local.getCookie(c, 'client_uid')
|
||||
client_key = local.getCookie(c, 'client_key')
|
||||
server_use = local.getCookie(c, 'server_use')
|
||||
random_key = local.getCookie(c, 'random_key')
|
||||
driver_txt = local.getCookie(c, 'driver_txt')
|
||||
if (server_use !== "on") {
|
||||
client_uid = local.getCookie(c, 'client_uid')
|
||||
client_key = local.getCookie(c, 'client_key')
|
||||
}
|
||||
|
||||
|
||||
if (!random_uid || !random_key || random_uid !== random_key
|
||||
|| !driver_txt || !login_data || !client_uid || !client_key)
|
||||
return c.redirect(showErr("Cookie无效", "", ""));
|
||||
client_url = driver_map[1];
|
||||
params_all = {
|
||||
client_id: client_uid,
|
||||
client_secret: client_key,
|
||||
client_id: server_use == "on" ? c.env.cloud115_uid : client_uid,
|
||||
client_secret: server_use == "on" ? c.env.cloud115_uid : client_key,
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback',
|
||||
code: login_data,
|
||||
grant_type: 'authorization_code'
|
||||
@ -76,17 +86,20 @@ export async function oneToken(c: Context) {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
});
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
if (server_use !== "on") {
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
}
|
||||
local.deleteCookie(c, 'random_key');
|
||||
local.deleteCookie(c, 'driver_txt');
|
||||
local.deleteCookie(c, 'server_use');
|
||||
let json: Record<string, any> = await response.json();
|
||||
if (json.state == 1) {
|
||||
return c.redirect(
|
||||
`/?access_token=${json.data.access_token}`
|
||||
+ `&refresh_token=${json.data.refresh_token}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`
|
||||
+ `&client_uid=${server_use == "on" ? "" : client_uid}`
|
||||
+ `&client_key=${server_use == "on" ? "" : client_key}`
|
||||
+ `&driver_txt=${driver_txt}`
|
||||
);
|
||||
}
|
||||
|
15
src/123ui.ts
15
src/123ui.ts
@ -10,16 +10,17 @@ const driver_map: string[] = [
|
||||
|
||||
// 登录申请 ##############################################################################
|
||||
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)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
console.log(server_use);
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
client_id: client_uid,
|
||||
clientSecret: client_key,
|
||||
|
||||
};
|
||||
// 执行请求 ===========================================================================
|
||||
try {
|
||||
@ -32,8 +33,8 @@ export async function oneLogin(c: Context) {
|
||||
},
|
||||
});
|
||||
const json: Record<string, any> = await response.json();
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
// 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);
|
||||
|
20
src/aliui.ts
20
src/aliui.ts
@ -30,14 +30,15 @@ interface AliQrcodeReq {
|
||||
// 登录申请 ##############################################################################
|
||||
export async function alyLogin(c: Context) {
|
||||
try {
|
||||
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)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
const req: AliQrcodeReq = {
|
||||
client_id: client_uid,
|
||||
client_secret: client_key,
|
||||
client_id: server_use == "on" ? c.env.alicloud_uid : client_uid,
|
||||
client_secret: server_use == "on" ? c.env.alicloud_key : client_key,
|
||||
scopes: ['user:base', 'file:all:read', 'file:all:write']
|
||||
}
|
||||
const response = await fetch(driver_map[0], {
|
||||
@ -50,6 +51,7 @@ export async function alyLogin(c: Context) {
|
||||
return c.json({text: `${error.code}: ${error.message}`}, 403);
|
||||
}
|
||||
local.setCookie(c, 'driver_txt', driver_txt);
|
||||
local.setCookie(c, 'server_use', server_use);
|
||||
const data: Record<string, any> = await response.json();
|
||||
console.log(data);
|
||||
return c.json({
|
||||
@ -64,9 +66,10 @@ export async function alyLogin(c: Context) {
|
||||
|
||||
// 令牌申请 ##############################################################################
|
||||
export async function alyToken(c: Context) {
|
||||
let server_use: string = <string>local.getCookie(c, 'server_use')
|
||||
const req: AliAccessTokenReq = {
|
||||
client_id: <string>c.req.query('client_id'),
|
||||
client_secret: <string>c.req.query('client_secret'),
|
||||
client_id: server_use == "on" ? c.env.alicloud_uid : <string>c.req.query('client_id'),
|
||||
client_secret: server_use == "on" ? c.env.alicloud_key : <string>c.req.query('client_secret'),
|
||||
grant_type: <string>c.req.query('grant_type'),
|
||||
code: <string>c.req.query('code'),
|
||||
refresh_token: <string>c.req.query('refresh_token')
|
||||
@ -87,6 +90,7 @@ export async function alyToken(c: Context) {
|
||||
req.code = code_data.authCode;
|
||||
}
|
||||
local.deleteCookie(c, 'driver_txt');
|
||||
local.deleteCookie(c, 'server_use');
|
||||
try {
|
||||
const response = await fetch(driver_map[1], {
|
||||
method: 'POST',
|
||||
|
54
src/baidu.ts
54
src/baidu.ts
@ -10,16 +10,17 @@ const driver_map: string[] = [
|
||||
|
||||
// 登录申请 ##############################################################################
|
||||
export async function oneLogin(c: Context) {
|
||||
const client_uid = c.req.query('client_uid');
|
||||
const client_key = c.req.query('client_key');
|
||||
const secret_key = c.req.query('secret_key');
|
||||
const driver_txt = c.req.query('apps_types');
|
||||
if (!driver_txt || !client_uid || !client_key || !secret_key)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const secret_key: string = <string>c.req.query('secret_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key || !secret_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
client_id: client_key,
|
||||
device_id: client_uid,
|
||||
client_id: server_use == "on" ? c.env.baiduyun_key : client_key,
|
||||
device_id: server_use == "on" ? c.env.baiduyun_uid : client_uid,
|
||||
scope: "basic,netdisk",
|
||||
response_type: 'code',
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/baiduyun/callback'
|
||||
@ -33,10 +34,13 @@ export async function oneLogin(c: Context) {
|
||||
const response = await fetch(urlWithParams.href, {
|
||||
method: 'GET',
|
||||
});
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
if (server_use !== "on") {
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
local.setCookie(c, 'secret_key', secret_key);
|
||||
}
|
||||
local.setCookie(c, 'driver_txt', driver_txt);
|
||||
local.setCookie(c, 'secret_key', secret_key);
|
||||
local.setCookie(c, 'server_use', server_use);
|
||||
console.log(response.url);
|
||||
return c.json({text: response.url}, 200);
|
||||
} catch (error) {
|
||||
@ -47,19 +51,23 @@ export async function oneLogin(c: Context) {
|
||||
// 令牌申请 ##############################################################################
|
||||
export async function oneToken(c: Context) {
|
||||
let login_data, client_uid, client_key, secret_key, client_url;
|
||||
let driver_txt, params_all: Record<string, any>;
|
||||
let driver_txt, server_use, params_all: Record<string, any>;
|
||||
try { // 请求参数 ====================================================================
|
||||
login_data = c.req.query('code');
|
||||
client_uid = local.getCookie(c, 'client_uid')
|
||||
client_key = local.getCookie(c, 'client_key')
|
||||
secret_key = local.getCookie(c, 'secret_key')
|
||||
server_use = local.getCookie(c, 'server_use')
|
||||
driver_txt = local.getCookie(c, 'driver_txt')
|
||||
client_uid = client_key = secret_key = ""
|
||||
if (server_use !== "on") {
|
||||
client_uid = local.getCookie(c, 'client_uid')
|
||||
client_key = local.getCookie(c, 'client_key')
|
||||
secret_key = local.getCookie(c, 'secret_key')
|
||||
}
|
||||
if (!login_data || !client_uid || !client_key || !secret_key)
|
||||
return c.redirect(showErr("Cookie缺少", "", ""));
|
||||
client_url = driver_map[1];
|
||||
params_all = {
|
||||
client_id: client_key,
|
||||
client_secret: secret_key,
|
||||
client_id: server_use == "on" ? c.env.baiduyun_key : client_key,
|
||||
client_secret: server_use == "on" ? c.env.baiduyun_ext : secret_key,
|
||||
code: login_data,
|
||||
grant_type: 'authorization_code',
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/baiduyun/callback'
|
||||
@ -77,9 +85,13 @@ export async function oneToken(c: Context) {
|
||||
urlWithParams.searchParams.append(key, params_all[key]);
|
||||
});
|
||||
const response: Response = await fetch(urlWithParams, {method: 'GET'});
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
local.deleteCookie(c, 'secret_key');
|
||||
if (server_use !== "on") {
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
local.deleteCookie(c, 'secret_key');
|
||||
}
|
||||
local.deleteCookie(c, 'driver_txt');
|
||||
local.deleteCookie(c, 'server_use');
|
||||
const json: Record<string, any> = await response.json();
|
||||
// console.log(response, json);
|
||||
if (response.ok) {
|
||||
@ -87,8 +99,8 @@ export async function oneToken(c: Context) {
|
||||
`/?access_token=${json.access_token}`
|
||||
+ `&refresh_token=${json.refresh_token}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`
|
||||
+ `&secret_key=${secret_key}`
|
||||
+ `&client_key=${server_use == "on" ? "" : client_key}`
|
||||
+ `&secret_key=${server_use == "on" ? "" : secret_key}`
|
||||
+ `&driver_txt=${driver_txt}`
|
||||
);
|
||||
}
|
||||
|
44
src/goapi.ts
44
src/goapi.ts
@ -10,15 +10,16 @@ const driver_map: string[] = [
|
||||
|
||||
// 登录申请 ##############################################################################
|
||||
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)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
const random_key = getRandomString(32);
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
'client_id': client_uid,
|
||||
'client_id': server_use == "on" ? c.env.onedrive_uid : client_uid,
|
||||
'redirect_uri': 'https://' + c.env.MAIN_URLS + '/googleui/callback',
|
||||
'scope': "https://www.googleapis.com/auth/drive",
|
||||
'response_type': 'code',
|
||||
@ -26,10 +27,13 @@ export async function oneLogin(c: Context) {
|
||||
'access_type': 'offline',
|
||||
'prompt': 'consent'
|
||||
};
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
if (server_use !== "on") {
|
||||
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);
|
||||
local.setCookie(c, 'server_use', server_use);
|
||||
const urlWithParams = new URL(driver_map[0]);
|
||||
Object.keys(params_all).forEach(key => {
|
||||
urlWithParams.searchParams.append(key, params_all[key]);
|
||||
@ -44,21 +48,26 @@ export async function oneLogin(c: Context) {
|
||||
|
||||
// 令牌申请 ##############################################################################
|
||||
export async function oneToken(c: Context) {
|
||||
let login_data, client_uid, client_key, random_key;
|
||||
let login_data, client_uid, client_key, random_key, server_use;
|
||||
let driver_txt, params_all, random_uid;
|
||||
try { // 请求参数 ====================================================================
|
||||
login_data = <string>c.req.query('code');
|
||||
random_uid = <string>c.req.query('state');
|
||||
client_uid = <string>local.getCookie(c, 'client_uid')
|
||||
client_key = <string>local.getCookie(c, 'client_key')
|
||||
server_use = local.getCookie(c, 'server_use')
|
||||
driver_txt = <string>local.getCookie(c, 'driver_txt')
|
||||
client_uid = client_key = ""
|
||||
if (server_use !== "on") {
|
||||
client_uid = <string>local.getCookie(c, 'client_uid')
|
||||
client_key = <string>local.getCookie(c, 'client_key')
|
||||
}
|
||||
random_key = <string>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无效", "", ""));
|
||||
params_all = {
|
||||
'client_id': client_uid,
|
||||
'client_secret': client_key,
|
||||
'client_id': server_use == "on" ? c.env.googleui_uid : client_uid,
|
||||
'client_secret': server_use == "on" ? c.env.googleui_key : client_key,
|
||||
'code': login_data,
|
||||
'grant_type': 'authorization_code',
|
||||
'redirect_uri': 'https://' + c.env.MAIN_URLS + '/googleui/callback',
|
||||
@ -74,18 +83,21 @@ export async function oneToken(c: Context) {
|
||||
method: 'POST', body: paramsString,
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded',},
|
||||
});
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
if (server_use !== "on") {
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
}
|
||||
local.deleteCookie(c, 'random_key');
|
||||
local.deleteCookie(c, 'driver_txt');
|
||||
local.deleteCookie(c, 'server_use');
|
||||
let json: Record<string, any> = await response.json();
|
||||
console.log(json);
|
||||
if (json.token_type == "Bearer") {
|
||||
return c.redirect(
|
||||
`/?access_token=${json.access_token}`
|
||||
+ `&refresh_token=${json.refresh_token}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`
|
||||
+ `&client_uid=${server_use == "on" ? "" : client_uid}`
|
||||
+ `&client_key=${server_use == "on" ? "" : client_key}`
|
||||
+ `&driver_txt=${driver_txt}`
|
||||
);
|
||||
}
|
||||
|
@ -9,8 +9,14 @@ import * as ui115 from './115ui';
|
||||
import * as ui123 from './123ui';
|
||||
import * as baidu from './baidu';
|
||||
import * as goapi from './goapi';
|
||||
|
||||
export type Bindings = {
|
||||
MAIN_URLS: string
|
||||
MAIN_URLS: string,
|
||||
onedrive_uid: string, onedrive_key: string,
|
||||
alicloud_uid: string, alicloud_key: string,
|
||||
baiduyun_uid: string, baiduyun_key: string,
|
||||
cloud115_uid: string, cloud115_key: string,
|
||||
googleui_uid: string, googleui_key: string,
|
||||
}
|
||||
const app = new Hono<{ Bindings: Bindings }>()
|
||||
app.use("*", serveStatic({manifest: manifest, root: "./"}));
|
||||
|
72
src/oneui.ts
72
src/oneui.ts
@ -1,5 +1,6 @@
|
||||
import * as local from "hono/cookie";
|
||||
import {Context} from "hono";
|
||||
import {showErr} from "./error";
|
||||
|
||||
|
||||
const driver_map: Record<string, string[]> = {
|
||||
@ -23,16 +24,17 @@ const driver_map: Record<string, string[]> = {
|
||||
|
||||
// 登录申请 ##############################################################################
|
||||
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)
|
||||
const client_uid: string = <string>c.req.query('client_uid');
|
||||
const client_key: string = <string>c.req.query('client_key');
|
||||
const driver_txt: string = <string>c.req.query('apps_types');
|
||||
const server_use: string = <string>c.req.query('server_use');
|
||||
if (server_use == "off" && (!driver_txt || !client_uid || !client_key))
|
||||
return c.json({text: "参数缺少"}, 500);
|
||||
const scopes_all = 'offline_access Files.ReadWrite.All';
|
||||
const client_url: string = driver_map[driver_txt][0];
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
client_id: client_uid,
|
||||
client_id: server_use == "on" ? c.env.onedrive_uid : client_uid,
|
||||
scope: scopes_all,
|
||||
response_type: 'code',
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback'
|
||||
@ -46,9 +48,12 @@ export async function oneLogin(c: Context) {
|
||||
const response = await fetch(urlWithParams.href, {
|
||||
method: 'GET',
|
||||
});
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
if (server_use !== "on") {
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
}
|
||||
local.setCookie(c, 'driver_txt', driver_txt);
|
||||
local.setCookie(c, 'server_use', server_use);
|
||||
return c.json({text: response.url}, 200);
|
||||
} catch (error) {
|
||||
return c.json({text: error}, 500);
|
||||
@ -57,30 +62,26 @@ export async function oneLogin(c: Context) {
|
||||
|
||||
// 令牌申请 ##############################################################################
|
||||
export async function oneToken(c: Context) {
|
||||
let login_data, client_uid, client_key, driver_txt, client_url, params_all;
|
||||
let login_data, client_uid, client_key, driver_txt, client_url, server_use, params_all;
|
||||
try { // 请求参数 ====================================================================
|
||||
login_data = <string>c.req.query('code');
|
||||
client_uid = <string>local.getCookie(c, 'client_uid')
|
||||
client_key = <string>local.getCookie(c, 'client_key')
|
||||
server_use = local.getCookie(c, 'server_use')
|
||||
driver_txt = <string>local.getCookie(c, 'driver_txt')
|
||||
client_uid = client_key = ""
|
||||
if (server_use !== "on") {
|
||||
client_uid = <string>local.getCookie(c, 'client_uid')
|
||||
client_key = <string>local.getCookie(c, 'client_key')
|
||||
}
|
||||
client_url = driver_map[driver_txt][1];
|
||||
params_all = {
|
||||
client_id: client_uid,
|
||||
client_secret: client_key,
|
||||
client_id: server_use == "on" ? c.env.onedrive_uid : client_uid,
|
||||
client_secret: server_use == "on" ? c.env.onedrive_key : client_key,
|
||||
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback',
|
||||
code: login_data,
|
||||
grant_type: 'authorization_code'
|
||||
};
|
||||
} catch (error) {
|
||||
return c.redirect(
|
||||
`/?message_err=${"授权失败,请检查: <br>" +
|
||||
"1、应用ID和应用机密是否正确<br>" +
|
||||
"2、登录账号是否具有应用权限<br>" +
|
||||
"3、回调地址是否包括上面地址<br>" +
|
||||
"4、登录可能过期,请重新登录<br>" +
|
||||
"错误信息: <br> " + error}`
|
||||
+ `&client_uid=`
|
||||
+ `&client_key=`);
|
||||
return c.redirect(showErr("参数错误", "", ""));
|
||||
}
|
||||
// console.log(login_data);
|
||||
|
||||
@ -95,38 +96,27 @@ export async function oneToken(c: Context) {
|
||||
body: paramsString,
|
||||
});
|
||||
// console.log(response);
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
if (server_use !== "on") {
|
||||
local.deleteCookie(c, 'client_uid');
|
||||
local.deleteCookie(c, 'client_key');
|
||||
}
|
||||
local.deleteCookie(c, 'apps_types');
|
||||
local.deleteCookie(c, 'driver_txt');
|
||||
local.deleteCookie(c, 'server_use');
|
||||
if (!response.ok)
|
||||
return c.redirect(
|
||||
`/?message_err=${"授权失败,请检查: <br>" +
|
||||
"1、应用ID和应用机密是否正确<br>" +
|
||||
"2、登录账号是否具有应用权限<br>" +
|
||||
"3、回调地址是否包括上面地址<br>" +
|
||||
"错误信息: <br>" + response.text()}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`);
|
||||
return c.redirect(showErr("请求失败", client_uid, client_key));
|
||||
const json: Record<string, any> = await response.json();
|
||||
if (json.token_type === 'Bearer') {
|
||||
return c.redirect(
|
||||
`/?access_token=${json.access_token}`
|
||||
+ `&refresh_token=${json.refresh_token}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`
|
||||
+ `&client_uid=${server_use == "on" ? "" : client_uid}`
|
||||
+ `&client_key=${server_use == "on" ? "" : client_key}`
|
||||
+ `&driver_txt=${driver_txt}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.redirect(
|
||||
`/?message_err=${"授权失败,请检查: <br>" +
|
||||
"1、应用ID和应用机密是否正确<br>" +
|
||||
"2、登录账号是否具有应用权限<br>" +
|
||||
"3、回调地址是否包括上面地址<br>" +
|
||||
"错误信息: <br>" + error}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`);
|
||||
return c.redirect(showErr(<string>error, client_uid, client_key));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user