mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
consolidate the external backup api
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user