-
Notifications
You must be signed in to change notification settings - Fork 219
Add 115 QR Code #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BrandonStudio
wants to merge
2
commits into
OpenListTeam:main
Choose a base branch
from
BrandonStudio:dev/115qr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add 115 QR Code #76
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
|
||
| // 生成二维码 - 使用带指纹的请求 | ||
BrandonStudio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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; | ||
BrandonStudio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
BrandonStudio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // 关闭模态框 | ||
| 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; | ||
| } | ||
|
Comment on lines
+44
to
+59
|
||
|
|
||
| // 重置界面 | ||
| document.getElementById('qr-code-container').style.display = 'none'; | ||
| document.getElementById('qr-status').style.display = 'none'; | ||
| document.getElementById('refresh-qr-btn').style.display = 'none'; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.