π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Compress image attachments on Android
laurenspriem300f8a3beed4
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.ktindex c15bab1eda..2c95d47c5d 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt@@ -67,6 +67,7 @@ import io.ente.ensu.domain.model.LogEntryimport io.ente.ensu.domain.state.AppStateimport io.ente.ensu.domain.store.AppStoreimport io.ente.ensu.utils.EnsuFeatureFlags+import io.ente.labs.ensu_db.compressAttachmentImageimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.launch@@ -449,19 +450,31 @@ private fun buildAttachmentFromUri(val attachmentId = UUID.randomUUID().toString()val destination = File(attachmentsDir, attachmentId)return runCatching {- val inputStream = resolver.openInputStream(uri) ?: return@runCatching null+ val finalName: String- inputStream.use { input ->+ if (type == AttachmentType.Image) {+ val inputStream = resolver.openInputStream(uri) ?: return@runCatching null+ val originalBytes = inputStream.use { input -> input.readBytes() }+ val compressedBytes = compressAttachmentImage(originalBytes)FileOutputStream(destination).use { output ->- input.copyTo(output)+ output.write(compressedBytes)}+ finalName = normalizedJpegAttachmentName(name ?: safeName)+ } else {+ val inputStream = resolver.openInputStream(uri) ?: return@runCatching null+ inputStream.use { input ->+ FileOutputStream(destination).use { output ->+ input.copyTo(output)+ }+ }+ finalName = name ?: safeName}val finalSize = destination.length().takeIf { it > 0 } ?: size ?: 0LAttachment(id = attachmentId,- name = name ?: safeName,+ name = finalName,sizeBytes = finalSize,type = type,localPath = destination.absolutePath,@@ -470,6 +483,18 @@ private fun buildAttachmentFromUri(}.getOrNull()}+private fun normalizedJpegAttachmentName(name: String?): String {+ val raw = name+ ?.replace("\u0000", "")+ ?.replace("\\", "/")+ ?.substringAfterLast("/")+ ?.trim()+ ?.takeIf { it.isNotBlank() }+ ?: "image"+ val base = raw.substringBeforeLast(".", raw).ifBlank { "image" }+ return "$base.jpg"+}+private fun openAttachment(context: Context, attachment: Attachment) {val path = attachment.localPathif (path.isNullOrBlank()) {