From 6b778c404846b6b283b3ce1d378ce9655df1a0f4 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 7 Mar 2026 17:11:34 +0000 Subject: [PATCH] refactor(zalouser): reuse shared QR temp file writer --- extensions/zalouser/src/onboarding.ts | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/extensions/zalouser/src/onboarding.ts b/extensions/zalouser/src/onboarding.ts index 728edff704a..195f3dfe1a6 100644 --- a/extensions/zalouser/src/onboarding.ts +++ b/extensions/zalouser/src/onboarding.ts @@ -1,5 +1,3 @@ -import fsp from "node:fs/promises"; -import path from "node:path"; import type { ChannelOnboardingAdapter, ChannelOnboardingDmPolicy, @@ -14,7 +12,6 @@ import { normalizeAccountId, promptAccountId, promptChannelAccessConfig, - resolvePreferredOpenClawTmpDir, } from "openclaw/plugin-sdk/zalouser"; import { listZalouserAccountIds, @@ -22,6 +19,7 @@ import { resolveZalouserAccountSync, checkZcaAuthenticated, } from "./accounts.js"; +import { writeQrDataUrlToTempFile } from "./qr-temp-file.js"; import { logoutZaloProfile, resolveZaloAllowFromEntries, @@ -103,25 +101,6 @@ async function noteZalouserHelp(prompter: WizardPrompter): Promise { ); } -async function writeQrDataUrlToTempFile( - qrDataUrl: string, - profile: string, -): Promise { - const trimmed = qrDataUrl.trim(); - const match = trimmed.match(/^data:image\/png;base64,(.+)$/i); - const base64 = (match?.[1] ?? "").trim(); - if (!base64) { - return null; - } - const safeProfile = profile.replace(/[^a-zA-Z0-9_-]+/g, "-") || "default"; - const filePath = path.join( - resolvePreferredOpenClawTmpDir(), - `openclaw-zalouser-qr-${safeProfile}.png`, - ); - await fsp.writeFile(filePath, Buffer.from(base64, "base64")); - return filePath; -} - async function promptZalouserAllowFrom(params: { cfg: OpenClawConfig; prompter: WizardPrompter;