mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-31 14:22:27 +00:00
core: add automatic project icon discovery from favicon/logo files
This commit is contained in:
@@ -119,7 +119,29 @@ export namespace Project {
|
||||
return existing
|
||||
}
|
||||
|
||||
async function discover(input: Pick<Info, "id" | "worktree">) {}
|
||||
export async function discover(input: Pick<Info, "id" | "worktree">) {
|
||||
const glob = new Bun.Glob("**/{favicon,icon,logo}.{ico,png,svg,jpg,jpeg,webp}")
|
||||
for await (const match of glob.scan({
|
||||
cwd: input.worktree,
|
||||
absolute: true,
|
||||
onlyFiles: true,
|
||||
followSymlinks: false,
|
||||
dot: false,
|
||||
})) {
|
||||
const file = Bun.file(match)
|
||||
const buffer = await file.arrayBuffer()
|
||||
const base64 = Buffer.from(buffer).toString("base64")
|
||||
const mime = file.type || "image/png"
|
||||
const url = `data:${mime};base64,${base64}`
|
||||
await Storage.update<Info>(["project", input.id], (draft) => {
|
||||
draft.icon = {
|
||||
url,
|
||||
color: draft.icon?.color ?? "#000000",
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
async function migrateFromGlobal(newProjectID: string, worktree: string) {
|
||||
const globalProject = await Storage.read<Info>(["project", "global"]).catch(() => undefined)
|
||||
|
||||
Reference in New Issue
Block a user