refactor: migrate src/project/project.ts from Bun.file() to Filesystem/stat modules (#14126)
This commit is contained in:
@@ -86,8 +86,7 @@ export namespace Project {
|
|||||||
const gitBinary = Bun.which("git")
|
const gitBinary = Bun.which("git")
|
||||||
|
|
||||||
// cached id calculation
|
// cached id calculation
|
||||||
let id = await Bun.file(path.join(dotgit, "opencode"))
|
let id = await Filesystem.readText(path.join(dotgit, "opencode"))
|
||||||
.text()
|
|
||||||
.then((x) => x.trim())
|
.then((x) => x.trim())
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
|
|
||||||
@@ -125,9 +124,7 @@ export namespace Project {
|
|||||||
|
|
||||||
id = roots[0]
|
id = roots[0]
|
||||||
if (id) {
|
if (id) {
|
||||||
void Bun.file(path.join(dotgit, "opencode"))
|
void Filesystem.write(path.join(dotgit, "opencode"), id).catch(() => undefined)
|
||||||
.write(id)
|
|
||||||
.catch(() => undefined)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,10 +274,9 @@ export namespace Project {
|
|||||||
)
|
)
|
||||||
const shortest = matches.sort((a, b) => a.length - b.length)[0]
|
const shortest = matches.sort((a, b) => a.length - b.length)[0]
|
||||||
if (!shortest) return
|
if (!shortest) return
|
||||||
const file = Bun.file(shortest)
|
const buffer = await Filesystem.readBytes(shortest)
|
||||||
const buffer = await file.arrayBuffer()
|
const base64 = buffer.toString("base64")
|
||||||
const base64 = Buffer.from(buffer).toString("base64")
|
const mime = Filesystem.mimeType(shortest) || "image/png"
|
||||||
const mime = file.type || "image/png"
|
|
||||||
const url = `data:${mime};base64,${base64}`
|
const url = `data:${mime};base64,${base64}`
|
||||||
await update({
|
await update({
|
||||||
projectID: input.id,
|
projectID: input.id,
|
||||||
@@ -381,10 +377,8 @@ export namespace Project {
|
|||||||
const data = fromRow(row)
|
const data = fromRow(row)
|
||||||
const valid: string[] = []
|
const valid: string[] = []
|
||||||
for (const dir of data.sandboxes) {
|
for (const dir of data.sandboxes) {
|
||||||
const stat = await Bun.file(dir)
|
const s = Filesystem.stat(dir)
|
||||||
.stat()
|
if (s?.isDirectory()) valid.push(dir)
|
||||||
.catch(() => undefined)
|
|
||||||
if (stat?.isDirectory()) valid.push(dir)
|
|
||||||
}
|
}
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user