refactor(web): share creds json reader
This commit is contained in:
@@ -33,7 +33,7 @@ export function hasWebCredsSync(authDir: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function readCredsJsonRaw(filePath: string): string | null {
|
||||
export function readCredsJsonRaw(filePath: string): string | null {
|
||||
try {
|
||||
if (!fsSync.existsSync(filePath)) {
|
||||
return null;
|
||||
|
||||
@@ -15,6 +15,7 @@ import { ensureDir, resolveUserPath } from "../utils.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import {
|
||||
maybeRestoreCredsFromBackup,
|
||||
readCredsJsonRaw,
|
||||
resolveDefaultWebAuthDir,
|
||||
resolveWebCredsBackupPath,
|
||||
resolveWebCredsPath,
|
||||
@@ -43,21 +44,6 @@ function enqueueSaveCreds(
|
||||
});
|
||||
}
|
||||
|
||||
function readCredsJsonRaw(filePath: string): string | null {
|
||||
try {
|
||||
if (!fsSync.existsSync(filePath)) {
|
||||
return null;
|
||||
}
|
||||
const stats = fsSync.statSync(filePath);
|
||||
if (!stats.isFile() || stats.size <= 1) {
|
||||
return null;
|
||||
}
|
||||
return fsSync.readFileSync(filePath, "utf-8");
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function safeSaveCreds(
|
||||
authDir: string,
|
||||
saveCreds: () => Promise<void> | void,
|
||||
|
||||
Reference in New Issue
Block a user