mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
add backup validation endpoints
This commit is contained in:
@@ -96,6 +96,9 @@ object MangaAPI {
|
||||
post("import", BackupController::protobufImport)
|
||||
post("import/file", BackupController::protobufImportFile)
|
||||
|
||||
post("validate", BackupController::protobufValidate)
|
||||
post("validate/file", BackupController::protobufValidateFile)
|
||||
|
||||
get("export", BackupController::protobufExport)
|
||||
get("export/file", BackupController::protobufExportFile)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import suwayomi.tachidesk.manga.impl.backup.legacy.LegacyBackupExport
|
||||
import suwayomi.tachidesk.manga.impl.backup.legacy.LegacyBackupImport
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupExport
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator
|
||||
import suwayomi.tachidesk.server.JavalinSetup
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
@@ -77,7 +78,7 @@ object BackupController {
|
||||
|
||||
/** expects a Tachiyomi protobuf backup in the body */
|
||||
fun protobufImport(ctx: Context) {
|
||||
ctx.result(
|
||||
ctx.json(
|
||||
JavalinSetup.future {
|
||||
ProtoBackupImport.performRestore(ctx.bodyAsInputStream())
|
||||
}
|
||||
@@ -86,7 +87,7 @@ object BackupController {
|
||||
|
||||
/** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
|
||||
fun protobufImportFile(ctx: Context) {
|
||||
ctx.result(
|
||||
ctx.json(
|
||||
JavalinSetup.future {
|
||||
ProtoBackupImport.performRestore(ctx.uploadedFile("backup.proto.gz")!!.content)
|
||||
}
|
||||
@@ -94,7 +95,7 @@ object BackupController {
|
||||
}
|
||||
|
||||
/** returns a Tachiyomi protobuf backup created from the current database as a body */
|
||||
fun protobufExport(ctx: Context) { // TODO
|
||||
fun protobufExport(ctx: Context) {
|
||||
ctx.contentType("application/octet-stream")
|
||||
ctx.result(
|
||||
JavalinSetup.future {
|
||||
@@ -131,4 +132,22 @@ object BackupController {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/** Reports missing sources and trackers, expects a Tachiyomi protobuf backup in the body */
|
||||
fun protobufValidate(ctx: Context) { // TODO
|
||||
ctx.json(
|
||||
JavalinSetup.future {
|
||||
ProtoBackupValidator.validate(ctx.bodyAsInputStream())
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/** Reports missing sources and trackers, expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
|
||||
fun protobufValidateFile(ctx: Context) {
|
||||
ctx.json(
|
||||
JavalinSetup.future {
|
||||
ProtoBackupValidator.validate(ctx.uploadedFile("backup.proto.gz")!!.content)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ object ProtoBackupImport : ProtoBackupBase() {
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
println("fek fek")
|
||||
return validationResult
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,16 @@ package suwayomi.tachidesk.manga.impl.backup.proto
|
||||
* 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/. */
|
||||
|
||||
import okio.buffer
|
||||
import okio.gzip
|
||||
import okio.source
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import suwayomi.tachidesk.manga.impl.backup.AbstractBackupValidator
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.models.Backup
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSerializer
|
||||
import suwayomi.tachidesk.manga.model.table.SourceTable
|
||||
import java.io.InputStream
|
||||
|
||||
object ProtoBackupValidator : AbstractBackupValidator() {
|
||||
fun validate(backup: Backup): ValidationResult {
|
||||
@@ -42,4 +47,11 @@ object ProtoBackupValidator : AbstractBackupValidator() {
|
||||
|
||||
return ValidationResult(missingSources, missingTrackers)
|
||||
}
|
||||
|
||||
fun validate(sourceStream: InputStream): ValidationResult {
|
||||
val backupString = sourceStream.source().gzip().buffer().use { it.readByteArray() }
|
||||
val backup = ProtoBackupImport.parser.decodeFromByteArray(BackupSerializer, backupString)
|
||||
|
||||
return validate(backup)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user