mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 07:03:45 +00:00
fix bunfile bug
This commit is contained in:
@@ -6,7 +6,7 @@ import fs from "fs/promises"
|
||||
export namespace AuthAnthropic {
|
||||
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
|
||||
|
||||
const file = Bun.file(path.join(Global.Path.data, "auth", "anthropic.json"))
|
||||
const filepath = path.join(Global.Path.data, "auth", "anthropic.json")
|
||||
|
||||
export async function authorize() {
|
||||
const pkce = await generatePKCE()
|
||||
@@ -48,15 +48,15 @@ export namespace AuthAnthropic {
|
||||
}),
|
||||
})
|
||||
if (!result.ok) throw new ExchangeFailed()
|
||||
const file = Bun.file(filepath)
|
||||
await Bun.write(file, result)
|
||||
await fs.chmod(file.name!, 0o600)
|
||||
}
|
||||
|
||||
export const exists = file.exists
|
||||
|
||||
export async function access() {
|
||||
if (!(await file.exists())) return
|
||||
const result = await file.json()
|
||||
const file = Bun.file(filepath)
|
||||
const result = await file.json().catch(() => ({}))
|
||||
if (!result) return
|
||||
const refresh = result.refresh_token
|
||||
const response = await fetch(
|
||||
"https://console.anthropic.com/v1/oauth/token",
|
||||
|
||||
@@ -3,9 +3,10 @@ import { Global } from "../global"
|
||||
import fs from "fs/promises"
|
||||
|
||||
export namespace AuthKeys {
|
||||
const file = Bun.file(path.join(Global.Path.data, "auth", "keys.json"))
|
||||
const filepath = path.join(Global.Path.data, "auth", "keys.json")
|
||||
|
||||
export async function get() {
|
||||
const file = Bun.file(filepath)
|
||||
return file
|
||||
.json()
|
||||
.catch(() => ({}))
|
||||
@@ -13,6 +14,7 @@ export namespace AuthKeys {
|
||||
}
|
||||
|
||||
export async function set(key: string, value: string) {
|
||||
const file = Bun.file(filepath)
|
||||
const env = await get()
|
||||
await Bun.write(file, JSON.stringify({ ...env, [key]: value }))
|
||||
await fs.chmod(file.name!, 0o600)
|
||||
|
||||
Reference in New Issue
Block a user