Merge branch 'main' into main

This commit is contained in:
Pikachu Ren 2025-06-15 09:56:34 +08:00 committed by GitHub
commit fd3b9ac6eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 1820 additions and 201 deletions

2
.gitignore vendored
View File

@ -10,3 +10,5 @@ yarn-error.log*
.vscode/* .vscode/*
.wrangler/* .wrangler/*
wrangler.jsonc
.idea

View File

@ -2,6 +2,7 @@
<dictionary name="project"> <dictionary name="project">
<words> <words>
<w>alicloud</w> <w>alicloud</w>
<w>baiduyun</w>
</words> </words>
</dictionary> </dictionary>
</component> </component>

61
.idea/workspace.xml generated
View File

@ -4,11 +4,16 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="987ac7e2-ceaa-49a2-b5c9-aed65a7c598d" name="更改" comment="deal ali cloud scan login"> <list default="true" id="987ac7e2-ceaa-49a2-b5c9-aed65a7c598d" name="更改" comment="add server app">
<change beforePath="$PROJECT_DIR$/.idea/cf-worker-api.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/cf-worker-api.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/public/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/public/index.html" 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/oneui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/oneui.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/oneui.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/oneui.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/wrangler.jsonc.example" beforeDir="false" afterPath="$PROJECT_DIR$/wrangler.jsonc.example" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -68,6 +73,11 @@
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="G:\AList\cf-worker-api" /> <recent name="G:\AList\cf-worker-api" />
<recent name="G:\AList\cf-worker-api\public" />
<recent name="G:\AList\cf-worker-api\src" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="G:\AList\cf-worker-api\public" />
</key> </key>
</component> </component>
<component name="SharedIndexes"> <component name="SharedIndexes">
@ -129,7 +139,47 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1749714906877</updated> <updated>1749714906877</updated>
</task> </task>
<option name="localTasksCounter" value="6" /> <task id="LOCAL-00006" summary="deal ali cloud scan login">
<option name="closed" value="true" />
<created>1749720117274</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1749720117274</updated>
</task>
<task id="LOCAL-00007" summary="deal 115 baidu cloud">
<option name="closed" value="true" />
<created>1749806487624</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1749806487624</updated>
</task>
<task id="LOCAL-00008" summary="deal google &amp; 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>
<task id="LOCAL-00009" summary="add server app">
<option name="closed" value="true" />
<created>1749817021359</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1749817021359</updated>
</task>
<task id="LOCAL-00010" summary="add server app">
<option name="closed" value="true" />
<created>1749817071777</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1749817071777</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -141,6 +191,9 @@
<MESSAGE value="add onedrive area: cn us de" /> <MESSAGE value="add onedrive area: cn us de" />
<MESSAGE value="deal merge issue" /> <MESSAGE value="deal merge issue" />
<MESSAGE value="deal ali cloud scan login" /> <MESSAGE value="deal ali cloud scan login" />
<option name="LAST_COMMIT_MESSAGE" value="deal ali cloud scan login" /> <MESSAGE value="deal 115 baidu cloud" />
<MESSAGE value="deal google &amp; 123 pan" />
<MESSAGE value="add server app" />
<option name="LAST_COMMIT_MESSAGE" value="add server app" />
</component> </component>
</project> </project>

View File

@ -1,10 +1,77 @@
# OpenList API Token Generator # OpenList API Token Generator
## 项目说明
用于OpenList获取部分网盘API的接口和页面
部署地址:[OpenList Token 获取工具](https://api.oplist.org/)
## 接口文档
### 登录接口
- #### 接口地址
#### `https://api.oplist.org/<driver>/requests`
- #### 接口参数
| 参数名称 | 类型 | 必要 | 示例 | 说明 |
| ------------ | ----- | ---- | -------------------------------- | ---------------------------------- |
| `driver` | `str` | 是 | onedrive | 平台驱动名称,详见"配置设置"部分 |
| `client_uid` | `str` | 是 | 4308adf60f3fe4058533 | 提供客户端ID详见"配置设置"部分 |
| `client_key` | `str` | 是 | 09F260A4BF5EF7F4181E35E59759C0BC | 提供应用密码,详见"配置设置"部分 |
| `apps_types` | `str` | 是 | onedrive_go | 驱动类型,格式 `driver`+`类型后缀` |
| `server_set` | `str` | 是 | true | 是否使用服务器预设的应用ID和密钥 |
| `secret_key` | `str` | 否 | 3yp8NOMsRulxll44f5ayrxF1vgBfPW85 | 百度网盘额外需要 secret_key字段 |
### 回调接口
- #### 接口地址
#### `https://api.oplist.org/<driver>/callback`
- #### 接口参数
| 参数名称 | 类型 | 必要 | 示例 | 说明 |
| ------------ | ----- | ---- | -------------------------------- | -------------------------------- |
| `driver` | `str` | 是 | onedrive | 平台驱动名称,详见"配置设置"部分 |
| `code` | `str` | 是 | 40YJzShAJSodbIXvNEw3Ru9N4Lkznx93 | 回调的认证代码登录之后URL自带 |
| `client_uid` | `str` | 否 | 4308adf60f3fe4058533 | 阿里云盘验证码登录提供client_uid |
| `client_key` | `str` | 否 | 09F260A4BF5EF7F4181E35E59759C0BC | 阿里云盘验证码登录提供client_key |
| `grant_type` | `str` | 否 | authorization_code | 阿里云盘固定authorization_code |
## 配置设置
| 网盘驱动 | 区域类型 | driver | apps_types | client_uid | client_key | secret_key |
| -------- | -------- | -------- | ----------- | ---------- | ------------- | ---------- |
| Onedrive | 企业版本 | onedrive | onedrive_go | 客户端ID | 客户端秘钥 | / |
| Onedrive | 世纪互联 | onedrive | onedrive_cn | 客户端ID | 客户端秘钥 | / |
| Onedrive | 美国版本 | onedrive | onedrive_us | 客户端ID | 客户端秘钥 | / |
| Onedrive | 德国版本 | onedrive | onedrive_de | 客户端ID | 客户端秘钥 | / |
| 阿里云盘 | 扫码登录 | alicloud | alicloud_qr | APP ID | App Secret | / |
| 百度云盘 | 验证登录 | baiduyun | baiduyun_go | AppID | AppKey | SecretKey |
| 115 云盘 | 验证登录 | 115cloud | 115cloud_go | AppID | AppSecret | / |
| 123 云盘 | 验证登录 | 123cloud | 123cloud_go | client_id | client_secret | / |
| 谷歌云盘 | 验证登录 | googleui | googleui_go | 客户端ID | 客户端秘钥 | / |
## 部署方法
### 测试代码
```txt ```txt
npm install npm install
npm run dev npm run dev
``` ```
### 部署项目
```txt ```txt
npm run deploy npm run deploy
``` ```

980
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,10 @@
}, },
"dependencies": { "dependencies": {
"@cloudflare/workers-types": "^4.20250610.0", "@cloudflare/workers-types": "^4.20250610.0",
"hono": "^4.7.11" "@google-cloud/local-auth": "^2.1.0",
"googleapis": "^105.0.0",
"hono": "^4.7.11",
"http-server": "^14.1.1"
}, },
"devDependencies": { "devDependencies": {
"wrangler": "^4.4.0" "wrangler": "^4.4.0"

View File

@ -4,8 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OpenList Token 获取工具</title> <title>OpenList Token 获取工具</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://jsd.tencent.to/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script src="https://jsd.tencent.to/npm/sweetalert2@11.22.0/dist/sweetalert2.all.min.js"></script>
<style> <style>
:root { :root {
--bg-color-light: #ffffff; --bg-color-light: #ffffff;
@ -102,62 +102,77 @@
<div class="mb-3"> <div class="mb-3">
<label for="site-select" class="form-label">网盘名称</label> <label for="site-select" class="form-label">网盘名称</label>
<select id="site-select" class="form-select"> <select id="site-select" class="form-select">
<option value="onedrive_go" selected>OneDrive 官方站点</option> <!-- <option value="onedrive_pr" selected>OneDrive 个人账户</option>-->
<option value="onedrive_go" selected>OneDrive 企业版本</option>
<option value="onedrive_cn">OneDrive 世纪互联</option> <option value="onedrive_cn">OneDrive 世纪互联</option>
<option value="onedrive_us">OneDrive 美国版本</option> <option value="onedrive_us">OneDrive 美国版本</option>
<option value="onedrive_de">OneDrive 德国版本</option> <option value="onedrive_de">OneDrive 德国版本</option>
<option value="alicloud_qr">阿里网盘 扫码登录</option> <option value="alicloud_qr">阿里网盘 扫码登录</option>
<option value="baiduyun_go">百度网盘 验证登录</option>
<option value="115cloud_go">115 网盘 验证登录</option>
<option value="123cloud_go">123 网盘 直接登录</option>
<option value="googleui_go">Google Drive Team</option>
</select> </select>
</div>
<div class="mb-3"> <div class="mb-3" style="margin-top: 15px">
<label for="client-id" class="form-label">客户端 ID</label> <input type="checkbox" id="server_use" class="form-check-input">
<input type="text" id="client-id" class="form-control"> <label for="server_use" class="form-check-label">使用 OpenList 提供的参数</label>
</div> </div>
<div class="mb-3"> <div class="mb-3" id="client-id-view">
<label for="app-secret" class="form-label">应用机密</label> <label for="client-id" class="form-label">Client ID客户端ID</label>
<input type="text" id="app-secret" class="form-control"> <input type="text" id="client-id" class="form-control">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="callback-url" class="form-label">回调地址</label> <label for="app-secret" class="form-label">AppKey应用秘钥</label>
<input type="text" id="callback-url" class="form-control" value="https://api.oplist.org/onedrive/callback" <input type="text" id="app-secret" class="form-control">
readonly </div>
onclick="autoCopy(this)">
</div>
<div class="d-grid gap-2 mb-3"> <div class="mb-3" id="secret-key-view">
<button class="btn btn-primary" onclick="getLogin()">获取 Token</button> <label for="secret-key" class="form-label">SecretKey访问秘钥</label>
</div> <input type="text" id="secret-key" class="form-control">
</div>
<div class="mb-3"> <div class="mb-3">
<label for="access-token" class="form-label">访问秘钥</label> <label for="callback-url" class="form-label">回调地址</label>
<textarea id="access-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea> <input type="text" id="callback-url" class="form-control" value="https://api.oplist.org/onedrive/callback"
</div> readonly
onclick="autoCopy(this)">
</div>
<div class="mb-3"> <div class="d-grid gap-2 mb-3">
<label for="refresh-token" class="form-label">刷新秘钥</label> <button class="btn btn-primary" onclick="getLogin()">获取 Token</button>
<textarea id="refresh-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea> </div>
</div>
<div class="mb-3"> <div class="mb-3">
<label for="sharepoint-url" class="form-label">SharePoint Site URL</label> <label for="access-token" class="form-label">访问秘钥</label>
<label for="sharepoint-url"></label><input type="text" id="sharepoint-url" class="form-control"> <textarea id="access-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
</div> </div>
<div class="d-grid gap-2 mb-3">
<button class="btn btn-primary" onclick="getSiteID()">获取 SharePoint 站点ID</button> <div class="mb-3">
</div> <label for="refresh-token" class="form-label">刷新秘钥</label>
<div class="mb-3"> <textarea id="refresh-token" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
<label for="sharepoint-id" class="form-label">SharePoint Site URL</label> </div>
<textarea id="sharepoint-id" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea> <div class="mb-3">
</div> <label for="sharepoint-url" class="form-label">SharePoint Site URL</label>
<div class="text-muted text-center"> <label for="sharepoint-url"></label><input type="text" id="sharepoint-url" class="form-control">
<p style="text-align:center"> </div>
本工具所有信息只以Cookie形式存储于浏览器本地<br> <div class="d-grid gap-2 mb-3">
开源于 <a href="https://github.com/OpenListTeam/cf-worker-api" target="_blank">GitHub</a> | By <a <button class="btn btn-primary" onclick="getSiteID()">获取 SharePoint 站点ID</button>
href="https://github.com/OpenListTeam" </div>
target="_blank">OpenListTeam</a> <div class="mb-3">
</p> <label for="sharepoint-id" class="form-label">SharePoint Site URL</label>
</div> <textarea id="sharepoint-id" class="form-control" rows="3" readonly onclick="autoCopy(this)"></textarea>
</div>
<div class="text-muted text-center">
<p style="text-align:center">
本工具所有信息只以Cookie形式存储于浏览器本地<br>
开源于 <a href="https://github.com/OpenListTeam/cf-worker-api" target="_blank">GitHub</a> | By <a
href="https://github.com/OpenListTeam"
target="_blank">OpenListTeam</a>
</p>
</div> </div>
</div> </div>
@ -166,22 +181,27 @@
// 获取登录秘钥 ####################################################### // 获取登录秘钥 #######################################################
async function getLogin() { async function getLogin() {
let server_use = document.getElementById("server_use").checked;
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; let apps_type = document.getElementById("site-select").value;
if (apps_uuid === "" || apps_keys === "") { let secret_key = document.getElementById("secret-key").value;
console.log(server_use);
if (!server_use && (apps_uuid === "" || apps_keys === "")) {
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
icon: 'info', icon: 'info',
title: '获取失败', title: '获取失败',
text: '请先填写客户端ID和应用机密', text: '请先填写AppID和AppKey',
showConfirmButton: true, showConfirmButton: true,
}); });
return; return;
} }
let apps_subs = apps_type.split("_")[0] let apps_subs = apps_type.split("_")[0]
let post_urls = "/" + apps_subs + "/requests?client_uid=" + apps_uuid let post_urls = "/" + apps_subs + "/requests?client_uid=" + apps_uuid
+ "&client_key=" + apps_keys + "&apps_type=" + apps_type; + "&client_key=" + apps_keys + "&apps_types=" + apps_type
+ "&server_use=" + server_use
if (apps_subs === "baiduyun") post_urls += "&secret_key=" + secret_key
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'}
@ -189,9 +209,14 @@
// 解析响应内容 =============================================== // 解析响应内容 ===============================================
const response_data = await response.json(); const response_data = await response.json();
if (response.status === 200) { if (response.status === 200) {
if (apps_subs === "onedrive") { if (apps_subs === "onedrive" || apps_subs === "115cloud"
|| apps_subs === "baiduyun" || apps_subs === "googleui") {
window.location.href = response_data.text; window.location.href = response_data.text;
} }
if (apps_subs === "123cloud") {
document.getElementById("access-token").value = response_data.text;
return;
}
if (apps_type === "alicloud_qr") { if (apps_type === "alicloud_qr") {
let sid = response_data.sid; let sid = response_data.sid;
await Swal.fire({ await Swal.fire({
@ -260,12 +285,84 @@
async function getToken() { async function getToken() {
const strSearch = window.location.search; const strSearch = window.location.search;
const urlParams = new URLSearchParams(strSearch); const urlParams = new URLSearchParams(strSearch);
const server_use = urlParams.get("server_use");
const client_uid = urlParams.get("client_uid"); const client_uid = urlParams.get("client_uid");
const secret_key = urlParams.get("secret_key");
const driver_txt = urlParams.get("driver_txt");
const client_key = urlParams.get("client_key"); const client_key = urlParams.get("client_key");
const access_token = urlParams.get("access_token"); const access_token = urlParams.get("access_token");
const refresh_token = urlParams.get("refresh_token"); const refresh_token = urlParams.get("refresh_token");
const message_err = urlParams.get("message_err"); const message_err = urlParams.get("message_err");
if (message_err && client_uid) { document.getElementById("site-select").value = driver_txt;
if (!driver_txt || driver_txt === "")
document.getElementById("site-select").value = "onedrive_go";
document.getElementById("app-secret").value = client_key;
document.getElementById("client-id").value = client_uid;
document.getElementById("access-token").value = access_token;
document.getElementById("refresh-token").value = refresh_token;
if (secret_key)
document.getElementById("secret-key").value = secret_key;
// 获取select元素和输入框元素
const siteSelect = document.getElementById('site-select');
const callbackUrlInput = document.getElementById('callback-url');
// 监听select的变化
siteSelect.addEventListener('change', function () {
const selectedValue = this.value.split("_")[0]; // 获取选中的value
// 更新输入框的值
callbackUrlInput.value = `https://api.oplist.org/${selectedValue}/callback`;
document.getElementById('secret-key-view').hidden = true;
if (siteSelect.value === "baiduyun_go") {
document.getElementById('secret-key-view').hidden = false;
document.getElementById('client-id-view').hidden = true;
}else{
document.getElementById('client-id-view').hidden = false;
}
});
document.getElementById('server_use').addEventListener('change', function () {
const clientIdInput = document.getElementById('client-id');
const appSecretInput = document.getElementById('app-secret');
const secretKeyInput = document.getElementById('secret-key');
const server_flag = document.getElementById('server_use');
if ((siteSelect.value === "alicloud_qr"
|| siteSelect.value === "123cloud_go"
|| siteSelect.value === "onedrive_cn"
|| siteSelect.value === "onedrive_us"
|| siteSelect.value === "onedrive_de"
) && server_flag.checked) {
server_flag.checked = false;
Swal.fire({
position: 'top',
icon: 'error',
title: '暂不支持',
html: "阿里云、123云盘、OneDrive非美国区域暂不支持使用官方密钥",
showConfirmButton: true,
});
return;
}
if (this.checked) {
// 禁用输入框并清空内容
clientIdInput.disabled = true;
clientIdInput.value = '';
appSecretInput.disabled = true;
appSecretInput.value = '';
secretKeyInput.disabled = true;
secretKeyInput.value = '';
} else {
// 启用输入框
clientIdInput.disabled = false;
appSecretInput.disabled = false;
secretKeyInput.disabled = false;
}
});
// 页面加载时初始化回调地址
window.onload = function () {
siteSelect.dispatchEvent(new Event('change'));
};
if (message_err) {
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
icon: 'error', icon: 'error',
@ -274,13 +371,9 @@
showConfirmButton: true, showConfirmButton: true,
}); });
} }
document.getElementById("client-id").value = client_uid;
document.getElementById("app-secret").value = client_key;
document.getElementById("access-token").value = access_token;
document.getElementById("refresh-token").value = refresh_token;
} }
getToken();
// 获取站点ID // 获取站点ID
function getSiteID() { function getSiteID() {
const siteUrl = document.getElementById("sharepoint-url").value.trim(); const siteUrl = document.getElementById("sharepoint-url").value.trim();
@ -387,7 +480,6 @@
console.error("URL解析失败:", error); console.error("URL解析失败:", error);
} }
} }
//手动切换主题模式 //手动切换主题模式
function toggleTheme() { function toggleTheme() {
const html = document.documentElement; const html = document.documentElement;
@ -401,6 +493,8 @@
if (hour < 6 || hour >= 18) document.documentElement.setAttribute("data-theme", "dark"); if (hour < 6 || hour >= 18) document.documentElement.setAttribute("data-theme", "dark");
getToken(); getToken();
})(); })();
getToken();
</script> </script>
</body> </body>
</html> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

View File

@ -1,58 +0,0 @@
/* 手动设置字体链接 */
@font-face {
font-family: 'MapleMonoNL';
src: url('/static/maple-min.ttf');
}
* {
font-family: MapleMonoNL, sans-serif;
}
body {
margin: 0;
padding: 0;
font-family: MapleMonoNL, sans-serif;
background: url('/static/cdn-image.jpg') no-repeat center center fixed;
background-size: cover;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.form-container {
background: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.input-group {
margin-bottom: 20px;
}
.input-group label {
display: block;
margin-bottom: 5px;
color: #555;
}
.input-group input, .input-group select,.input-group textarea{
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 10px; /* 修改圆角为10px */
box-sizing: border-box;
}

120
src/115ui.ts Normal file
View File

@ -0,0 +1,120 @@
import * as local from "hono/cookie";
import {Context} from "hono";
import {showErr} from "./error";
const driver_map: string[] = [
"https://passportapi.115.com/open/authorize",
"https://passportapi.115.com/open/authCodeToToken"
]
// 登录申请 ##############################################################################
export async function oneLogin(c: Context) {
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 == "false" && (!driver_txt || !client_uid || !client_key))
return c.json({text: "参数缺少"}, 500);
const random_key = getRandomString(64);
console.log(server_use);
// 请求参数 ==========================================================================
const params_all: Record<string, any> = {
client_id: server_use == "true" ? c.env.cloud115_uid : client_uid,
state: random_key,
response_type: 'code',
redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback'
};
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',});
if (server_use == "false") {
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) {
return c.json({text: error}, 500);
}
}
// 令牌申请 ##############################################################################
export async function oneToken(c: Context) {
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');
server_use = local.getCookie(c, 'server_use')
random_key = local.getCookie(c, 'random_key')
driver_txt = local.getCookie(c, 'driver_txt')
if (server_use == "false") {
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: server_use == "true" ? c.env.cloud115_uid : client_uid,
client_secret: server_use == "true" ? c.env.cloud115_key : client_key,
redirect_uri: 'https://' + c.env.MAIN_URLS + '/115cloud/callback',
code: login_data,
grant_type: 'authorization_code'
};
} catch (error) {
return c.redirect(showErr(<string>error, "", ""));
}
// console.log(login_data);
// 执行请求 ===========================================================================
try {
const paramsString = new URLSearchParams(params_all).toString();
const response: Response = await fetch(client_url, {
method: 'POST', body: paramsString,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
if (server_use == "false") {
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=${server_use == "true" ? "" : client_uid}`
+ `&client_key=${server_use == "true" ? "" : client_key}`
+ `&driver_txt=${driver_txt}`
);
}
return c.redirect(showErr(json.message, client_uid, client_key));
} catch (error) {
return c.redirect(showErr(<string>error, client_uid, client_key));
}
}
function getRandomString(length: number): string {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}

47
src/123ui.ts Normal file
View File

@ -0,0 +1,47 @@
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: 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 == "false" && (!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 {
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<string, any> = await response.json();
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);
}

View File

@ -1,4 +1,5 @@
import {Context} from "hono"; import {Context} from "hono";
import * as local from "hono/cookie";
const driver_map = [ const driver_map = [
'https://openapi.aliyundrive.com/oauth/authorize/qrcode', 'https://openapi.aliyundrive.com/oauth/authorize/qrcode',
@ -29,9 +30,15 @@ interface AliQrcodeReq {
// 登录申请 ############################################################################## // 登录申请 ##############################################################################
export async function alyLogin(c: Context) { export async function alyLogin(c: Context) {
try { try {
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 == "false" && (!driver_txt || !client_uid || !client_key))
return c.json({text: "参数缺少"}, 500);
const req: AliQrcodeReq = { const req: AliQrcodeReq = {
client_id: <string>c.req.query('client_uid'), client_id: server_use == "true" ? c.env.alicloud_uid : client_uid,
client_secret: <string>c.req.query('client_key'), client_secret: server_use == "true" ? c.env.alicloud_key : client_key,
scopes: ['user:base', 'file:all:read', 'file:all:write'] scopes: ['user:base', 'file:all:read', 'file:all:write']
} }
const response = await fetch(driver_map[0], { const response = await fetch(driver_map[0], {
@ -43,6 +50,8 @@ export async function alyLogin(c: Context) {
const error: AliAccessTokenErr = await response.json(); const error: AliAccessTokenErr = await response.json();
return c.json({text: `${error.code}: ${error.message}`}, 403); 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(); const data: Record<string, any> = await response.json();
console.log(data); console.log(data);
return c.json({ return c.json({
@ -57,9 +66,10 @@ export async function alyLogin(c: Context) {
// 令牌申请 ############################################################################## // 令牌申请 ##############################################################################
export async function alyToken(c: Context) { export async function alyToken(c: Context) {
let server_use: string = <string>local.getCookie(c, 'server_use')
const req: AliAccessTokenReq = { const req: AliAccessTokenReq = {
client_id: <string>c.req.query('client_id'), client_id: server_use == "true" ? c.env.alicloud_uid : <string>c.req.query('client_id'),
client_secret: <string>c.req.query('client_secret'), client_secret: server_use == "true" ? c.env.alicloud_key : <string>c.req.query('client_secret'),
grant_type: <string>c.req.query('grant_type'), grant_type: <string>c.req.query('grant_type'),
code: <string>c.req.query('code'), code: <string>c.req.query('code'),
refresh_token: <string>c.req.query('refresh_token') refresh_token: <string>c.req.query('refresh_token')
@ -79,6 +89,8 @@ export async function alyToken(c: Context) {
} }
req.code = code_data.authCode; req.code = code_data.authCode;
} }
local.deleteCookie(c, 'driver_txt');
local.deleteCookie(c, 'server_use');
try { try {
const response = await fetch(driver_map[1], { const response = await fetch(driver_map[1], {
method: 'POST', method: 'POST',

107
src/baidu.ts Normal file
View File

@ -0,0 +1,107 @@
import * as local from "hono/cookie";
import {Context} from "hono";
import {showErr} from "./error";
const driver_map: string[] = [
"https://openapi.baidu.com/oauth/2.0/authorize",
"https://openapi.baidu.com/oauth/2.0/token"
]
// 登录申请 ##############################################################################
export async function oneLogin(c: Context) {
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 == "false" && (!driver_txt || !client_key || !secret_key))
return c.json({text: "参数缺少"}, 500);
// 请求参数 ==========================================================================
const params_all: Record<string, any> = {
client_id: server_use == "true" ? c.env.baiduyun_key : client_key,
scope: "basic,netdisk",
response_type: 'code',
redirect_uri: 'https://' + c.env.MAIN_URLS + '/baiduyun/callback'
};
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',
});
if (server_use == "false") {
local.setCookie(c, 'client_key', client_key);
local.setCookie(c, 'secret_key', secret_key);
}
local.setCookie(c, 'driver_txt', driver_txt);
local.setCookie(c, 'server_use', server_use);
console.log(response.url);
return c.json({text: response.url}, 200);
} catch (error) {
return c.json({text: error}, 500);
}
}
// 令牌申请 ##############################################################################
export async function oneToken(c: Context) {
let login_data, client_key, secret_key, client_url;
let driver_txt, server_use, params_all: Record<string, any>;
try { // 请求参数 ====================================================================
login_data = c.req.query('code');
server_use = local.getCookie(c, 'server_use')
driver_txt = local.getCookie(c, 'driver_txt')
client_key = secret_key = ""
if (server_use == "false") {
client_key = local.getCookie(c, 'client_key')
secret_key = local.getCookie(c, 'secret_key')
if (!login_data || !client_key || !secret_key)
return c.redirect(showErr("Cookie缺少", "", ""));
}
client_url = driver_map[1];
params_all = {
client_id: server_use == "true" ? c.env.baiduyun_key : client_key,
client_secret: server_use == "true" ? c.env.baiduyun_ext : secret_key,
code: login_data,
grant_type: 'authorization_code',
redirect_uri: 'https://' + c.env.MAIN_URLS + '/baiduyun/callback'
};
} catch (error) {
return c.redirect(showErr(<string>error, "", ""));
}
// console.log(login_data);
// 执行请求 ===========================================================================
try {
const paramsString = new URLSearchParams(params_all).toString();
const urlWithParams = new URL(client_url);
Object.keys(params_all).forEach(key => {
urlWithParams.searchParams.append(key, params_all[key]);
});
const response: Response = await fetch(urlWithParams, {method: 'GET'});
if (server_use == "false") {
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) {
return c.redirect(
`/?access_token=${json.access_token}`
+ `&refresh_token=${json.refresh_token}`
+ `&client_key=${server_use == "true" ? "" : client_key}`
+ `&secret_key=${server_use == "true" ? "" : secret_key}`
+ `&driver_txt=${driver_txt}`
);
}
return c.redirect(showErr(json.error_description, client_key));
} catch (error) {
return c.redirect(showErr(<string>error, client_key));
}
}

9
src/error.ts Normal file
View File

@ -0,0 +1,9 @@
export function showErr(error: string, client_uid: string, client_key: string) {
return `/?message_err=${"授权失败,请检查: <br>" +
"1、应用ID和应用机密是否正确<br>" +
"2、登录账号是否具有应用权限<br>" +
"3、回调地址是否包括上面地址<br>" +
"错误信息: <br>" + error}`
+ `&client_uid=${client_uid}`
+ `&client_key=${client_key}`;
}

119
src/goapi.ts Normal file
View File

@ -0,0 +1,119 @@
import * as local from "hono/cookie";
import {Context} from "hono";
import {showErr} from "./error";
const driver_map: string[] = [
"https://accounts.google.com/o/oauth2/v2/auth",
"https://oauth2.googleapis.com/token"
]
// 登录申请 ##############################################################################
export async function oneLogin(c: Context) {
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 == "false" && (!driver_txt || !client_uid || !client_key))
return c.json({text: "参数缺少"}, 500);
const random_key = getRandomString(32);
// 请求参数 ==========================================================================
const params_all: Record<string, any> = {
'client_id': server_use == "true" ? c.env.googleui_uid : 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'
};
if (server_use == "false") {
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]);
});
// 执行请求 ===========================================================================
try {
return c.json({text: urlWithParams}, 200);
} catch (error) {
return c.json({text: error}, 500);
}
}
// 令牌申请 ##############################################################################
export async function oneToken(c: Context) {
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');
server_use = local.getCookie(c, 'server_use')
driver_txt = <string>local.getCookie(c, 'driver_txt')
client_uid = client_key = ""
if (server_use == "false") {
client_uid = <string>local.getCookie(c, 'client_uid')
client_key = <string>local.getCookie(c, 'client_key')
if (!client_uid || !client_key || random_uid !== random_key || !client_uid || !client_key)
return c.redirect(showErr("Cookie无效", "", ""));
}
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)
params_all = {
'client_id': server_use == "true" ? c.env.googleui_uid : client_uid,
'client_secret': server_use == "true" ? c.env.googleui_key : client_key,
'code': login_data,
'grant_type': 'authorization_code',
'redirect_uri': 'https://' + c.env.MAIN_URLS + '/googleui/callback',
};
} catch (error) {
return c.redirect(showErr(<string>error, "", ""));
}
console.log(params_all);
// 执行请求 ===========================================================================
try {
const paramsString = new URLSearchParams(params_all).toString();
const response: Response = await fetch(driver_map[1], {
method: 'POST', body: paramsString,
headers: {'Content-Type': 'application/x-www-form-urlencoded',},
});
if (server_use == "false") {
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=${server_use == "true" ? "" : client_uid}`
+ `&client_key=${server_use == "true" ? "" : client_key}`
+ `&driver_txt=${driver_txt}`
);
}
return c.redirect(showErr(json.message, client_uid, client_key));
} catch (error) {
return c.redirect(showErr(<string>error, client_uid, client_key));
}
}
function getRandomString(length: number): string {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}

View File

@ -5,9 +5,18 @@ import manifest from '__STATIC_CONTENT_MANIFEST'
import * as local from "hono/cookie"; import * as local from "hono/cookie";
import * as oneui from './oneui'; import * as oneui from './oneui';
import * as aliui from './aliui'; 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 = { export type Bindings = {
MAIN_URLS: string MAIN_URLS: string, baiduyun_ext: 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 }>() const app = new Hono<{ Bindings: Bindings }>()
app.use("*", serveStatic({manifest: manifest, root: "./"})); app.use("*", serveStatic({manifest: manifest, root: "./"}));
@ -31,4 +40,45 @@ app.get('/alicloud/callback', async (c: Context) => {
return aliui.alyToken(c); return aliui.alyToken(c);
}); });
// 登录申请 ##############################################################################
app.get('/baiduyun/requests', async (c: Context) => {
return baidu.oneLogin(c);
});
// 令牌申请 ##############################################################################
app.get('/baiduyun/callback', async (c: Context) => {
return baidu.oneToken(c);
});
// 登录申请 ##############################################################################
app.get('/115cloud/requests', async (c: Context) => {
return ui115.oneLogin(c);
});
// 令牌申请 ##############################################################################
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);
});
// 令牌申请 ##############################################################################
app.get('/googleui/callback', async (c: Context) => {
return goapi.oneToken(c);
});
export default app export default app

