Merge branch 'main' into main
This commit is contained in:
commit
c1b932a9bb
@ -56,12 +56,53 @@
|
||||
<body>
|
||||
<div class="toggle-theme">
|
||||
<button class="btn btn-outline-secondary" onclick="toggleTheme()">切换主题</button>
|
||||
</div><div class="container form-container">
|
||||
<h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2><div class="mb-3">
|
||||
</div>
|
||||
<div class="container form-container">
|
||||
<h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
|
||||
<div class="mb-3">
|
||||
<label for="site-select" class="form-label">网盘名称</label>
|
||||
<select id="site-select" class="form-select">
|
||||
<option value="official" selected>OneDrive 官方站点</option>
|
||||
<option value="onedrive_go" selected>OneDrive 官方站点</option>
|
||||
<option value="onedrive_cn">OneDrive 世纪互联</option>
|
||||
<option value="onedrive_us">OneDrive 美国版本</option>
|
||||
<option value="onedrive_de">OneDrive 德国版本</option>
|
||||
</select>
|
||||
|
||||
|
||||
<div class="input-group">
|
||||
<label for="client-id">客户端ID(Client ID)</label>
|
||||
<input type="text" id="client-id" name="client-id">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="app-secret">应用机密(App Secret)</label>
|
||||
<input type="text" id="app-secret" name="app-secret">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="callback-url">回调地址(Callback URL)</label>
|
||||
<input type="text" id="callback-url" name="callback-url" value="https://api.oplist.org/onedrive/callback"
|
||||
readonly onclick="autoCopy(this)">
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<button class="btn btn-success" onclick="getLogin()">获取Token</button>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="access-token">访问秘钥(Access Token)</label>
|
||||
<textarea type="text" id="access-token" name="access-token" readonly onclick="autoCopy(this)"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="refresh-token">刷新秘钥(Refresh Token)</label>
|
||||
<textarea type="text" id="refresh-token" name="refresh-token" readonly onclick="autoCopy(this)"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
本工具所有信息只以Cookie形式存储于浏览器本地,开源于<a href="https://github.com/OpenListTeam/cf-worker-api">CF-Worker-API</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@ -108,6 +149,7 @@
|
||||
async function getLogin() {
|
||||
let apps_uuid = document.getElementById("client-id").value;
|
||||
let apps_keys = document.getElementById("app-secret").value;
|
||||
let apps_type = document.getElementById("site-select").value;
|
||||
if (apps_uuid === "" || apps_keys === "") {
|
||||
Swal.fire({
|
||||
position: 'top',
|
||||
@ -119,7 +161,7 @@
|
||||
return;
|
||||
}
|
||||
let post_urls = "/onedrive/requests?client_uid=" + apps_uuid
|
||||
+ "&client_key=" + apps_keys;
|
||||
+ "&client_key=" + apps_keys + "&apps_type=" + apps_type;
|
||||
try {
|
||||
const response = await fetch(post_urls, {
|
||||
method: 'GET', headers: {'Content-Type': 'application/json'}
|
||||
|
34
src/index.ts
34
src/index.ts
@ -9,13 +9,31 @@ export type Bindings = {
|
||||
}
|
||||
const app = new Hono<{ Bindings: Bindings }>()
|
||||
app.use("*", serveStatic({manifest: manifest, root: "./"}));
|
||||
|
||||
const driver_map: Record<string, string[]> = {
|
||||
"onedrive_go": [
|
||||
'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
|
||||
'https://login.microsoftonline.com/common/oauth2/v2.0/token'
|
||||
],
|
||||
"onedrive_cn": [
|
||||
'https://login.chinacloudapi.cn/common/oauth2/v2.0/authorize',
|
||||
'https://microsoftgraph.chinacloudapi.cn/common/oauth2/v2.0/token'
|
||||
],
|
||||
"onedrive_de": [
|
||||
'https://login.microsoftonline.de/common/oauth2/v2.0/authorize',
|
||||
'https://graph.microsoft.de/common/oauth2/v2.0/token'
|
||||
],
|
||||
"onedrive_us": [
|
||||
'https://login.microsoftonline.us/common/oauth2/v2.0/authorize',
|
||||
'https://graph.microsoft.us/common/oauth2/v2.0/token'
|
||||
],
|
||||
}
|
||||
// 登录申请 ##############################################################################
|
||||
app.get('/onedrive/requests', async (c) => {
|
||||
const client_uid = <string>c.req.query('client_uid');
|
||||
const client_key = <string>c.req.query('client_key');
|
||||
const driver_txt = <string>c.req.query('apps_type');
|
||||
const scopes_all = 'offline_access Files.ReadWrite.All';
|
||||
const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
|
||||
const client_url: string = driver_map[driver_txt][0];
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all: Record<string, any> = {
|
||||
client_id: client_uid,
|
||||
@ -34,6 +52,7 @@ app.get('/onedrive/requests', async (c) => {
|
||||
});
|
||||
local.setCookie(c, 'client_uid', client_uid);
|
||||
local.setCookie(c, 'client_key', client_key);
|
||||
local.setCookie(c, 'apps_types', driver_txt);
|
||||
return c.json({text: response.url}, 200);
|
||||
} catch (error) {
|
||||
return c.json({text: error}, 500);
|
||||
@ -42,9 +61,10 @@ app.get('/onedrive/requests', async (c) => {
|
||||
// 令牌申请 ##############################################################################
|
||||
app.get('/onedrive/callback', async (c) => {
|
||||
const login_data = <string>c.req.query('code');
|
||||
const client_uid: string | undefined = local.getCookie(c, 'client_uid')
|
||||
const client_key: string | undefined = local.getCookie(c, 'client_key')
|
||||
const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
|
||||
const client_uid: string = <string>local.getCookie(c, 'client_uid')
|
||||
const client_key: string = <string>local.getCookie(c, 'client_key')
|
||||
const driver_txt: string = <string>local.getCookie(c, 'apps_types')
|
||||
const client_url: string = driver_map[driver_txt][1];
|
||||
console.log(login_data);
|
||||
// 请求参数 ==========================================================================
|
||||
const params_all = {
|
||||
@ -74,10 +94,6 @@ app.get('/onedrive/callback', async (c) => {
|
||||
+ `&refresh_token=${json.refresh_token}`
|
||||
+ `&client_uid=${client_uid}`
|
||||
+ `&client_key=${client_key}`);
|
||||
// return c.json({
|
||||
// access_token: json.access_token,
|
||||
// refresh_token: json.refresh_token,
|
||||
// });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user