refactor(pairing): share allowFrom path resolution

This commit is contained in:
Peter Steinberger
2026-03-08 02:06:03 +00:00
parent e7056272bc
commit 01cff3a7a6
2 changed files with 14 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ import { saveSessionStore } from "../config/sessions.js";
import { canonicalizeMainSessionAlias } from "../config/sessions/main-session.js"; import { canonicalizeMainSessionAlias } from "../config/sessions/main-session.js";
import type { SessionScope } from "../config/sessions/types.js"; import type { SessionScope } from "../config/sessions/types.js";
import { createSubsystemLogger } from "../logging/subsystem.js"; import { createSubsystemLogger } from "../logging/subsystem.js";
import { resolveChannelAllowFromPath } from "../pairing/pairing-store.js";
import { import {
buildAgentMainSessionKey, buildAgentMainSessionKey,
DEFAULT_ACCOUNT_ID, DEFAULT_ACCOUNT_ID,
@@ -617,10 +618,11 @@ export async function detectLegacyStateMigrations(params: {
const hasLegacyWhatsAppAuth = const hasLegacyWhatsAppAuth =
fileExists(path.join(oauthDir, "creds.json")) && fileExists(path.join(oauthDir, "creds.json")) &&
!fileExists(path.join(targetWhatsAppAuthDir, "creds.json")); !fileExists(path.join(targetWhatsAppAuthDir, "creds.json"));
const legacyTelegramAllowFromPath = path.join(oauthDir, "telegram-allowFrom.json"); const legacyTelegramAllowFromPath = resolveChannelAllowFromPath("telegram", env);
const targetTelegramAllowFromPath = path.join( const targetTelegramAllowFromPath = resolveChannelAllowFromPath(
oauthDir, "telegram",
`telegram-${DEFAULT_ACCOUNT_ID}-allowFrom.json`, env,
DEFAULT_ACCOUNT_ID,
); );
const hasLegacyTelegramAllowFrom = const hasLegacyTelegramAllowFrom =
fileExists(legacyTelegramAllowFromPath) && !fileExists(targetTelegramAllowFromPath); fileExists(legacyTelegramAllowFromPath) && !fileExists(targetTelegramAllowFromPath);

View File

@@ -104,6 +104,14 @@ function resolveAllowFromPath(
); );
} }
export function resolveChannelAllowFromPath(
channel: PairingChannel,
env: NodeJS.ProcessEnv = process.env,
accountId?: string,
): string {
return resolveAllowFromPath(channel, env, accountId);
}
async function readJsonFile<T>( async function readJsonFile<T>(
filePath: string, filePath: string,
fallback: T, fallback: T,