mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 15:22:12 +03:00
28 lines
779 B
TypeScript
28 lines
779 B
TypeScript
import { getDbInstance } from "./core";
|
|
|
|
interface SecretRow {
|
|
value?: unknown;
|
|
}
|
|
|
|
export function getPersistedSecret(key: string): string | null {
|
|
try {
|
|
const db = getDbInstance();
|
|
const row = db
|
|
.prepare<SecretRow>("SELECT value FROM key_value WHERE namespace = 'secrets' AND key = ?")
|
|
.get(key);
|
|
return typeof row?.value === "string" ? JSON.parse(row.value) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function persistSecret(key: string, value: string): void {
|
|
try {
|
|
const db = getDbInstance();
|
|
db.prepare("INSERT OR IGNORE INTO key_value (namespace, key, value) VALUES ('secrets', ?, ?)")
|
|
.run(key, JSON.stringify(value));
|
|
} catch {
|
|
// Non-fatal: secrets still work for the current process if persistence fails.
|
|
}
|
|
}
|