keys.ts 530 B

1234567891011121314151617181920
  1. import path from "path"
  2. import { Global } from "../global"
  3. import fs from "fs/promises"
  4. export namespace AuthKeys {
  5. const file = Bun.file(path.join(Global.Path.data, "auth", "keys.json"))
  6. export async function get() {
  7. return file
  8. .json()
  9. .catch(() => ({}))
  10. .then((x) => x as Record<string, string>)
  11. }
  12. export async function set(key: string, value: string) {
  13. const env = await get()
  14. await Bun.write(file, JSON.stringify({ ...env, [key]: value }))
  15. await fs.chmod(file.name!, 0o600)
  16. }
  17. }