Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← 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.

FollowForkOpen app

Files

AGENTS.md

40 lines · 3.7 KB · Markdown

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.ts radio (titles, lengths, open dates; also the npm run upload-radio list). 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: edit src/tracks.ts, publish, run npm run upload-radio.
  • ./audio-store { action: 'forget-legacy' } (owner only) deletes storage keys an older version used.
  • Do not import kody:* in page.ts, player.ts, styles.ts, tracks.ts, discord.ts or audio-core.ts (keeps them unit-testable). node --experimental-strip-types --test test/*.test.ts needs Node 22 or later.
  • Gate flow: currentVisitor() (metaGetCurrentUser, only user_id/username are trusted) → getMembership(user_id) → isActive (member and checkedAt < 30 days). Every /files/radio/* request runs this check.
  • Discord app: "Mega.dev", client ID 1565030809998458920 (DISCORD_CLIENT_ID in src/config.ts).
  • Discord check: /discord/start stores pkce:<state> → {verifier, userId} and sets the __Secure-<cookiePrefix>dstate cookie. It then redirects with prompt=none and retries with prompt=consent on consent_required. /discord/callback checks the state cookie, the stored userId and the iss value, exchanges the code (public client, no secret), calls checkMembership, and revokes the token.
  • No Kody credential needs on purpose: declaring an executor need (even required: false) made the platform redirect every route to a need:discord consent screen. Membership is proven only through the app's own Discord OAuth.
  • checkMembership uses /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: packageAppFetch GET /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 calls kody:@noah/mega-radio/audio-store, which is owner-only via OWNER_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) and play_user (user_id, n, plays, last_ms); last_ms exists only for the rate limit (90% of the track length, at least 30 s). POST /plays/NN runs the same membership gate as the audio and needs content-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.ts holds both origins (local pair for kody dev on *.localhost). src/move.ts (served as /move.js, page /move) moves exactly one browser item, localStorage mega-radio:repeat, with markers mega-radio:migrated (OLD) and mega-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.