Repository navigation
feat(desktop): implement favicon discovery and icon management for pr… #1168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
833d3d2
feat(desktop): implement favicon discovery and icon management for pr…
Ipriyankrajai 4761b9d
feat: update dependencies and enhance environment configuration
Ipriyankrajai b759a2f
feat(database): add icon_url and icon_override fields to projects table
Ipriyankrajai e9b5739
chore: bump version of @superset/desktop to 0.0.66 in bun.lock
Ipriyankrajai e4c920f
feat: add command for resolving PR comments in GitHub
Ipriyankrajai 8877efe
feat(project-settings): add error handling for icon update failures
Ipriyankrajai 0f46143
fix(ProjectThumbnail): reset error state on icon change
Ipriyankrajai b5a7580
feat(projects): enhance icon validation for project settings
Ipriyankrajai a8e0d66
fix(ProjectSettings): improve error handling for icon update failures
Ipriyankrajai 11e35ef
Delete .claude/commands/respond-to-pr-comments.md
Ipriyankrajai d6aeafa
cleanup: remove unnecessary code and fix data patterns in favicon PR
saddlepaddle e80fd6f
refactor(IconUploader): use native file picker instead of custom drag…
saddlepaddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/desktop/src/lib/trpc/routers/projects/utils/favicon-discovery.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { readFileSync, statSync } from "node:fs"; | ||
| import fg from "fast-glob"; | ||
|
|
||
| const FAVICON_GLOB = "**/favicon.{ico,png,svg,jpg,jpeg,webp}"; | ||
|
|
||
| const MAX_FILE_SIZE = 500 * 1024; // 500KB | ||
|
|
||
| /** | ||
| * Discovers a favicon in the project directory and returns it as a base64 data URL. | ||
| * Picks the favicon closest to the project root if multiple are found. | ||
| */ | ||
| export async function discoverFavicon( | ||
| repoPath: string, | ||
| ): Promise<string | null> { | ||
| try { | ||
| const matches = await fg(FAVICON_GLOB, { | ||
| cwd: repoPath, | ||
| absolute: true, | ||
| onlyFiles: true, | ||
| dot: false, | ||
| }); | ||
|
|
||
| if (matches.length === 0) return null; | ||
|
|
||
| const shortest = matches.sort((a, b) => a.length - b.length)[0]; | ||
|
|
||
| const stats = statSync(shortest); | ||
| if (stats.size > MAX_FILE_SIZE) { | ||
| console.log( | ||
| `[favicon-discovery] File too large: ${shortest} (${stats.size} bytes)`, | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| const buffer = readFileSync(shortest); | ||
| const base64 = buffer.toString("base64"); | ||
| const ext = shortest.split(".").pop()?.toLowerCase(); | ||
| const mime = getMimeType(ext); | ||
|
|
||
| console.log( | ||
| `[favicon-discovery] Found favicon: ${shortest} (${stats.size} bytes)`, | ||
| ); | ||
|
|
||
| return `data:${mime};base64,${base64}`; | ||
| } catch (error) { | ||
| console.error("[favicon-discovery] Error:", error); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function getMimeType(ext: string | undefined): string { | ||
| const mimes: Record<string, string> = { | ||
| ico: "image/x-icon", | ||
| png: "image/png", | ||
| svg: "image/svg+xml", | ||
| jpg: "image/jpeg", | ||
| jpeg: "image/jpeg", | ||
| webp: "image/webp", | ||
| }; | ||
| return mimes[ext ?? ""] ?? "image/png"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.