mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 06:42:05 +01:00
Backups
Restmore may be broken
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
package ca.gosyer.jui.domain.backup.interactor
|
||||
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepositoryOld
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepository
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.singleOrNull
|
||||
@@ -16,19 +16,25 @@ import org.lighthousegames.logging.logging
|
||||
class ExportBackupFile
|
||||
@Inject
|
||||
constructor(
|
||||
private val backupRepositoryOld: BackupRepositoryOld,
|
||||
private val backupRepository: BackupRepository,
|
||||
) {
|
||||
suspend fun await(
|
||||
includeCategories: Boolean,
|
||||
includeChapters: Boolean,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
onError: suspend (Throwable) -> Unit = {},
|
||||
) = asFlow(block)
|
||||
) = asFlow(includeCategories, includeChapters, block)
|
||||
.catch {
|
||||
onError(it)
|
||||
log.warn(it) { "Failed to export backup" }
|
||||
}
|
||||
.singleOrNull()
|
||||
|
||||
fun asFlow(block: HttpRequestBuilder.() -> Unit = {}) = backupRepositoryOld.exportBackupFile(block)
|
||||
fun asFlow(
|
||||
includeCategories: Boolean,
|
||||
includeChapters: Boolean,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
) = backupRepository.createBackup(includeCategories, includeChapters, block)
|
||||
|
||||
companion object {
|
||||
private val log = logging()
|
||||
|
||||
@@ -6,24 +6,24 @@
|
||||
|
||||
package ca.gosyer.jui.domain.backup.interactor
|
||||
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepositoryOld
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepository
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.singleOrNull
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.SYSTEM
|
||||
import org.lighthousegames.logging.logging
|
||||
|
||||
class ImportBackupFile
|
||||
@Inject
|
||||
constructor(
|
||||
private val backupRepositoryOld: BackupRepositoryOld,
|
||||
private val backupRepository: BackupRepository,
|
||||
) {
|
||||
suspend fun await(
|
||||
file: Path,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
onError: suspend (Throwable) -> Unit = {},
|
||||
) = asFlow(file, block)
|
||||
) = asFlow(file)
|
||||
.catch {
|
||||
onError(it)
|
||||
log.warn(it) { "Failed to import backup ${file.name}" }
|
||||
@@ -32,8 +32,7 @@ class ImportBackupFile
|
||||
|
||||
fun asFlow(
|
||||
file: Path,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
) = backupRepositoryOld.importBackupFile(BackupRepositoryOld.buildBackupFormData(file), block)
|
||||
) = backupRepository.restoreBackup(FileSystem.SYSTEM.source(file))
|
||||
|
||||
companion object {
|
||||
private val log = logging()
|
||||
|
||||
@@ -6,24 +6,24 @@
|
||||
|
||||
package ca.gosyer.jui.domain.backup.interactor
|
||||
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepositoryOld
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
import ca.gosyer.jui.domain.backup.service.BackupRepository
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.singleOrNull
|
||||
import me.tatarka.inject.annotations.Inject
|
||||
import okio.FileSystem
|
||||
import okio.Path
|
||||
import okio.SYSTEM
|
||||
import org.lighthousegames.logging.logging
|
||||
|
||||
class ValidateBackupFile
|
||||
@Inject
|
||||
constructor(
|
||||
private val backupRepositoryOld: BackupRepositoryOld,
|
||||
private val backupRepository: BackupRepository,
|
||||
) {
|
||||
suspend fun await(
|
||||
file: Path,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
onError: suspend (Throwable) -> Unit = {},
|
||||
) = asFlow(file, block)
|
||||
) = asFlow(file)
|
||||
.catch {
|
||||
onError(it)
|
||||
log.warn(it) { "Failed to validate backup ${file.name}" }
|
||||
@@ -32,8 +32,7 @@ class ValidateBackupFile
|
||||
|
||||
fun asFlow(
|
||||
file: Path,
|
||||
block: HttpRequestBuilder.() -> Unit = {},
|
||||
) = backupRepositoryOld.validateBackupFile(BackupRepositoryOld.buildBackupFormData(file), block)
|
||||
) = backupRepository.validateBackup(FileSystem.SYSTEM.source(file))
|
||||
|
||||
companion object {
|
||||
private val log = logging()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.domain.backup.model
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
enum class RestoreState {
|
||||
IDLE,
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
RESTORING_CATEGORIES,
|
||||
RESTORING_MANGA,
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class RestoreStatus(
|
||||
val state: RestoreState,
|
||||
val completed: Int,
|
||||
val total: Int,
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
package ca.gosyer.jui.domain.backup.service
|
||||
|
||||
import ca.gosyer.jui.domain.backup.model.BackupValidationResult
|
||||
import ca.gosyer.jui.domain.backup.model.RestoreStatus
|
||||
import io.ktor.client.request.HttpRequestBuilder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import okio.Source
|
||||
|
||||
interface BackupRepository {
|
||||
fun validateBackup(source: Source): Flow<BackupValidationResult>
|
||||
fun restoreBackup(source: Source): Flow<Pair<String, RestoreStatus>>
|
||||
fun restoreStatus(id: String): Flow<RestoreStatus>
|
||||
fun createBackup(
|
||||
includeCategories: Boolean,
|
||||
includeChapters: Boolean,
|
||||
block: HttpRequestBuilder.() -> Unit,
|
||||
): Flow<Pair<String, Source>>
|
||||
}
|
||||
Reference in New Issue
Block a user