diff --git a/src/services/weixin/login.ts b/src/services/weixin/login.ts index ab7a4913b..23789c4ce 100644 --- a/src/services/weixin/login.ts +++ b/src/services/weixin/login.ts @@ -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 { + 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 { 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 { const qrcodeUrl = data.qrcode_img_content || '' if (qrcodeUrl) { - qrcode.generate(qrcodeUrl, { small: true }, output => { - process.stderr.write(`${output}\n`) - }) + await renderQrCodeToTerminal(qrcodeUrl) } return {