feat(android): albums from the phone — several files shared at once are one link
Albums.encode and Grant.encode (live grants too) write what TS writes; the album vector is resealed byte for byte from Kotlin. MediaUploader.uploadAlbum seals and uploads one. The demo turns a multi-file share into an album and its player lists an album's items and opens them in place. The live cross-check uploads an album from Kotlin that TS opens. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,7 @@ import { createHash, randomBytes } from 'node:crypto';
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { MediaClient, OwnerKey, fromCapabilityUrl, openGrant, toCapabilityUrl } from '../packages/shade-media/src/index.js';
|
||||
import { MediaClient, OwnerKey, fromCapabilityUrl, openAlbum, openGrant, toCapabilityUrl } from '../packages/shade-media/src/index.js';
|
||||
import type { MediaGrant } from '../packages/shade-media/src/index.js';
|
||||
import { createMediaService, mediaMaxRequestBody } from '../packages/shade-media/src/server.js';
|
||||
import { OFFSET_HEADER } from '../packages/shade-media/src/upload.js';
|
||||
@@ -105,6 +105,7 @@ try {
|
||||
film: { link: string; sha256: string; size: number };
|
||||
again: string;
|
||||
photo: { url: string };
|
||||
album: string;
|
||||
};
|
||||
const film = fromCapabilityUrl(out.film.link) as MediaGrant;
|
||||
const reader = await openGrant(film);
|
||||
@@ -112,13 +113,16 @@ try {
|
||||
check(sha256(await reader.read(0, reader.size)) === out.film.sha256, 'film bytes differ');
|
||||
check(reader.meta.name === 'Fra telefonen — «Kveld».mp4', `film name is ${reader.meta.name}`);
|
||||
check(out.again === out.film.link, 'putting the film again gave another link');
|
||||
const album = await openAlbum(fromCapabilityUrl(out.album) as MediaGrant);
|
||||
check(album.title === 'Tur — «Lofoten»' && album.items.length === 2, `album is ${album.title} with ${album.items.length} items`);
|
||||
check(toCapabilityUrl('https://watch.example/', album.items[0]!) === out.film.link, "the album's first item is not the film");
|
||||
check((await fetch(out.photo.url, { method: 'HEAD' })).status === 404, 'the deleted photo is still served');
|
||||
check(faults.lostAnswer === 1 && faults.refused === 1, `faults not hit: ${JSON.stringify(faults)}`);
|
||||
const left = await new MediaClient(url, kotlinOwner).list();
|
||||
check(left.items.length === 3, `Kotlin owner should have 3 files left (film, re-shared video, Android share), has ${left.items.length}`);
|
||||
check(left.items.length === 4, `Kotlin owner should have 4 files left (film, re-shared video, album, Android share), has ${left.items.length}`);
|
||||
console.log(
|
||||
`LIVE OK — Kotlin read the TS file; Kotlin film ${(out.film.size / MiB).toFixed(1)} MiB in ${faults.pieces} piece requests ` +
|
||||
`(${faults.starts} starts/resyncs, 1 lost answer, 1 refusal) read back by TS byte for byte; upload job killed and resumed; a content:// share uploaded from Robolectric; photo deleted`,
|
||||
`(${faults.starts} starts/resyncs, 1 lost answer, 1 refusal) read back by TS byte for byte; upload job killed and resumed; an album TS opens; a content:// share uploaded from Robolectric; photo deleted`,
|
||||
);
|
||||
} finally {
|
||||
server.stop(true);
|
||||
|
||||
Reference in New Issue
Block a user