Skip to main content

Public sharing

Imported component documentation. Source: melodee-project/melodee-api at commit 0267c458207082337d9baf1130deeb65f43c9d4a. Version 1.0.1. License MIT. Status: implemented-and-automatically-verified candidate; not published, deployed or production-qualified. This is the component's committed documentation, not proof of a distribution release or production qualification.

An account owner can explicitly share one static or concert playlist, one Release, or one Track. A share never grants access to the Catalog as a whole and never exposes the owner's favorites, ratings, dislikes, listening history, preferences or account identity. The API stays headless: recipient-facing pages belong to a separate application.

Owner operations​

OperationNotes
POST /api/v1/shares{targetKind, targetId, expiresInDays?, maxUses?}; default 30 days, max 365
GET /api/v1/sharesInventory; the token is never listed
DELETE /api/v1/shares/{id}Immediate revocation

The response to creation contains the recipient token exactly once and a relative sharePath (/api/v1/public/shares/{token}). The owner composes the absolute URL from MELODEE_PUBLIC_BASE_URL. PostgreSQL stores only the SHA-256 digest, so a database read cannot reproduce a working link.

Limits: at most 200 active shares per account; maxUses bounds metadata opens (1–100000). Dynamic playlists are refused because their contents depend on private listener state. Playlist shares require ownership; Release/Track shares name a catalog entity explicitly.

A successful metadata open consumes one use and starts (or renews) a bounded playback-authorization window of one hour, capped by the share expiry. Streaming while that window is valid does not consume metadata uses, so a one-use link can play its content. After the window ends, playback requires another metadata open; if the metadata budget is exhausted, no new authorization can be created. Share revocation and expiry end playback immediately.

Recipient operations (public, token-authenticated)​

OperationNotes
GET /api/v1/public/shares/{token}Kind, target title, expiry, playback-window end and a bounded page of entries; cursor is the opaque nextCursor from the previous page
GET /api/v1/public/shares/{token}/tracks/{track_id}/streamRange/ETag/206/416 exactly like authenticated streaming

Each entry carries trackId, title, durationMillis, optional position, discNumber, section, note, playable and a streamPath only when playable. Unavailable or redirected Tracks are resolved to canonical identity, marked playable: false and never fail the whole page. Pages use a stable composite cursor: (position, entry id) for playlists and (discNumber, position, membership id) for Releases. A malformed or wrong-scope cursor is 400 and does not consume a metadata use.

Expired, revoked, use-exhausted and unknown tokens are indistinguishable (404). Tracks outside the shared scope are 404. A merged (redirected) Track resolves to its canonical identity.

Abuse prevention and resource limits​

  • 256-bit random token, digest-only storage, constant lookup;
  • required expiry and optional metadata-open budget, both re-checked per request;
  • a separate one-hour playback window, renewed only by a metadata open and ended by expiry or revocation; ranges do not consume metadata uses;
  • immediate revocation;
  • per-account active-share cap;
  • bounded pages (limit ≤ 100) and no catalog-wide listing;
  • a bounded 30-day access ledger (public_share_access) pruned by the Cleanup job;
  • authentication is not bypassed for owner routes; public routes expose only the shared scope.

There is no per-IP rate limiter inside the API. Deployment must front the public share routes with reverse-proxy rate limits; this is recorded as an operational requirement rather than silently assumed.

Downstream integration​

The unresolved public-share frontend ownership decision is respected: this repository provides no UI. A recipient-facing page must:

  1. read the token from its own route (never log it);
  2. call GET /api/v1/public/shares/{token} and render only the returned entries;
  3. use the returned streamPath verbatim for playback (the browser's media element sends ranges);
  4. handle 404 as "link unavailable" without further detail;
  5. never attempt owner endpoints with the recipient token.

Verification​

tests/api_v1.rs::public_shares_are_explicit_bounded_revocable_and_scope_limited covers digest-only storage, owner inventory without tokens, recipient scoping (no favorite/rating/owner fields), ranged streaming with strong ETag, out-of-scope 404, use-budget exhaustion, Release and Track shares, dynamic-playlist refusal, cross-account revocation denial, immediate revocation, expiry and invalid tokens. public_share_pagination_is_stable_for_duplicates_and_multi_disc covers duplicate occurrences, multi-disc ordering, exact page boundaries and malformed cursors; one_use_share_authorizes_bounded_playback_and_revocation covers concurrent opens, one-use playback, ranges, exhaustion, revocation and window expiry.