init project
This commit is contained in:
parent
beac96f320
commit
a254e273e5
136
.gitignore
vendored
136
.gitignore
vendored
@ -1,136 +0,0 @@
|
|||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
|
||||||
.cache
|
|
||||||
|
|
||||||
# vitepress build output
|
|
||||||
**/.vitepress/dist
|
|
||||||
|
|
||||||
# vitepress cache directory
|
|
||||||
**/.vitepress/cache
|
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
|
||||||
.docusaurus
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/CFWorker-api.iml" filepath="$PROJECT_DIR$/.idea/CFWorker-api.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
22
README.md
22
README.md
@ -1 +1,21 @@
|
|||||||
# API
|
```txt
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
npm run deploy
|
||||||
|
```
|
||||||
|
|
||||||
|
[For generating/synchronizing types based on your Worker configuration run](https://developers.cloudflare.com/workers/wrangler/commands/#types):
|
||||||
|
|
||||||
|
```txt
|
||||||
|
npm run cf-typegen
|
||||||
|
```
|
||||||
|
|
||||||
|
Pass the `CloudflareBindings` as generics when instantiation `Hono`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// src/index.ts
|
||||||
|
const app = new Hono<{ Bindings: CloudflareBindings }>()
|
||||||
|
```
|
||||||
|
1548
package-lock.json
generated
Normal file
1548
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "cf-worker-api",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "wrangler dev",
|
||||||
|
"deploy": "wrangler deploy --minify",
|
||||||
|
"cf-typegen": "wrangler types --env-interface CloudflareBindings"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@cloudflare/workers-types": "^4.20250610.0",
|
||||||
|
"hono": "^4.7.11"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"wrangler": "^4.4.0"
|
||||||
|
}
|
||||||
|
}
|
115
public/index.html
Normal file
115
public/index.html
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>AList Token获取工具</title>
|
||||||
|
<link href="static/style-all.css" rel="stylesheet">
|
||||||
|
<link href="static/bootstrap.css" rel="stylesheet">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="form-container" style="max-width: 1600px;">
|
||||||
|
<h1>AList Token获取工具</h1>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="site-select">OneDrive 站点</label>
|
||||||
|
<select id="site-select">
|
||||||
|
<option value="official" selected>OneDrive 官方站点</option>
|
||||||
|
<!-- <option value="cn">OneDrive 世纪互联</option>-->
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="client-id">客户端ID</label>
|
||||||
|
<input type="text" id="client-id" name="client-id">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="app-secret">应用机密</label>
|
||||||
|
<input type="text" id="app-secret" name="app-secret">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="callback-url">回调地址</label>
|
||||||
|
<input type="text" id="callback-url" name="callback-url" value="https://baidu.com/onedrive/callback"
|
||||||
|
readonly>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<button class="btn btn-success" onclick="getLogin()">获取Token</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="refresh-token">访问秘钥(Access Token)</label>
|
||||||
|
<input type="text" id="access-token" name="access-token" readonly disabled="disabled">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<label for="refresh-token">刷新秘钥(Refresh Token)</label>
|
||||||
|
<input type="text" id="refresh-token" name="refresh-token" readonly disabled="disabled">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
let intervalId;
|
||||||
|
|
||||||
|
// 获取登录秘钥 ==============================================================================
|
||||||
|
async function getLogin() {
|
||||||
|
let apps_uuid = document.getElementById("client-id").value;
|
||||||
|
let apps_keys = document.getElementById("app-secret").value;
|
||||||
|
let post_urls = "/onedrive/requests?client_uid=" + apps_uuid + "&client_key=" + apps_keys;
|
||||||
|
try {
|
||||||
|
const response = await fetch(post_urls, {
|
||||||
|
method: 'GET', headers: {'Content-Type': 'application/json'}
|
||||||
|
});
|
||||||
|
// 解析响应内容 ===============================================
|
||||||
|
const response_data = await response.json();
|
||||||
|
if (response.status === 200) {
|
||||||
|
window.open(response_data.text)
|
||||||
|
intervalId = setInterval(getToken, 3000);
|
||||||
|
} else Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: "获取秘钥失败: " + response_data.text,
|
||||||
|
showConfirmButton: true,
|
||||||
|
timer: 1000
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: '获取秘钥失败: ' + error,
|
||||||
|
showConfirmButton: true,
|
||||||
|
timer: 1000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getToken() {
|
||||||
|
let apps_uuid = document.getElementById("client-id").value;
|
||||||
|
let post_urls = "/onedrive/gettoken?client_uid=" + apps_uuid;
|
||||||
|
try {
|
||||||
|
const response = await fetch(post_urls, {method: 'GET'});
|
||||||
|
// 解析响应内容 ===============================================
|
||||||
|
const response_data = await response.json();
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(response_data);
|
||||||
|
clearInterval(intervalId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: '获取秘钥失败: ' + error,
|
||||||
|
showConfirmButton: true,
|
||||||
|
timer: 1000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
7
public/static/bootstrap.css
vendored
Normal file
7
public/static/bootstrap.css
vendored
Normal file
File diff suppressed because one or more lines are too long
7
public/static/bootstrap.js
vendored
Normal file
7
public/static/bootstrap.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
public/static/cdn-image.jpg
Normal file
BIN
public/static/cdn-image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 97 KiB |
BIN
public/static/maple-min.ttf
Normal file
BIN
public/static/maple-min.ttf
Normal file
Binary file not shown.
58
public/static/style-all.css
Normal file
58
public/static/style-all.css
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/* 手动设置字体链接 */
|
||||||
|
@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 {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 10px; /* 修改圆角为10px */
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
85
src/index.ts
Normal file
85
src/index.ts
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import {Context, Hono} from 'hono'
|
||||||
|
import {KVNamespace} from '@cloudflare/workers-types';
|
||||||
|
import {serveStatic} from 'hono/cloudflare-workers' // @ts-ignore
|
||||||
|
import manifest from '__STATIC_CONTENT_MANIFEST'
|
||||||
|
|
||||||
|
export type Bindings = {
|
||||||
|
MAIN_URLS: string, DATABASE: KVNamespace,
|
||||||
|
}
|
||||||
|
const app = new Hono<{ Bindings: Bindings }>()
|
||||||
|
app.use("*", serveStatic({manifest: manifest, root: "./"}));
|
||||||
|
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 scopes_all = 'offline_access Files.ReadWrite.All';
|
||||||
|
const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
|
||||||
|
|
||||||
|
const params_all: Record<string, any> = {
|
||||||
|
client_id: client_uid,
|
||||||
|
scope: scopes_all,
|
||||||
|
response_type: 'code',
|
||||||
|
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback'
|
||||||
|
};
|
||||||
|
const urlWithParams = new URL(client_url);
|
||||||
|
Object.keys(params_all).forEach(key => {
|
||||||
|
urlWithParams.searchParams.append(key, params_all[key]);
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const response = await fetch(urlWithParams.href, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
console.log(response);
|
||||||
|
await c.env.DATABASE.put(client_uid, JSON.stringify({
|
||||||
|
"keys": client_key,
|
||||||
|
"data": "",
|
||||||
|
}))
|
||||||
|
return c.json({text: response.url}, 200);
|
||||||
|
} catch (error) {
|
||||||
|
return c.json({text: error}, 500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/onedrive/callback/', async (c) => {
|
||||||
|
const login_data = <string>c.req.query('code');
|
||||||
|
const client_uid = <string>c.req.query('uuid');
|
||||||
|
const client_key = <string>c.req.query('keys');
|
||||||
|
console.log(login_data);
|
||||||
|
let data: string = <string>await c.env.DATABASE.get(client_uid)
|
||||||
|
// getToken(c,)
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/onedrive/gettoken/', (c) => {
|
||||||
|
const client_uid = <string>c.req.query('uuid');
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
async function getToken(c: Context, client_uid: string, client_key: string, login_data: string) {
|
||||||
|
const client_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
|
||||||
|
const params_all = {
|
||||||
|
client_id: client_uid,
|
||||||
|
client_secret: client_key,
|
||||||
|
redirect_uri: 'https://' + c.env.MAIN_URLS + '/onedrive/callback',
|
||||||
|
code: login_data,
|
||||||
|
grant_type: 'authorization_code'
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(client_url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: params_all,
|
||||||
|
});
|
||||||
|
const json = JSON.parse(response.body);
|
||||||
|
if (json.token_type === 'Bearer') {
|
||||||
|
return c.json({
|
||||||
|
access_token: json.access_token,
|
||||||
|
refresh_token: json.refresh_token ? json.refresh_token : 'Error',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return c.json({error: 'Invalid token type'});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return c.json({error: error});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default app
|
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"lib": [
|
||||||
|
"ESNext",
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"@cloudflare/workers-types/2023-07-01"
|
||||||
|
],
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "hono/jsx"
|
||||||
|
},
|
||||||
|
}
|
21
wrangler.jsonc.example
Normal file
21
wrangler.jsonc.example
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"$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": "example.com"
|
||||||
|
},
|
||||||
|
"site": {
|
||||||
|
"bucket": "./public"
|
||||||
|
},
|
||||||
|
"kv_namespaces": [
|
||||||
|
{
|
||||||
|
"binding": "DATABASE",
|
||||||
|
"id": "*******************************"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user