Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ class MaaMeetingRepo @Inject constructor(

serverList.forEach { item ->

val imageUriList = (item.meetingImages ?: emptyList()).mapNotNull { base64 ->
val imageUriList = withContext(Dispatchers.IO){ (item.meetingImages ?: emptyList()).mapNotNull { base64 ->
try {
val base64Data = base64.substringAfter(",", base64)
val bytes = Base64.decode(base64Data, Base64.DEFAULT)
val (ext, _) = detectExtAndMime(bytes)

val file = File(
appContext.cacheDir,
"meeting_${System.currentTimeMillis()}.$ext"
"meeting_${item.id}_img${index}.$ext"
)

file.outputStream().use { it.write(bytes) }
Expand All @@ -164,7 +164,7 @@ class MaaMeetingRepo @Inject constructor(

} catch (e: Exception) {
null
}
}}
}

val entity = MaaMeetingEntity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ class SaasBahuSammelanRepo @Inject constructor(
saasBahuDao.clearAll()
parsed.data?.forEach { item ->
val imageBase64List = item.meetingImages ?: emptyList()
val imageUriList = imageBase64List.mapNotNull { base64 ->
val imageUriList = withContext(Dispatchers.IO) {imageBase64List.mapNotNull { base64 ->
try {
val base64Data = base64.substringAfter(",", base64)
val bytes = Base64.decode(base64Data, Base64.DEFAULT)
val (ext, _) = detectExtAndMime(bytes)
val file = File(appContext.cacheDir, "saas_bahu_sammelan${System.currentTimeMillis()}.$ext")
val file = File(appContext.cacheDir, "saas_bahu_${item.id}_img${index}.$ext")
file.outputStream().use { it.write(bytes) }
val uri = FileProvider.getUriForFile(
appContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class UwinRepo @Inject constructor(
val base64Data = base64.substringAfter(",", base64)
val bytes = Base64.decode(base64Data, Base64.DEFAULT)
val (ext, _) = detectExtAndMime(bytes)
val file = File(appContext.cacheDir, "uwin_${System.currentTimeMillis()}.$ext")
val file = File(appContext.cacheDir, "uwin_${item.id}_img${index}.$ext")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor | ⚑ Quick win

Edge case: nullable item.id produces collision-prone filename.

UwinServerItem.id is Int? (line 271). When id is null, the filename becomes uwin_null_img0.$ext, so multiple server entries lacking an id will overwrite each other's cached images on the same down-sync. Either skip the item early or substitute a stable fallback before building the file name.

πŸ›  Proposed fix
         val localList = entries.mapNotNull { item ->
+            val itemId = item.id ?: return@mapNotNull null
             val imageUriList = item.meetingImages?.mapIndexedNotNull { index, base64 ->
                 try {
                     val base64Data = base64.substringAfter(",", base64)
                     val bytes = Base64.decode(base64Data, Base64.DEFAULT)
                     val (ext, _) = detectExtAndMime(bytes)
-                    val file = File(appContext.cacheDir, "uwin_${item.id}_img${index}.$ext")
+                    val file = File(appContext.cacheDir, "uwin_${itemId}_img${index}.$ext")
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/org/piramalswasthya/sakhi/repositories/UwinRepo.kt` at line
222, The filename generation uses UwinServerItem.id which is nullable, causing
"uwin_null_..." collisions; change the logic around where File is created (the
val file = File(... "uwin_${item.id}_img${index}.$ext")) to either skip
processing when item.id is null or substitute a stable fallback (e.g., item.id
?: item.hashCode() or a generated UUID per item) so filenames are unique; update
the filename expression to use that fallback and add a debug/warning log when id
is null to aid tracing.

file.outputStream().use { it.write(bytes) }
val uri = FileProvider.getUriForFile(
appContext,
Expand Down