diff --git a/app-phone/src/main/kotlin/pw/binom/viewmate/phone/ui/DetailsScreen.kt b/app-phone/src/main/kotlin/pw/binom/viewmate/phone/ui/DetailsScreen.kt index a73f5e5..e78ad11 100644 --- a/app-phone/src/main/kotlin/pw/binom/viewmate/phone/ui/DetailsScreen.kt +++ b/app-phone/src/main/kotlin/pw/binom/viewmate/phone/ui/DetailsScreen.kt @@ -85,10 +85,34 @@ fun DetailsScreen( mirrorStatus = runCatching { app.mirror.mirrorByItem(item.Id) }.getOrNull() mirrorJob = runCatching { app.mirror.list(limit = 500).firstOrNull { it.itemId == item.Id } }.getOrNull() loading = false - while (mirrorStatus?.status == "processing" || mirrorStatus?.status == "queued") { - delay(3_000) - mirrorStatus = runCatching { app.mirror.mirrorByItem(item.Id) }.getOrNull() - mirrorJob = runCatching { app.mirror.list(limit = 500).firstOrNull { it.itemId == item.Id } }.getOrNull() + var retryCount = 0 + while (true) { + when (mirrorStatus?.status) { + "processing", "queued" -> { + delay(3_000) + mirrorStatus = runCatching { app.mirror.mirrorByItem(item.Id) }.getOrNull() + mirrorJob = runCatching { app.mirror.list(limit = 500).firstOrNull { it.itemId == item.Id } }.getOrNull() + retryCount = 0 + } + "done" -> { + break + } + "failed", "error" -> { + if (retryCount < 2) { + retryCount++ + log("mirror", "конвертация упала, retry $retryCount/2 для ${item.Id}") + runCatching { app.mirror.createMirror(item.Id) } + .onSuccess { refreshKey++ } + .onFailure { e -> log("mirror", "retry $retryCount не удался: ${e.message}") } + delay(5_000) + } else { + break + } + } + else -> { + break + } + } } }