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:
@@ -144,7 +144,14 @@ class DashcamViewModel(application: Application) : AndroidViewModel(application)
|
|||||||
fun deleteVideo(video: VideoFile) {
|
fun deleteVideo(video: VideoFile) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
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()
|
loadVideos()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_error.value = "Delete failed: ${e.message}"
|
_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.GpsStatus
|
||||||
import com.yarisobd.app.data.remote.dto.VideoListResponse
|
import com.yarisobd.app.data.remote.dto.VideoListResponse
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@@ -33,5 +34,5 @@ interface PiApi {
|
|||||||
|
|
||||||
/** Delete local copy only */
|
/** Delete local copy only */
|
||||||
@HTTP(method = "DELETE", path = "/api/local-video", hasBody = true)
|
@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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user