feat(media): albums — one link for a season or a photo album; fix path traversal in media get
An album is a sealed file (shade.album/v1) listing grants, so the relay cannot tell it from a film. `shade media put dir/` uploads every file and the album (subdirectories nest, natural order); `media get` brings an album back as a directory; /watch/ shows a grid with decrypted previews and Back returns to the album without putting grants in history. Kotlin reads albums (Albums.read) against a new shared vector. Fixed: `media get` used the sealer-chosen meta.name as the output path. Fixed a relay test race (flush() is sent, not received); the relay now reports framesIn. Verified: 64 TS tests x3, Kotlin 81/0, a 6-file album with a nested album uploaded, browsed, played and downloaded back bit-identical. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
package no.zyon.shade
|
||||
|
||||
import no.zyon.shade.media.ALBUM_MIME
|
||||
import no.zyon.shade.media.Albums
|
||||
import no.zyon.shade.media.ByteArraySource
|
||||
import no.zyon.shade.media.FOOTER_BYTES
|
||||
import no.zyon.shade.media.Grants
|
||||
import no.zyon.shade.media.LIVE_GRANT_KIND
|
||||
import no.zyon.shade.media.LiveContent
|
||||
import no.zyon.shade.media.LiveGrant
|
||||
import no.zyon.shade.media.LiveKeyException
|
||||
import no.zyon.shade.media.LivePublisher
|
||||
import no.zyon.shade.media.LiveSubscriber
|
||||
import no.zyon.shade.media.MEDIA_GRANT_KIND
|
||||
import no.zyon.shade.media.MediaFormatException
|
||||
import no.zyon.shade.media.MediaGrant
|
||||
import no.zyon.shade.media.MediaIntegrityException
|
||||
import no.zyon.shade.media.MediaKeys
|
||||
@@ -23,6 +28,7 @@ import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertThrows
|
||||
@@ -176,4 +182,30 @@ class MediaVectorTest {
|
||||
assertArrayEquals(mediaId, g.mediaId)
|
||||
assertThrows(Exception::class.java) { Grants.parse("""{"kind":"shade.media-grant/v1","mediaId":"AA","key":"AA","root":"ab"}""") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun albumOpensFromTheSealedVector() {
|
||||
val v = byPrefix("album:").single()
|
||||
val reader = MediaReader.open(ByteArraySource(hex(v.getString("sealed"))), MediaKeys(mediaId, mediaKey, hex(v.getString("rootDigest"))))
|
||||
assertEquals(ALBUM_MIME, reader.meta.mime)
|
||||
val album = Albums.read(reader)
|
||||
assertEquals(v.getString("title"), album.title)
|
||||
val kinds = v.getJSONArray("itemKinds")
|
||||
val names = v.getJSONArray("itemNames")
|
||||
assertEquals(kinds.length(), album.items.size)
|
||||
album.items.forEachIndexed { i, g ->
|
||||
assertEquals(kinds.getString(i), if (g is MediaGrant) MEDIA_GRANT_KIND else LIVE_GRANT_KIND)
|
||||
val meta = when (g) {
|
||||
is MediaGrant -> g.meta
|
||||
is LiveGrant -> g.meta
|
||||
}
|
||||
assertEquals(names.getString(i), meta?.name)
|
||||
}
|
||||
assertTrue(Albums.isAlbum(album.items[1]))
|
||||
assertFalse(Albums.isAlbum(album.items[0]))
|
||||
// Strict: a bad item, the wrong kind, invalid UTF-8.
|
||||
assertThrows(MediaFormatException::class.java) { Albums.parse("""{"kind":"shade.album/v1","title":"","items":[{"kind":"x"}]}""".toByteArray()) }
|
||||
assertThrows(MediaFormatException::class.java) { Albums.parse("""{"kind":"shade.album/v2","title":"","items":[]}""".toByteArray()) }
|
||||
assertThrows(MediaFormatException::class.java) { Albums.parse(byteArrayOf(0xff.toByte(), 0xfe.toByte())) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user