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:
2026-10-19 00:34:24 +02:00
parent 7d45be8712
commit 65d7a0646f
11 changed files with 202 additions and 33 deletions

View File

@@ -1,5 +1,7 @@
package no.zyon.shade
import no.zyon.shade.media.Album
import no.zyon.shade.media.Albums
import no.zyon.shade.media.FileRangeSource
import no.zyon.shade.media.Grants
import no.zyon.shade.media.MediaGrant
@@ -109,11 +111,20 @@ class MediaLiveTest {
assertTrue(uploader.delete(photo.mediaId))
assertFalse(uploader.delete(photo.mediaId))
// The photos of a trip, shared at once: one album link for all of them.
val album = uploader.uploadAlbum(Album("Tur — «Lofoten»", listOf(film, fresh)))
album.open().use { r ->
val back = Albums.read(r)
assertEquals("Tur — «Lofoten»", back.title)
assertEquals(listOf(film.encode(), fresh.encode()), back.items.map { it.encode() })
}
File(spec.getString("kotlinOut")).writeText(
JSONObject()
.put("film", JSONObject().put("link", film.capabilityUrl("https://watch.example/")).put("sha256", sha256(plain)).put("size", plain.size))
.put("again", again.capabilityUrl("https://watch.example/"))
.put("photo", JSONObject().put("url", photo.url))
.put("album", album.capabilityUrl("https://watch.example/"))
.toString(),
)
sealedFile.delete()

View File

@@ -137,6 +137,7 @@ class MediaVectorTest {
fun liveFramesOpenFromTheLinkGrantAcrossARotation() {
val g = Grants.parse(byPrefix("live grant").single().getString("json")) as LiveGrant
assertNotNull(g.channelSecret)
assertEquals(byPrefix("live grant").single().getString("json"), g.encode())
val sub = LiveSubscriber(g)
for (v in byPrefix("live frame")) {
val f = sub.open(hex(v.getString("wire")))
@@ -193,6 +194,11 @@ class MediaVectorTest {
assertEquals(ALBUM_MIME, reader.meta.mime)
val album = Albums.read(reader)
assertEquals(v.getString("title"), album.title)
// And written back: the same plaintext, sealed to the same bytes.
val plain = Albums.encode(album)
assertEquals(v.getString("plaintext"), String(plain, Charsets.UTF_8))
val (resealed, _) = MediaSealer.withPinnedKeys(mediaId, mediaKey, Albums.meta(album.title), 4096).sealAll(plain)
assertEquals(v.getString("sealed"), toHex(resealed))
val kinds = v.getJSONArray("itemKinds")
val names = v.getJSONArray("itemNames")
assertEquals(kinds.length(), album.items.size)