Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
504 changes: 455 additions & 49 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cf-worker-api",
"scripts": {
"dev-js": "tsx watch src/basic.ts",
"dev-js": "tsx watch --include \"public/**\" src/basic.ts",
"build-js": "webpack --mode production",
"deploy-js": "node dist/bundle.js",
"dev-cf": "wrangler dev",
Expand Down
8 changes: 7 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
<option value="baiduyun_ob">百度网盘 (OAuth2) 手动登录</option>
<option value="quarkyun_fn">夸克网盘 (OAuth2) 验证登录</option>
<option value="115cloud_go">115 网盘 (OAuth2) 跳转登录</option>
<option value="115cloud_qr">115 网盘 扫码</option>
<option value="123cloud_go">123 网盘 (OAuth2) 跳转登录</option>
<option value="dropboxs_go">Drop Box (OAuth2) 跳转登录</option>
<option value="googleui_go">GoogleDrive Login (OAuth2)</option>
Expand Down Expand Up @@ -133,12 +134,15 @@ <h2 class="text-center mb-4">🔐 OpenList Token 获取工具</h2>
<div id="qr-modal" class="qr-modal">
<div class="qr-modal-content">
<span class="close-btn" onclick="closeQRModal()">&times;</span>
<h4>阿里云盘扫码登录v2</h4>
<h4 id="qr-modal-title"></h4>
<div id="qr-code-container" class="qr-code-container" style="display: none;">
<div id="qr-code-display"></div>
</div>
<div id="qr-status" class="qr-status" style="display: none;"></div>
<div class="mt-3">
<button id="qr-status-btn" class="btn btn-secondary" onclick="checkQRStatus()">
刷新状态
</button>
<button id="refresh-qr-btn" class="btn btn-secondary" onclick="refreshQRCode()" style="display: none;">
刷新二维码
</button>
Expand Down Expand Up @@ -171,7 +175,9 @@ <h4>隐私政策和使用条款</h4>
<script src="/static/login.js"></script>
<script src="/static/token.js"></script>
<script src="/static/theme.js"></script>
<script src="/static/qr.js"></script>
<script src="/static/aliv2.js"></script>
<script src="/static/115qr.js"></script>
<script src="/static/eulas.js"></script>
<script src="/static/spoid.js"></script>
<script src="/static/input.js"></script>
Expand Down
85 changes: 85 additions & 0 deletions public/static/115qr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* @typedef {import('../../src/driver/115cloud_qr.ts').QRCodeResponse} QRCodeResponse
*/

async function start115CloudQRLogin() {
try {
// 显示模态框
document.getElementById('qr-modal').style.display = 'block';
setQRStatus('正在生成二维码...', 'waiting');

/** @type {string | null} */
let uid = null;

// 生成二维码 - 使用带指纹的请求
const response = await fetch(`/115cloud_qr/get_qr`);
if (response.ok) {
/** @type {QRCodeResponse} */
const result = await response.json();
uid = result.uid
showQRCode(result.qrcode);

setQRStatus('请使用115 App扫描二维码', 'waiting');

checkQRStatus = () => check115CloudQRStatus(result);

// qr115CheckInterval = setInterval(() => check115CloudQRStatus(result), 2000);
} else {
setQRStatus(response.statusText || '生成二维码失败', 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
}
} catch (error) {
setQRStatus('网络错误,请重试', 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
console.error('生成二维码失败:', error);
}
}

/**
* @param {QRCodeResponse} body
*/
async function check115CloudQRStatus(body) {
try {
const response = await fetch('/115cloud_qr/check_status', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body),
});
/** @type {HTMLButtonElement} */
const refreshBtn = document.getElementById('refresh-qr-btn');
if (response.ok) {
const status = await response.text();
switch (status) {
case '0':
setQRStatus('等待扫描二维码', 'waiting');
break;
case '1':
setQRStatus('二维码已扫描,请在手机上确认登录', 'waiting');
break;
case '2':
setQRStatus('登录成功', 'success');
// clearInterval(qr115CheckInterval);
document.getElementById("access-token").value = body.uid;
closeQRModal();
break;
case '-1':
setQRStatus('二维码已过期,请刷新重试', 'error');
refreshBtn.style.display = 'inline-block';
break;
case '-2':
setQRStatus('登录已取消,请重试', 'error');
refreshBtn.style.display = 'inline-block';
break;
default:
setQRStatus(`未知状态: ${status}`, 'info');
}
} else {
setQRStatus('检查登录状态失败', 'error');
}
} catch (error) {
setQRStatus('网络错误,请重试', 'error');
console.error('检查登录状态失败:', error);
}
}
64 changes: 9 additions & 55 deletions public/static/aliv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async function startAlicloud2Login() {
// console.log(`会话将在 ${expireMinutes} 分钟后过期`);
}

startStatusCheck();
checkQRStatus = checkAlicloud2Status;
startAliQRStatusCheck();
} else {
setQRStatus(result.error || '生成二维码失败', 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
Expand All @@ -80,29 +81,14 @@ async function startAlicloud2Login() {
}
}

// 显示二维码
function showQRCode(qrUrl) {
const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrUrl)}`;
document.getElementById('qr-code-display').innerHTML = `<img src="${qrApiUrl}" alt="二维码" class="qr-code-img">`;
document.getElementById('qr-code-container').style.display = 'block';
}

// 设置状态
function setQRStatus(message, type) {
const statusEl = document.getElementById('qr-status');
statusEl.textContent = message;
statusEl.className = `qr-status ${type}`;
statusEl.style.display = 'block';
}

// 开始状态检查
function startStatusCheck() {
stopStatusCheck();
function startAliQRStatusCheck() {
stopAliQRStatusCheck();
alicloud2CheckInterval = setInterval(checkAlicloud2Status, 2000);
}

// 停止状态检查
function stopStatusCheck() {
function stopAliQRStatusCheck() {
if (alicloud2CheckInterval) {
clearInterval(alicloud2CheckInterval);
alicloud2CheckInterval = null;
Expand All @@ -118,7 +104,7 @@ async function checkAlicloud2Status() {
if (elapsed > 180000) { // 3分钟
setQRStatus('二维码可能已过期,建议点击刷新重新生成', 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
stopStatusCheck();
stopAliQRStatusCheck();
return;
}

Expand All @@ -138,15 +124,15 @@ async function checkAlicloud2Status() {
break;
case 'CONFIRMED':
setQRStatus('登录成功!正在获取用户信息...', 'success');
stopStatusCheck();
stopAliQRStatusCheck();
// 稍等一下确保token已保存
setTimeout(async () => {
await getAlicloud2UserInfo();
}, 1000);
break;
case 'EXPIRED':
setQRStatus('二维码已过期,请点击刷新重新生成', 'error');
stopStatusCheck();
stopAliQRStatusCheck();
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
break;
}
Expand All @@ -155,7 +141,7 @@ async function checkAlicloud2Status() {
if (response.status === 403) {
setQRStatus('会话验证失败,请重新生成二维码', 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
stopStatusCheck();
stopAliQRStatusCheck();
} else {
setQRStatus('检查状态失败: ' + (result.error || '未知错误'), 'error');
document.getElementById('refresh-qr-btn').style.display = 'inline-block';
Expand Down Expand Up @@ -215,35 +201,3 @@ async function getAlicloud2UserInfo() {
}
}

// 刷新二维码
async function refreshQRCode() {
document.getElementById('refresh-qr-btn').style.display = 'none';
// 清理旧会话
if (alicloud2SessionId) {
try {
await fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`);
} catch (e) {
// console.log('清理旧会话失败:', e);
}
alicloud2SessionId = null;
}
await startAlicloud2Login();
}

