fix: 延迟加载 weixin 登录二维码依赖

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
1111
2026-04-19 18:38:40 +08:00
parent 6607b13364
commit 3b3e4fb1ea

View File

@@ -1,5 +1,3 @@
import qrcode from 'qrcode-terminal'
export interface QRCodeResult {
qrcodeUrl?: string
qrcodeId: string
@@ -15,6 +13,23 @@ export interface LoginResult {
message: string
}
async function renderQrCodeToTerminal(qrcodeUrl: string): Promise<void> {
const moduleName = 'qrcode-terminal'
const { default: qrcode } = (await import(moduleName)) as {
default: {
generate: (
text: string,
options?: { small?: boolean },
callback?: (output: string) => void,
) => void
}
}
qrcode.generate(qrcodeUrl, { small: true }, output => {
process.stderr.write(`${output}\n`)
})
}
export async function startLogin(apiBaseUrl: string): Promise<QRCodeResult> {
const response = await fetch(`${apiBaseUrl}/ilink/bot/get_bot_qrcode?bot_type=3`)
if (!response.ok) {
@@ -32,9 +47,7 @@ export async function startLogin(apiBaseUrl: string): Promise<QRCodeResult> {
const qrcodeUrl = data.qrcode_img_content || ''
if (qrcodeUrl) {
qrcode.generate(qrcodeUrl, { small: true }, output => {
process.stderr.write(`${output}\n`)
})
await renderQrCodeToTerminal(qrcodeUrl)
}
return {