first commit
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled
Sync to CNB / sync (push) Has been cancelled
Delete old workflow runs / del_runs (push) Has been cancelled
Upstream Sync / Sync latest commits from upstream repo (push) Has been cancelled

This commit is contained in:
2026-01-30 16:57:44 +08:00
commit 3d175d75af
119 changed files with 35834 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
import { decrypt, getParams } from '@/utils/decode'
interface QrCodeStatus {
status: 'WaitLogin' | 'LoginSuccess' | 'QRCodeExpired' | 'ScanSuccess' | 'LoginFailed'
authCode?: string
}
interface TokenResponseEncrypt {
data: {
ciphertext: string
iv: string
}
}
interface TokenRequest {
akv: string
apv: string
b: string
d: string
m: string
mac: string
n: string
t: number
wifiMac: string
code?: string
'Content-Type': string
}
export async function GET(
request: Request,
{ params }: { params: Promise<{ sid: string }> }
) {
try {
const { sid } = await params
const statusResponse = await fetch(`https://openapi.alipan.com/oauth/qrcode/${sid}/status`)
if (!statusResponse.ok) {
throw new Error('Failed to check status')
}
const statusData: QrCodeStatus = await statusResponse.json()
if (statusData.status === 'LoginSuccess' && statusData.authCode) {
try {
const t = Math.floor(Date.now() / 1000)
const sendData: TokenRequest = {
...getParams(t),
code: statusData.authCode,
"Content-Type": "application/json"
} as TokenRequest
const headers = Object.fromEntries(
Object.entries(sendData).map(([k, v]) => [k, String(v)])
)
const tokenResponse = await fetch('https://api.extscreen.com/aliyundrive/v3/token', {
method: 'POST',
headers: headers,
body: JSON.stringify(sendData)
})
if (!tokenResponse.ok) {
throw new Error('Failed to get token')
}
const tokenResult: TokenResponseEncrypt = await tokenResponse.json()
const plainData = decrypt(tokenResult.data.ciphertext, tokenResult.data.iv, t)
const tokenInfo = JSON.parse(plainData)
return Response.json({
status: 'LoginSuccess',
refresh_token: tokenInfo.refresh_token,
access_token: tokenInfo.access_token
})
} catch {
return Response.json({ status: 'LoginFailed' })
}
}
return Response.json(statusData)
} catch (error: any) {
return Response.json(
{ error: error.message },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,38 @@
interface ApiResponse<T> {
data: T
}
interface QrCodeData {
qrCodeUrl: string
sid: string
}
export async function POST() {
try {
const response = await fetch('https://api.extscreen.com/aliyundrive/qrcode', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
scopes: ["user:base", "file:all:read", "file:all:write"].join(','),
width: 500,
height: 500,
})
})
if (!response.ok) {
throw new Error('Failed to generate QR code')
}
const result: ApiResponse<QrCodeData> = await response.json()
return Response.json({
qr_link: result.data.qrCodeUrl,
sid: result.data.sid
})
} catch (error: any) {
return Response.json(
{ error: error.message },
{ status: 500 }
)
}
}