feat(android): Share to Shade — a video from the gallery is sealed on the phone and uploaded

ShadeUpload turns a shared content:// URI into meta and an upload job;
KeystoreSecretFile keeps the owner seed under a Keystore key. The demo app
takes SEND/SEND_MULTIPLE of video, images, audio and documents, uploads in a
foreground service with progress, and its done notification plays the file
or shares the link; the player gets a Share button. The live cross-check
also uploads a content:// share under Robolectric.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-19 00:28:36 +02:00
parent b53dcd7813
commit 0a706cdb47
16 changed files with 733 additions and 11 deletions

View File

@@ -42,7 +42,7 @@ class MediaUploader(
private val owner: MediaOwner,
private val timeoutMs: Int = 60_000,
) {
private val server = server.trimEnd('/')
val server = server.trimEnd('/')
fun mediaUrl(mediaId: ByteArray): String = "$server/v1/media/${hex(mediaId)}"
@@ -130,7 +130,7 @@ class MediaUploader(
val j = job ?: run {
val sealed = jobs.sealedFile(key)
val result = open().use { input -> sealed.outputStream().buffered().use { MediaSealer.sealStream(input, it, meta) } }
UploadJobs.Job(result, readToken, meta, source).also { jobs.save(key, it) }
UploadJobs.Job(result, readToken, meta, source, server = server).also { jobs.save(key, it) }
}
val grant = FileRangeSource(jobs.sealedFile(key)).use { putSealed(j.result, it, j.readToken, j.meta, onProgress) }
jobs.done(key, j, grant)
@@ -334,7 +334,7 @@ class MediaUploader(
}
private fun request(method: String, url: String, headers: Map<String, String>, body: ByteArray?): Answer {
val c = URL(url).openConnection() as HttpURLConnection
val c = java.net.URI(url).toURL().openConnection() as HttpURLConnection
try {
c.requestMethod = method
c.connectTimeout = timeoutMs

View File

@@ -36,6 +36,8 @@ class UploadJobs(private val dir: File) {
val source: String,
/** Set once the relay stored the file. */
val grant: MediaGrant? = null,
/** The relay it goes to, for resuming it after a restart. */
val server: String = "",
)
class BusyException(message: String) : Exception(message)
@@ -107,6 +109,7 @@ class UploadJobs(private val dir: File) {
MediaMeta.fromJson(o.getString("meta")),
o.optString("source"),
if (o.has("grant")) Grants.parse(o.getString("grant")) as? MediaGrant else null,
o.optString("server"),
)
} catch (e: JSONException) {
return null
@@ -122,6 +125,7 @@ class UploadJobs(private val dir: File) {
val o = JSONObject()
.put("v", 1)
.put("source", job.source)
.put("server", job.server)
.put(
"result",
JSONObject()
@@ -144,7 +148,7 @@ class UploadJobs(private val dir: File) {
/** The relay has it: keep the grant, drop the sealed copy. */
fun done(key: String, job: Job, grant: MediaGrant): Job {
val finished = Job(job.result, job.readToken, job.meta, job.source, grant)
val finished = Job(job.result, job.readToken, job.meta, job.source, grant, job.server)
save(key, finished)
sealedFile(key).delete()
return finished

View File

@@ -23,7 +23,7 @@ class UploadJobsTest {
val result = jobs.sealedFile(key).also { it.parentFile.mkdirs() }.outputStream().use {
MediaSealer.sealStream(ByteArray(200_000) { i -> i.toByte() }.inputStream(), it, meta)
}
return UploadJobs.Job(result, ByteArray(32) { 9 }, meta, "content://media/1")
return UploadJobs.Job(result, ByteArray(32) { 9 }, meta, "content://media/1", server = "https://relay")
}
@Test
@@ -48,6 +48,7 @@ class UploadJobsTest {
assertArrayEquals(job.result.mediaKey, back.result.mediaKey)
assertArrayEquals(job.readToken, back.readToken)
assertEquals("Kveld.mp4", back.meta.name)
assertEquals("https://relay", back.server)
assertEquals(listOf(key), jobs.unfinished().map { it.first })
// Cut short: not resumable.