feat(zns-import): DAT-Dateisupport hinzugefügt, Fehlerbehebung und UI-Anpassungen
Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
+11
-5
@@ -24,7 +24,7 @@ import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
|
||||
@Serializable
|
||||
internal data class JobIdResponse(val jobId: String)
|
||||
data class ImportStartResponse(val jobId: String)
|
||||
|
||||
@Serializable
|
||||
internal data class JobStatusResponse(
|
||||
@@ -57,8 +57,12 @@ class ZnsImportViewModel(
|
||||
override fun startImport(mode: String) {
|
||||
val filePath = state.selectedFilePath ?: return
|
||||
val file = File(filePath)
|
||||
if (!file.exists() || !file.name.endsWith(".zip", ignoreCase = true)) {
|
||||
state = state.copy(errorMessage = "Bitte eine gültige .zip-Datei auswählen.")
|
||||
if (!file.exists() || !(file.name.endsWith(".zip", ignoreCase = true) || file.name.endsWith(
|
||||
".dat",
|
||||
ignoreCase = true
|
||||
))
|
||||
) {
|
||||
state = state.copy(errorMessage = "Bitte eine gültige .zip oder .dat-Datei auswählen.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -72,15 +76,17 @@ class ZnsImportViewModel(
|
||||
val response: HttpResponse = httpClient.post("${NetworkConfig.baseUrl}/api/v1/import/zns") {
|
||||
parameter("mode", mode)
|
||||
if (token != null) header(HttpHeaders.Authorization, "Bearer $token")
|
||||
val contentType =
|
||||
if (file.name.endsWith(".zip", ignoreCase = true)) "application/zip" else "application/octet-stream"
|
||||
setBody(MultiPartFormDataContent(formData {
|
||||
append("file", file.readBytes(), Headers.build {
|
||||
append(HttpHeaders.ContentDisposition, "filename=\"${file.name}\"")
|
||||
append(HttpHeaders.ContentType, "application/zip")
|
||||
append(HttpHeaders.ContentType, contentType)
|
||||
})
|
||||
}))
|
||||
}
|
||||
if (response.status == HttpStatusCode.Accepted) {
|
||||
val body = json.decodeFromString<JobIdResponse>(response.bodyAsText())
|
||||
val body = json.decodeFromString<ImportStartResponse>(response.bodyAsText())
|
||||
state = state.copy(isUploading = false, jobId = body.jobId, jobStatus = "AUSSTEHEND")
|
||||
startPolling(body.jobId)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user