[Feature Enhancement]: Add a URL-returning overload of `getBlob(from:cid:)`

Aperta
#337 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
swift

Direzione di ricerca

Start by reading the existing getBlob(from:cid:) implementation and the account PDS endpoint resolution discussed in issue #319. Add a synchronous overload that builds a URL using the resolved PDS endpoint and the supplied DID and CID; done means callers can obtain a URL without downloading the blob as Data. The issue names no relevant test file, so locate tests for getBlob and endpoint resolution before making the change.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Summary

getBlob(from:cid:) currently returns Data via an async throws call, which is appropriate for saving or exporting a blob. However, display-oriented APIs such as SwiftUI's AsyncImage and AVPlayer require a URL, not Data. A synchronous URL-building overload with the same name would cover this use case without an additional download.

Pain points

Callers that only need a URL for playback or image loading are forced to either:

  • Download the full blob as Data and convert it to UIImage/NSImage — wasting memory and blocking the async task before display can begin, or
  • Construct the URL manually from the PDS endpoint string, bypassing the typed API.

Concrete cases where a URL is required by the consuming API:

  • SwiftUI AsyncImage(url:) — displays a blob image (thumbnail, avatar stored as blob, etc.) with built-in lazy loading and caching. Accepts URL, not Data.
  • AVPlayer(url:) — streams a video blob for playback. AVPlayer must be initialised with a URL; passing Data is not supported.
Considered Alternatives

Keeping a raw helper that builds the URL from a PDS endpoint string — this works but lives outside the typed API and requires the caller to manage the endpoint separately.

Is this a breaking change?

No

Additional Context

The com.atproto.sync.getBlob lexicon specifies "output": { "encoding": "*/*" } and notes it is implemented by PDS. The URL-returning overload should therefore resolve the account's PDS endpoint rather than hardcoding a relay (see #319).

The new synchronous overload can construct the correct URL from the resolved PDS endpoint and the provided DID/CID query parameters.
Proposed addition:

public func getBlob(from accountDID: String, cid: String) -> URL?

Swift disambiguates the two overloads at the call site: the existing async throws form is chosen when the caller writes try await, and the new synchronous form is chosen when a URL? is expected without await.

Lingua principale
Swift
Stelle
226
Fork
40
Merge medio
5h 8m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MasterJ93/ATProtoKit

Tutte le issue di MasterJ93/ATProtoKit

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.