refactor(zalouser): reuse shared QR temp file writer

This commit is contained in:
Peter Steinberger
2026-03-07 17:11:34 +00:00
parent c5bb6db85b
commit 6b778c4048

View File

@@ -1,5 +1,3 @@
import fsp from "node:fs/promises";
import path from "node:path";
import type { import type {
ChannelOnboardingAdapter, ChannelOnboardingAdapter,
ChannelOnboardingDmPolicy, ChannelOnboardingDmPolicy,
@@ -14,7 +12,6 @@ import {
normalizeAccountId, normalizeAccountId,
promptAccountId, promptAccountId,
promptChannelAccessConfig, promptChannelAccessConfig,
resolvePreferredOpenClawTmpDir,
} from "openclaw/plugin-sdk/zalouser"; } from "openclaw/plugin-sdk/zalouser";
import { import {
listZalouserAccountIds, listZalouserAccountIds,
@@ -22,6 +19,7 @@ import {
resolveZalouserAccountSync, resolveZalouserAccountSync,
checkZcaAuthenticated, checkZcaAuthenticated,
} from "./accounts.js"; } from "./accounts.js";
import { writeQrDataUrlToTempFile } from "./qr-temp-file.js";
import { import {
logoutZaloProfile, logoutZaloProfile,
resolveZaloAllowFromEntries, resolveZaloAllowFromEntries,
@@ -103,25 +101,6 @@ async function noteZalouserHelp(prompter: WizardPrompter): Promise<void> {
); );
} }
async function writeQrDataUrlToTempFile(
qrDataUrl: string,
profile: string,
): Promise<string | null> {
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: { async function promptZalouserAllowFrom(params: {
cfg: OpenClawConfig; cfg: OpenClawConfig;
prompter: WizardPrompter; prompter: WizardPrompter;