← Public packages
@noah/mega-radio
MEGA Radio (the WAKE album) for members of the MEGA.dev Discord: sign in with Kody, verify with Discord, listen with repeat.
Files
AGENTS.md: @noah/mega-radio
- Source is public (open source); audio is not. Gating is enforced in the hosted app (
src/app.ts). A copy of the source cannot serve the audio, because the MP3s live only in this package's storage. Never commit audio to git. - Standalone: no dependencies on other packages, no credential needs, no scheduled jobs, no email.
- Track list:
src/tracks.tsradio(titles, lengths, open dates; also thenpm run upload-radiolist). A track plays when its MP3 is fully stored and its New York open date has passed; otherwise it shows as?????. New tracks are added by hand: editsrc/tracks.ts, publish, runnpm run upload-radio. ./audio-store{ action: 'forget-legacy' }(owner only) deletes storage keys an older version used.- Do not import
kody:*inpage.ts,player.ts,styles.ts,tracks.ts,discord.tsoraudio-core.ts(keeps them unit-testable).node --experimental-strip-types --test test/*.test.tsneeds Node 22 or later. - Gate flow:
currentVisitor()(metaGetCurrentUser, onlyuser_id/usernameare trusted) →getMembership(user_id)→isActive(member andcheckedAt< 30 days). Every/files/radio/*request runs this check. - Discord app: "Mega.dev", client ID
1565030809998458920(DISCORD_CLIENT_IDinsrc/config.ts). - Discord check:
/discord/startstorespkce:<state>→{verifier, userId}and sets the__Secure-<cookiePrefix>dstatecookie. It then redirects withprompt=noneand retries withprompt=consentonconsent_required./discord/callbackchecks the state cookie, the stored userId and theissvalue, exchanges the code (public client, no secret), callscheckMembership, and revokes the token. - No Kody credential needs on purpose: declaring an executor need (even
required: false) made the platform redirect every route to aneed:discordconsent screen. Membership is proven only through the app's own Discord OAuth. checkMembershipuses/users/@me/guilds/{GUILD_ID}/member(guilds.members.read). If that returns 401/403, it falls back to paging/users/@me/guilds(guilds).- Smoke test after publish:
packageAppFetchGET/status(signed out →signedIn:false) and/files/radio/01.mp3(signed out → 401). Run as Noah after a check → 200 / 206 with Range. - Upload:
npm run upload-radio(Noah's machine). It callskody:@noah/mega-radio/audio-store, which is owner-only viaOWNER_KODY_ID. - Lock-screen artwork:
/art/NN.png?exp&sig(src/art.ts) is the only cookie-free file route. The HMAC key is random and kept in package storage (art:key); links last 12 hours and are only minted on the member page. Playback uses one<audio id="radio-audio" playsinline>(src/player.ts); don't go back to one element per track (the lock screen loses its metadata and next-track advance). - Listen stats (src/plays.ts, src/stats.ts): SQLite
play_total (n, plays)andplay_user (user_id, n, plays, last_ms);last_msexists only for the rate limit (90% of the track length, at least 30 s).POST /plays/NNruns the same membership gate as the audio and needscontent-type: application/json. - Origin move (until December 17, 2026): the app is served at https://noah.kody.run/mega-radio/ (OLD) and
https://mega-radio--noah.kody.run/ (NEW).
src/origins.tsholds both origins (local pair forkody devon *.localhost).src/move.ts(served as/move.js, page/move) moves exactly one browser item, localStoragemega-radio:repeat, with markersmega-radio:migrated(OLD) andmega-radio:imported(NEW): window handoff (postMessage, exact origins, nonce) or a downloaded JSON file (noah/mega-radio-migration, version 1). No server relay. Never read or write any other storage key.