|
@@ -1,6 +1,7 @@
|
|
|
import path from "path"
|
|
import path from "path"
|
|
|
import { Global } from "../global"
|
|
import { Global } from "../global"
|
|
|
import z from "zod"
|
|
import z from "zod"
|
|
|
|
|
+import { Filesystem } from "../util/filesystem"
|
|
|
|
|
|
|
|
export const OAUTH_DUMMY_KEY = "opencode-oauth-dummy-key"
|
|
export const OAUTH_DUMMY_KEY = "opencode-oauth-dummy-key"
|
|
|
|
|
|
|
@@ -42,8 +43,7 @@ export namespace Auth {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function all(): Promise<Record<string, Info>> {
|
|
export async function all(): Promise<Record<string, Info>> {
|
|
|
- const file = Bun.file(filepath)
|
|
|
|
|
- const data = await file.json().catch(() => ({}) as Record<string, unknown>)
|
|
|
|
|
|
|
+ const data = await Filesystem.readJson<Record<string, unknown>>(filepath).catch(() => ({}))
|
|
|
return Object.entries(data).reduce(
|
|
return Object.entries(data).reduce(
|
|
|
(acc, [key, value]) => {
|
|
(acc, [key, value]) => {
|
|
|
const parsed = Info.safeParse(value)
|
|
const parsed = Info.safeParse(value)
|
|
@@ -56,15 +56,13 @@ export namespace Auth {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function set(key: string, info: Info) {
|
|
export async function set(key: string, info: Info) {
|
|
|
- const file = Bun.file(filepath)
|
|
|
|
|
const data = await all()
|
|
const data = await all()
|
|
|
- await Bun.write(file, JSON.stringify({ ...data, [key]: info }, null, 2), { mode: 0o600 })
|
|
|
|
|
|
|
+ await Filesystem.writeJson(filepath, { ...data, [key]: info }, 0o600)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function remove(key: string) {
|
|
export async function remove(key: string) {
|
|
|
- const file = Bun.file(filepath)
|
|
|
|
|
const data = await all()
|
|
const data = await all()
|
|
|
delete data[key]
|
|
delete data[key]
|
|
|
- await Bun.write(file, JSON.stringify(data, null, 2), { mode: 0o600 })
|
|
|
|
|
|
|
+ await Filesystem.writeJson(filepath, data, 0o600)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|