fix: delete uses @HTTP hasBody + JsonObject return type

- Retrofit @DELETE doesn't support @Body — switched to @HTTP(method=DELETE, hasBody=true)
- Return type changed from Map<String,Any?> to JsonObject (kotlinx-serialization
  can't deserialize untyped maps)
- Fixed double-slash in download URL (baseUrl trailing slash)
- Cleaned up download progress tracking (emit outside withContext(IO))
This commit is contained in:
Mathieu Moran
2026-08-12 01:35:11 -04:00
parent 3916f9879e
commit 1556c65131
2 changed files with 10 additions and 2 deletions
@@ -144,7 +144,14 @@ class DashcamViewModel(application: Application) : AndroidViewModel(application)
fun deleteVideo(video: VideoFile) {
viewModelScope.launch {
try {
api.deleteVideo(mapOf("path" to video.path))
val result = api.deleteVideo(mapOf("path" to video.path))
val status = result["status"]?.let { it.toString().trim('"') } ?: "unknown"
if (status == "ok") {
_downloadEvents.emit("✓ Deleted: ${video.path}")
} else {
val msg = result["message"]?.let { it.toString().trim('"') } ?: status
_downloadEvents.emit("✗ Delete: $msg")
}
loadVideos()
} catch (e: Exception) {
_error.value = "Delete failed: ${e.message}"
@@ -2,6 +2,7 @@ package com.yarisobd.app.data.remote
import com.yarisobd.app.data.remote.dto.GpsStatus
import com.yarisobd.app.data.remote.dto.VideoListResponse
import kotlinx.serialization.json.JsonObject
import okhttp3.ResponseBody
import retrofit2.http.Body
import retrofit2.http.GET
@@ -33,5 +34,5 @@ interface PiApi {
/** Delete local copy only */
@HTTP(method = "DELETE", path = "/api/local-video", hasBody = true)
suspend fun deleteVideo(@Body body: Map<String, String>): Map<String, Any?>
suspend fun deleteVideo(@Body body: Map<String, String>): JsonObject
}