import { kody, packageStorage } from 'kody:runtime' import { OWNER_KODY_ID } from './config.ts' import { store } from './store.ts' /** Storage keys left by an older version of this package; removed by `{ action: 'forget-legacy' }`. */ const LEGACY_KEYS = ['source:auth', 'radio:sync', 'radio:catalog'] /** * Manage the MEGA Radio MP3s and covers kept in this package's storage (see src/audio-core.ts). * Owner only. Called by scripts/upload-radio.ts through `kody execute --invoke kody:@noah/mega-radio/audio-store`. * * @param params - `{ action: 'begin' | 'put' | 'status' | 'verify' | 'remove' | 'store', code, ... }`, `{ action: 'list', prefix }` * or `{ action: 'forget-legacy' }` (deletes old storage keys this version no longer uses) * @returns a small JSON summary, never the file itself */ export default async function audioStore(params: Record = {}) { const me = (await kody.metaGetCurrentUser({})) as { user_id?: string } if (me?.user_id !== OWNER_KODY_ID) throw new Error('Only the package owner can manage the radio files.') if (params.action === 'forget-legacy') { const removed: string[] = [] for (const k of LEGACY_KEYS) { if ((await packageStorage().get(k)) == null) continue await packageStorage().delete(k) removed.push(k) } return { ok: true, removed } } return store.manage(params) } export const serveFile = store.serve