View File

@ -1,5 +1,7 @@
import * as local from "hono/cookie"; import * as local from "hono/cookie";
import {Context} from "hono"; import {Context} from "hono";
import {showErr} from "./error";
const driver_map: Record<string, string[]> = { const driver_map: Record<string, string[]> = {
"onedrive_go": [ "onedrive_go": [
@ -7,7 +9,7 @@ const driver_map: Record<string, string[]> = {
'https://login.microsoftonline.com/common/oauth2/v2.0/token' 'https://login.microsoftonline.com/common/oauth2/v2.0/token'
], ],
"onedrive_cn": [ "onedrive_cn": [
'https://login.chinacloudapi.cn/common/oauth2/authorize', 'https://login.chinacloudapi.cn/common/oauth2/v2.0/authorize',
'https://login.chinacloudapi.cn/common/oauth2/token' 'https://login.chinacloudapi.cn/common/oauth2/token'
], ],
"onedrive_de": [ "onedrive_de": [
@ -22,14 +24,17 @@ const driver_map: Record<string, string[]> = {
// 登录申请 ############################################################################## // 登录申请 ##############################################################################
export async function oneLogin(c: Context) { export async function oneLogin(c: Context) {
const client_uid = <string>c.req.query('client_uid'); const client_uid: string = <string>c.req.query('client_uid');
const client_key = <string>c.req.query('client_key'); const client_key: string = <string>c.req.query('client_key');
const driver_txt = <string>c.req.query('apps_type'); const driver_txt: string = <string>c.req.query('apps_types');
const server_use: string = <string>c.req.query('server_use');
if (server_use == "false" && (!driver_txt || !client_uid || !client_key))
return c.json({text: "参数缺少"}, 500);
const scopes_all = 'offline_access Files.ReadWrite.All'; const scopes_all = 'offline_access Files.ReadWrite.All';
const client_url: string = driver_map[driver_txt][0]; 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: server_use == "true" ? c.env.onedrive_uid : client_uid,
scope: scopes_all, scope: scopes_all,
response_type: 'code', response_type: 'code',
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback' redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback'
@ -43,9 +48,12 @@ export async function oneLogin(c: Context) {
const response = await fetch(urlWithParams.href, { const response = await fetch(urlWithParams.href, {
method: 'GET', method: 'GET',
}); });
local.setCookie(c, 'client_uid', client_uid); if (server_use == "false") {
local.setCookie(c, 'client_key', client_key); local.setCookie(c, 'client_uid', client_uid);
local.setCookie(c, 'apps_types', driver_txt); 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); return c.json({text: response.url}, 200);
} catch (error) { } catch (error) {
return c.json({text: error}, 500); return c.json({text: error}, 500);
@ -54,30 +62,26 @@ export async function oneLogin(c: Context) {
// 令牌申请 ############################################################################## // 令牌申请 ##############################################################################
export async function oneToken(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 { // 请求参数 ==================================================================== try { // 请求参数 ====================================================================
login_data = <string>c.req.query('code'); login_data = <string>c.req.query('code');
client_uid = <string>local.getCookie(c, 'client_uid') server_use = local.getCookie(c, 'server_use')
client_key = <string>local.getCookie(c, 'client_key') driver_txt = <string>local.getCookie(c, 'driver_txt')
driver_txt = <string>local.getCookie(c, 'apps_types') client_uid = client_key = ""
if (server_use == "false") {
client_uid = <string>local.getCookie(c, 'client_uid')
client_key = <string>local.getCookie(c, 'client_key')
}
client_url = driver_map[driver_txt][1]; client_url = driver_map[driver_txt][1];
params_all = { params_all = {
client_id: client_uid, client_id: server_use == "true" ? c.env.onedrive_uid : client_uid,
client_secret: client_key, client_secret: server_use == "true" ? c.env.onedrive_key : client_key,
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback', redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback',
code: login_data, code: login_data,
grant_type: 'authorization_code' grant_type: 'authorization_code'
}; };
} catch (error) { } catch (error) {
return c.redirect( return c.redirect(showErr("参数错误", "", ""));
`/?message_err=${"授权失败,请检查: <br>" +
"1、应用ID和应用机密是否正确<br>" +
"2、登录账号是否具有应用权限<br>" +
"3、回调地址是否包括上面地址<br>" +
"4、登录可能过期请重新登录<br>" +
"错误信息: <br> " + error}`
+ `&client_uid=NULL`
+ `&client_key=`);
} }
// console.log(login_data); // console.log(login_data);
@ -92,34 +96,52 @@ export async function oneToken(c: Context) {
body: paramsString, body: paramsString,
}); });
// console.log(response); // console.log(response);
local.deleteCookie(c, 'client_uid'); if (server_use == "false") {
local.deleteCookie(c, 'client_key'); local.deleteCookie(c, 'client_uid');
local.deleteCookie(c, 'client_key');
}
local.deleteCookie(c, 'apps_types'); local.deleteCookie(c, 'apps_types');
local.deleteCookie(c, 'driver_txt');
local.deleteCookie(c, 'server_use');
if (!response.ok) if (!response.ok)
return c.redirect( return c.redirect(showErr("请求失败", client_uid, client_key));
`/?message_err=${"授权失败,请检查: <br>" +
"1、应用ID和应用机密是否正确<br>" +
"2、登录账号是否具有应用权限<br>" +
"3、回调地址是否包括上面地址<br>" +
"错误信息: <br>" + response.text()}`
+ `&client_uid=${client_uid}`
+ `&client_key=${client_key}`);
const json: Record<string, any> = await response.json(); const json: Record<string, any> = await response.json();
if (json.token_type === 'Bearer') { if (json.token_type === 'Bearer') {
return c.redirect( return c.redirect(
`/?access_token=${json.access_token}` `/?access_token=${json.access_token}`
+ `&refresh_token=${json.refresh_token}` + `&refresh_token=${json.refresh_token}`
+ `&client_uid=${client_uid}` + `&client_uid=${server_use == "true" ? "" : client_uid}`
+ `&client_key=${client_key}`); + `&client_key=${server_use == "true" ? "" : client_key}`
+ `&driver_txt=${driver_txt}`
);
} }
} catch (error) { } catch (error) {
return c.redirect( return c.redirect(showErr(<string>error, client_uid, client_key));
`/?message_err=${"授权失败,请检查: <br>" + }
"1、应用ID和应用机密是否正确<br>" + }
"2、登录账号是否具有应用权限<br>" +
"3、回调地址是否包括上面地址<br>" + export async function spSiteID(c: Context) {
"错误信息: <br>" + error}` type Req = {
+ `&client_uid=${client_uid}` access_token: string;
+ `&client_key=${client_key}`); site_url: string;
zone: string;
};
const req: Req = await c.req.json();
const u = new URL(req.site_url);
const siteName = u.pathname;
if (driver_map[req.zone]) {
const response = await fetch(`${driver_map[req.zone][1]}/v1.0/sites/root:/${siteName}`, {
headers: {'Authorization': `Bearer ${req.access_token}`}
});
if (!response.ok) {
return c.json({error: 'Failed to fetch site ID'}, 403);
}
const data: Record<string, any> = await response.json();
console.log(data);
return c.json(data);
} else {
return c.json({error: 'Zone does not exist'}, 400);
} }
} }

View File

@ -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"
},
}

26
wrangler.jsonc.example Normal file
View File

@ -0,0 +1,26 @@
{
"$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": "",
"baiduyun_ext": "",
"115cloud_uid": "",
"115cloud_key": "",
"googleui_uid": "",
"googleui_key": ""
},
"site": {
"bucket": "./public"
}
}