Skip to content

Read the Blossom server list published to relays - #92

Open
dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:feat/blossom-server-list-from-relays
Open

dadofsambonzuki wants to merge 1 commit into
lnbits:mainfrom
dadofsambonzuki:feat/blossom-server-list-from-relays

Conversation

@dadofsambonzuki

Copy link
Copy Markdown

What happens today

Every upload uses one value: the encrypted app preference saved in Settings → Media & data storage, otherwise the built-in https://blossom.nostr.build. Nothing reads a published server list (grep -rn 10063 src/ is empty), so a user whose other clients already publish their Blossom servers to relays still uploads to whichever server Anagram happens to ship with, and the list they maintain elsewhere is ignored.

The change

  • NostrKind.BlossomServerList (10063, BUD-03 / NIP-B7) in the nostr-tools adapter.
  • src/utils/blossomServerList.ts turns a server tag list into ordered, de-duplicated HTTPS origins, reusing the existing normaliser (drops http:, upload paths, credentials).
  • src/stores/nostr/blossomServerListRuntime.ts reads {kinds:[10063], authors:[me], limit:1} from the account's read relays, shaped like the existing myRelayListRuntime: the list is replaceable, so only the newest snapshot is kept, a later list replaces the cached one while the app runs, and the cache is dropped on logout or account switch.
  • Resolution is now: saved setting → first server of the published list → built-in default. getBlossomServerOrigin() reports which of the three it was, and Settings shows a short caption when the value comes from the published list. Restore default keeps its meaning (stop overriding) and is disabled when there is no override to drop.
  • Read on start and on refresh: started with the rest of the session's subscriptions, restarted by restartSessionSubscriptions (session resume, relay-list change), and live in between. Deliberately not a startup step — it only decides future uploads, so a slow or empty relay response neither delays startup nor fails a step; the saved setting and the default already cover the gap.
  • A new blossomServerListVersion counter means the Settings field follows the list while the screen is open.

Deliberate limits

  • Publishing: the list is read, never written. Saving a server in Settings does not publish a kind 10063, so an Anagram user who has no list elsewhere keeps the current behaviour.
  • NIP-B7's other half — resolving another user's media through their 10063 list when a stored link is dead — is not in this PR.
  • One server, not several: an upload goes to the first server of the list (no try-each-in-turn fallback).

Verified

Unit tests (new): the parser keeps published order and drops duplicates, non-HTTPS and non-origin values; the runtime subscribes with a limit: 1 filter for the logged-in account, keeps the newest list when an older one arrives late, keeps a replacement published in the same second as the list it replaces, notifies listeners only when the list changes, ignores another author or kind, drops the cache when the account changes, and forgets everything on reset; the settings runtime uses the first published server when nothing is saved, lets the saved setting win, and falls through to the default when the list is unusable or missing; startup reads the list and stays successful when that read fails.

e2e/blossom-server-list.spec.ts publishes a real signed kind 10063 to the test relay the way another client would and asserts the whole path in a browser: default → live update without a reload → newest list wins → still read after a restart → a saved setting wins → restore default hands the choice back to the list, with the caption appearing and disappearing as the source changes. On the current code it fails at the first step (uploads keep going to the default). I added it to the browser list in .github/workflows/ci.yml; drop that line if you would rather keep the CI browser set as it is.

Ran locally: npm run quality:all (0 errors), npm run test:unit (140 files, 1107 tests), npm run build, npm run verify:iroh, and npx playwright test e2e/blossom-server-list.spec.ts e2e/settings-parity.spec.ts e2e/parity/session.spec.ts — 13 passed. The pre-existing npx prettier --check complaints in nostrStore.svelte.ts, client.ts, authSessionRuntime.ts and startupContactSyncRuntime.spec.ts are the repo's, not from this change; my own files and hunks are clean.

One new UI string, mediaDataStorage.serverUrlFromPublishedList: tests/unit/translation-catalogs.spec.ts requires every catalog to carry every key, so it is added to all of them, with English only in en-US.json and untranslated English text in the other 19 for translators to replace.

Note for review: open PR #82 rewrites the internals of createBlossomSettingsRuntime. This change adds one dependency and the resolution to that function, so the two should be a small conflict rather than a design clash; #82 also adds a second server preference (for encrypted private media) that I have deliberately not touched.

Uploads now use the first server from the account's kind 10063 list
(BUD-03) when no server is saved in Settings, and fall back to the
built-in default when no list is published. The list is read when the
session's subscriptions start, kept live while the app runs, restarted
on session resume or relay-list change, and cleared on logout.
@dadofsambonzuki

Copy link
Copy Markdown
Author

Following this up with #93, which adds NIP-B7's other half: when a stored media link is dead, the file is looked for on the author's published servers and shown only if the bytes match the hash.

Stacking, since #93 needs the parser this PR introduces:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant