refactor: drop skill file, rework client
This commit was merged in pull request #3.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user