-
-
Notifications
You must be signed in to change notification settings - Fork 271
feat: show bluesky avatar in header #896
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -7,6 +7,15 @@ import { SLINGSHOT_HOST } from '#shared/utils/constants' | |
| import { useServerSession } from '#server/utils/server-session' | ||
| import type { PublicUserSession } from '#shared/schemas/publicUserSession' | ||
|
|
||
| interface ProfileRecord { | ||
| avatar?: { | ||
| $type: 'blob' | ||
| ref: { $link: string } | ||
| mimeType: string | ||
| size: number | ||
| } | ||
| } | ||
|
|
||
| export default defineEventHandler(async event => { | ||
| const config = useRuntimeConfig(event) | ||
| if (!config.sessionPassword) { | ||
|
|
@@ -58,8 +67,36 @@ export default defineEventHandler(async event => { | |
| ) | ||
| if (response.ok) { | ||
| const miniDoc: PublicUserSession = await response.json() | ||
|
|
||
| // Fetch the user's profile record to get their avatar blob reference | ||
| let avatar: string | undefined | ||
| const did = agent.did | ||
| try { | ||
| const pdsUrl = new URL(miniDoc.pds) | ||
| // Only fetch from HTTPS PDS endpoints to prevent SSRF | ||
| if (did && pdsUrl.protocol === 'https:') { | ||
| const profileResponse = await fetch( | ||
| `${pdsUrl.origin}/xrpc/com.atproto.repo.getRecord?repo=${encodeURIComponent(did)}&collection=app.bsky.actor.profile&rkey=self`, | ||
| { headers: { 'User-Agent': 'npmx' } }, | ||
| ) | ||
| if (profileResponse.ok) { | ||
| const record = (await profileResponse.json()) as { value: ProfileRecord } | ||
| const avatarBlob = record.value.avatar | ||
| if (avatarBlob?.ref?.$link) { | ||
| // Use Bluesky CDN for faster image loading | ||
| avatar = `https://cdn.bsky.app/img/feed_thumbnail/plain/${did}/${avatarBlob.ref.$link}@jpeg` | ||
| } | ||
| } | ||
| } | ||
| } catch { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catch will happen a good bit for our npmx.social users. They do not get a |
||
| // Avatar fetch failed, continue without it | ||
| } | ||
|
|
||
| await session.update({ | ||
| public: miniDoc, | ||
| public: { | ||
| ...miniDoc, | ||
| avatar, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| import { object, string, pipe, url } from 'valibot' | ||
| import { object, string, pipe, url, optional } from 'valibot' | ||
| import type { InferOutput } from 'valibot' | ||
|
|
||
| export const PublicUserSessionSchema = object({ | ||
| // Safe to pass to the frontend | ||
| did: string(), | ||
| handle: string(), | ||
| pds: pipe(string(), url()), | ||
| avatar: optional(pipe(string(), url())), | ||
| }) | ||
|
|
||
| export type PublicUserSession = InferOutput<typeof PublicUserSessionSchema> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's read the file to understand the full context wc -l server/api/auth/atproto.get.tsRepository: npmx-dev/npmx.dev
Length of output: 95
🏁 Script executed:
# Read the entire file to understand variable declarations and context cat -n server/api/auth/atproto.get.tsRepository: npmx-dev/npmx.dev
Length of output: 3923
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 438
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 172
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 14997
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 8676
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1870
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 324
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 1119
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 914
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 763
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 551
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 761
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 111
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 43
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 947
🌐 Web query:
valibot url validator what does it check validate💡 Result:
Valibot’s
url()only validates that a string is “badly formatted” vs “validly formatted” as a URL (i.e., it’s a URL format check on astring, returning aurlvalidation issue if it isn’t). [1]What it does not check by itself:
javascript:...; you must add your own constraints). [2]startsWith('https://')). [3]Sources:
[1] Valibot
urlaction docs: https://valibot.dev/api/url/[2] Discussion referencing
javascript:concerns with extendingurl: open-circle/valibot#835[3] Valibot
startsWithdocs (HTTPS URL schema example): https://valibot.dev/api/startsWith/🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 143
🏁 Script executed:
Repository: npmx-dev/npmx.dev
Length of output: 617
Validate
miniDoc.pdsand guardagent.didbefore server-side fetches.miniDoc.pdsis cast to type without validation—valibot'surl()only checks format, not SSRF protections. This allows fetches to localhost, private IPs, or restricted hosts. Additionally,agent.did!uses a non-null assertion without checking if it's defined, bypassing type safety.Before fetching from the user's PDS, ensure you:
miniDocagainstPublicUserSessionSchemausingsafeParse()agent.didis defined before using it in URLs🔒 Suggested guard + validation