This commit is contained in:
2026-07-11 11:52:15 +03:00
parent 07db914ca0
commit a4741b6820
10 changed files with 35 additions and 42 deletions
+51
View File
@@ -0,0 +1,51 @@
import fs from "node:fs";
import { configFilePath, initDataDir } from "./data.ts";
// Re-export for backward compatibility
export { initDataDir };
export interface LoginConfig {
serverUrl: string;
email: string;
username: string;
domain?: string;
}
let inMemoryPassword: string | null = null;
export function setPassword(password: string): void {
inMemoryPassword = password;
}
export function getPassword(): string | null {
return inMemoryPassword;
}
export function hasPassword(): boolean {
return inMemoryPassword !== null;
}
export function clearPassword(): void {
inMemoryPassword = null;
}
export function loadConfig(): LoginConfig {
const filePath = configFilePath();
if (!fs.existsSync(filePath)) {
throw new Error("Not logged in. Use the login tool first.");
}
return JSON.parse(fs.readFileSync(filePath, "utf-8")) as LoginConfig;
}
export function saveConfig(config: LoginConfig): void {
const filePath = configFilePath();
fs.writeFileSync(filePath, JSON.stringify(config, null, 2), "utf-8");
}
export function clearConfig(): void {
const filePath = configFilePath();
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
clearPassword();
}