feat(media,server): media in the Shade container, owner-only uploads and channels

- createMediaService: sealed store + live relay + /watch in one mount, used
  by both `shade media serve` and standalone.ts
- SHADE_MEDIA_DIR enables it (no in-memory fallback, like the vault);
  SHADE_MEDIA_OWNERS lists who may upload and open live channels
- live publishers co-sign their hello with an owner key; a relay with an
  owner list refuses everyone else, and the client stops on that refusal
  instead of reconnecting forever
- relay caps live channels held at once; `shade media whoami`

Verified against the real standalone process: film round trip identical,
stranger gets 403 / refused channel, live logs and browser playback.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-18 21:10:43 +02:00
parent d117397b36
commit df3ca685c5
10 changed files with 225 additions and 23 deletions

View File

@@ -294,6 +294,37 @@ if (vaultDisabled) {
logger.info('Vault enabled', { route: '/v1/vault/:vaultId' });
}
// V4.15 — media: sealed films/video/images/audio over Range, live channels
// (logs, text, live video) through a relay, and the /watch page that plays
// both. Same rule as the vault: a media library that lives in RAM loses every
// film on the next redeploy, so no directory means no media, said loudly.
// Uploads and live channels are closed to everyone but SHADE_MEDIA_OWNERS.
let mediaService: import('@shade/media/server').MediaService | null = null;
if (process.env.SHADE_DISABLE_MEDIA === '1') {
logger.info('Media disabled (SHADE_DISABLE_MEDIA=1)');
} else if (!process.env.SHADE_MEDIA_DIR) {
logger.warn(
'Media not enabled — set SHADE_MEDIA_DIR to a directory on a persistent volume. ' +
'There is no in-memory fallback on purpose: a library that forgets on redeploy is not a library.',
);
} else {
const { createMediaService, parseOwners } = await import('@shade/media/server');
const owners = parseOwners(process.env.SHADE_MEDIA_OWNERS);
if (owners !== 'any' && owners.length === 0) {
logger.warn(
'Media is read-only: SHADE_MEDIA_OWNERS is empty, so nobody can upload or open a live channel. ' +
'Add owner keys (`shade media whoami`), comma-separated.',
);
}
mediaService = createMediaService({ dir: process.env.SHADE_MEDIA_DIR, owners });
app.route('/', mediaService.app);
logger.info('Media enabled', {
routes: ['/v1/media/:id', '/v1/live/:channelId', '/watch/'],
dir: process.env.SHADE_MEDIA_DIR,
owners: owners === 'any' ? 'any' : owners.length,
});
}
// ─── Optional: Observer + Dashboard ──────────────────────────
const observerToken = process.env.SHADE_OBSERVER_TOKEN;
@@ -361,6 +392,7 @@ async function shutdown(signal: string) {
try {
cleanupTask.stop();
inboxPrune.stop();
mediaService?.stop();
server.stop();
if ('close' in store && typeof store.close === 'function') {
await store.close();