// 关闭模态框
function closeQRModal() {
document.getElementById('qr-modal').style.display = 'none';
stopStatusCheck();

// 清理会话
if (alicloud2SessionId) {
fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`);
alicloud2SessionId = null;
}

// 重置界面
document.getElementById('qr-code-container').style.display = 'none';
document.getElementById('qr-status').style.display = 'none';
document.getElementById('refresh-qr-btn').style.display = 'none';
}

2 changes: 1 addition & 1 deletion public/static/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function onSelect() {
// 阿里云盘扫码登录v2不需要客户端ID、应用机密和回调地址 ================
if (driver_txt_input.value === "alicloud_cs"
|| driver_txt_input.value === "alicloud_tv"
|| driver_txt_input.value === "115cloud_qr"
) {
// 隐藏整个字段容器
clientIdContainer.style.display = 'none';
appSecretContainer.style.display = 'none';
serverUseContainer.style.display = 'none';
callbackContainer.style.display = 'none';
server_use_input.checked = true;
} else {
clientIdContainer.style.display = 'block';
appSecretContainer.style.display = 'block';
Expand Down
23 changes: 17 additions & 6 deletions public/static/login.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
// import Swal from 'sweetalert2';

/** @type {string | undefined} */
var driver_txt;

// 获取登录秘钥 #######################################################
async function getLogin(refresh = false) {
let server_use = document.getElementById("server-use-input").checked;
let secret_key = document.getElementById("secret-key-input").value;
let client_uid = document.getElementById("client-uid-input").value;
let client_key = document.getElementById("client-key-input").value;
let driver_txt = document.getElementById("driver-txt-input").value;
driver_txt = document.getElementById("driver-txt-input").value;
let refresh_ui = document.getElementById("refresh-token").value;
/** @type {HTMLHeadingElement} */
const qrModalTitle = document.getElementById('qr-modal-title');
let driver_pre = driver_txt.split("_")[0]
let check_flag = true;
// 阿里云盘扫码v2直接调用专用API,不需要构建传统的requests路径
if (driver_txt === "alicloud_cs" && !refresh) {
qrModalTitle.textContent = '阿里云盘扫码登录v2';
await startAlicloud2Login();
return;
} else if (driver_txt === "115cloud_qr") {
// Ignore refresh
qrModalTitle.textContent = '115网盘扫码登录';
await start115CloudQRLogin();
return;
}
// 验证秘钥情况 ==================================================
if (!server_use) {
if (driver_txt !== "alicloud_cs"
Expand All @@ -26,11 +42,6 @@ async function getLogin(refresh = false) {
return;
}
}
// 阿里云盘扫码v2直接调用专用API,不需要构建传统的requests路径
if (driver_txt === "alicloud_cs" && !refresh) {
await startAlicloud2Login();
return;
}
// 刷新秘钥情况 =================================================
let base_urls = "/requests?client_uid="
if (refresh) {
Expand Down
67 changes: 67 additions & 0 deletions public/static/qr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 显示二维码
function showQRCode(qrUrl) {
const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrUrl)}`;
document.getElementById('qr-code-display').innerHTML = `<img src="${qrApiUrl}" alt="二维码" class="qr-code-img">`;
document.getElementById('qr-code-container').style.display = 'block';
}

// 设置状态
function setQRStatus(message, type) {
const statusEl = document.getElementById('qr-status');
statusEl.textContent = message;
statusEl.className = `qr-status ${type}`;
statusEl.style.display = 'block';
}

/** @type {() => Promise<void> | null} */
var checkQRStatus = null;

/**
* @summary 刷新二维码
* @param {string} driver_txt 驱动类型
*/
async function refreshQRCode(driver_txt) {
document.getElementById('refresh-qr-btn').style.display = 'none';
// 清理旧会话
switch (driver_txt) {
case 'alicloud_cs':
if (alicloud2SessionId) {
try {
await fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`);
} catch (e) {
// console.log('清理旧会话失败:', e);
}
alicloud2SessionId = null;
}
await startAlicloud2Login();
break;
case '115cloud_qr':
await start115CloudQRLogin();
break;
}
}

// 关闭模态框
function closeQRModal() {
document.getElementById('qr-modal').style.display = 'none';
switch (driver_txt) {
case 'alicloud_cs':
stopAliQRStatusCheck();

// 清理会话
if (alicloud2SessionId) {
fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`);
alicloud2SessionId = null;
}
break;
case '115cloud_qr':

break;
}

// 重置界面
document.getElementById('qr-code-container').style.display = 'none';
document.getElementById('qr-status').style.display = 'none';
document.getElementById('refresh-qr-btn').style.display = 'none';
}

Loading