refactor(src): split oversized modules

This commit is contained in:
Peter Steinberger
2026-01-14 01:08:15 +00:00
parent b2179de839
commit bcbfb357be
675 changed files with 91476 additions and 73453 deletions

View File

@@ -0,0 +1,58 @@
import fs from "node:fs";
import JSON5 from "json5";
export type SessionEntryLike = {
sessionId?: string;
updatedAt?: number;
} & Record<string, unknown>;
export function safeReadDir(dir: string): fs.Dirent[] {
try {
return fs.readdirSync(dir, { withFileTypes: true });
} catch {
return [];
}
}
export function existsDir(dir: string): boolean {
try {
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
} catch {
return false;
}
}
export function ensureDir(dir: string) {
fs.mkdirSync(dir, { recursive: true });
}
export function fileExists(p: string): boolean {
try {
return fs.existsSync(p) && fs.statSync(p).isFile();
} catch {
return false;
}
}
export function isLegacyWhatsAppAuthFile(name: string): boolean {
if (name === "creds.json" || name === "creds.json.bak") return true;
if (!name.endsWith(".json")) return false;
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
}
export function readSessionStoreJson5(storePath: string): {
store: Record<string, SessionEntryLike>;
ok: boolean;
} {
try {
const raw = fs.readFileSync(storePath, "utf-8");
const parsed = JSON5.parse(raw);
if (parsed && typeof parsed === "object") {
return { store: parsed as Record<string, SessionEntryLike>, ok: true };
}
} catch {
// ignore
}
return { store: {}, ok: false };
}