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

@@ -222,9 +222,8 @@ describe('live relay over real WebSockets', () => {
const thief = new LivePublisher({ channelId: pub.channelId });
const terr: string[] = [];
const tc = new LivePublishClient({ relay: base, publisher: thief, readToken: new Uint8Array(32), onError: (m) => terr.push(m) });
await until(() => terr.length > 0);
await expect(tc.whenReady()).rejects.toThrow(/pinned/);
expect(terr[0]).toMatch(/pinned/);
tc.close();
await client.end();
await until(() => early.at(-1)?.content.type === 'end');
@@ -235,6 +234,29 @@ describe('live relay over real WebSockets', () => {
}
});
test('a relay with owners only takes channels co-signed by one of them', async () => {
const owner = OwnerKey.generate();
const relay = createLiveRelay({ pins: new MemoryLivePinStore(), allowedOwners: [owner.id] });
const { server, base } = serve(relay.app);
try {
const errs: string[] = [];
const stranger = new LivePublishClient({ relay: base, publisher: new LivePublisher(), readToken: new Uint8Array(32), onError: (m) => errs.push(m) });
await expect(stranger.whenReady()).rejects.toThrow(/owners/);
expect(errs[0]).toMatch(/owners/);
// Another owner's co-signature on this hello does not count either.
const errs2: string[] = [];
const wrong = new LivePublishClient({ relay: base, publisher: new LivePublisher(), readToken: new Uint8Array(32), owner: OwnerKey.generate(), onError: (m) => errs2.push(m) });
await until(() => errs2.length > 0);
wrong.close();
const ok = new LivePublishClient({ relay: base, publisher: new LivePublisher(), readToken: new Uint8Array(32), owner });
await ok.whenReady();
ok.close();
} finally {
relay.stop();
server.stop(true);
}
});
test('rotation: a re-granted viewer continues, the other is locked out; pins persist', async () => {
const dir = await tempDir();
const pins = new FileLivePinStore(join(dir, 'pins.json'));