Space Station Worker
The hub of Space Station: a Cloudflare Worker and D1 catalog in front of a music library mirrored to Google Drive, streaming the audio through the Worker.

What it does
- Holds the catalog (artists, albums, genres, tracks and the links between them) in D1 and serves it as one compact download, with a cheap version fingerprint so clients know when to refresh.
- Streams audio from Drive with range requests, and serves album art from Drive through an R2 cache.
- Radio and AutoDJ endpoints with an artist-repeat cooldown. AutoDJ drifts between neighbouring genres with a weighted random walk over a hand-curated adjacency graph.
- Likes, a global play history and a wishlist of tracks liked on radio that are not in the library, all shared across clients.
- Keeps D1 in step with Drive on a 15-minute cron using Drive's changes feed. A quiet run is one API call.
- A live radio station list (Death.FM and SomaFM channels) with a shared per-stream scrobble switch.
- A browser player served as static assets: artists, genres, stations and likes, fuzzy search, a crossfading queue, keyboard shortcuts, lock-screen media controls and history-aware navigation with no build step.
- Several separate libraries, each rooted at its own Drive folder with its own artists, albums, tracks, likes and history. Each has its own catalog version, so syncing one does not make the other's clients download again, and the web player shows a library switch when there is more than one.
- Sharing between libraries from the web player: an album or artist can be shared to another library as linked tracks, so a file both listeners have is stored once. Moving a file between libraries in Drive moves its tracks with it.
- A "Sync now" that repeats until nothing is waiting, with a Stop button.
Under the hood
- JavaScript on Workers with D1 for the catalog, R2 for art, and the Drive API through
googleapis. A seed script reads tags from the local files withmusic-metadataand matches them to Drive file ids. - Sync reads only part of each new file: the ID3v2 head and any trailing APEv2 or ID3v1 tag, a few small range requests per track. A queue and a bounded batch per run keep each invocation small, and a file that fails five times is dropped.
- Authentication lives in the Worker. Machine clients send a fixed header pair, and a browser goes through a Google login that is checked against a single allowed account and kept as a signed session cookie.
- A Chromecast cannot log in or add headers to a media request, so the receiver uses separate routes gated by a shared secret. The receiver is a real API client: it extends its own queue, signs its own Last.fm calls and records its own history.
- Split releases such as "A; B" are listed under each artist, and the fuzzy search is implemented twice (web and Android) with the same test cases.
- The Worker also tells clients where the home LAN server is, so they can prefer it. Tests run on Node's runner against real migrations on SQLite, with a scripted fake Drive, plus a headless-Chrome smoke test of the web player.
- On the Cast receiver, pause is treated as stop for live radio, since a live stream cannot resume where it was, and Death.FM plays are scrobbled on the time actually listened.
The Drive layout, hostnames and credentials are not described here.