consolidate the external backup api

This commit is contained in:
Aria Moradi
2021-08-18 23:34:39 +04:30
parent d61816734d
commit e2db191f70
3 changed files with 25 additions and 20 deletions

View File

@@ -4,6 +4,8 @@ import io.javalin.http.Context
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
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.server.JavalinSetup
import java.text.SimpleDateFormat
import java.util.Date
@@ -39,7 +41,7 @@ object BackupController {
ctx.contentType("application/json")
ctx.result(
JavalinSetup.future {
LegacyBackupExport.createLegacyBackup(
LegacyBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = true,
@@ -55,13 +57,12 @@ object BackupController {
/** returns a Tachiyomi legacy backup json created from the current database as a file */
fun legacyExportFile(ctx: Context) {
ctx.contentType("application/json")
val sdf = SimpleDateFormat("yyyy-MM-dd_HH-mm")
val currentDate = sdf.format(Date())
val currentDate = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date())
ctx.header("Content-Disposition", "attachment; filename=\"tachidesk_$currentDate.json\"")
ctx.header("Content-Disposition", """attachment; filename="tachidesk_$currentDate.json"""")
ctx.result(
JavalinSetup.future {
LegacyBackupExport.createLegacyBackup(
LegacyBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = true,
@@ -75,29 +76,29 @@ object BackupController {
}
/** expects a Tachiyomi protobuf backup in the body */
fun protobufImport(ctx: Context) { // TODO
fun protobufImport(ctx: Context) {
ctx.result(
JavalinSetup.future {
LegacyBackupImport.performRestore(ctx.bodyAsInputStream())
ProtoBackupImport.performRestore(ctx.bodyAsInputStream())
}
)
}
/** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto" */
fun protobufImportFile(ctx: Context) { // TODO
/** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto.gz" */
fun protobufImportFile(ctx: Context) {
ctx.result(
JavalinSetup.future {
LegacyBackupImport.performRestore(ctx.uploadedFile("backup.json")!!.content)
ProtoBackupImport.performRestore(ctx.uploadedFile("backup.proto.gz")!!.content)
}
)
}
/** returns a Tachiyomi protobuf backup created from the current database as a body */
fun protobufExport(ctx: Context) { // TODO
ctx.contentType("application/json")
ctx.contentType("application/octet-stream")
ctx.result(
JavalinSetup.future {
LegacyBackupExport.createLegacyBackup(
ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = true,
@@ -110,16 +111,15 @@ object BackupController {
)
}
/** returns a Tachiyomi legacy backup json created from the current database as a file */
/** returns a Tachiyomi protobuf backup created from the current database as a file */
fun protobufExportFile(ctx: Context) {
ctx.contentType("application/json")
val sdf = SimpleDateFormat("yyyy-MM-dd_HH-mm")
val currentDate = sdf.format(Date())
ctx.contentType("application/octet-stream")
val currentDate = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date())
ctx.header("Content-Disposition", "attachment; filename=\"tachidesk_$currentDate.json\"")
ctx.header("Content-Disposition", """attachment; filename="tachidesk_$currentDate.proto.gz"""")
ctx.result(
JavalinSetup.future {
LegacyBackupExport.createLegacyBackup(
ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = true,

View File

@@ -29,7 +29,7 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
object LegacyBackupExport : LegacyBackupBase() {
suspend fun createLegacyBackup(flags: BackupFlags): String? {
suspend fun createBackup(flags: BackupFlags): ByteArray {
// Create root object
val root = JsonObject()
@@ -77,7 +77,7 @@ object LegacyBackupExport : LegacyBackupBase() {
backupExtensionInfo(extensionEntries, extensions)
}
return parser.toJson(root)
return parser.toJson(root).encodeToByteArray()
}
private fun backupMangaObject(manga: Manga, options: BackupFlags): JsonElement {

View File

@@ -1,5 +1,7 @@
package suwayomi.tachidesk.manga.impl.backup.proto
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
/*
* Copyright (C) Contributors to the Suwayomi project
*
@@ -8,4 +10,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
object ProtoBackupExport {
suspend fun createBackup(flags: BackupFlags): String? {
TODO()
}
}