refactor(pairing): share allowFrom path resolution
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user