From f3856f051b5771b3fc7d586b48e1e4bd08f8beb9 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Tue, 17 Aug 2021 20:09:31 +0430 Subject: [PATCH] protobuf backup endpoints --- .../suwayomi/tachidesk/manga/MangaAPI.kt | 6 ++ .../manga/controller/BackupController.kt | 58 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt index 5315550f..7338759f 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/MangaAPI.kt @@ -92,6 +92,12 @@ object MangaAPI { get("legacy/export", BackupController::legacyExport) get("legacy/export/file", BackupController::legacyExportFile) + + post("protobuf/import", BackupController::protobufImport) + post("protobuf/import/file", BackupController::protobufImportFile) + + get("protobuf/export", BackupController::protobufExport) + get("protobuf/export/file", BackupController::protobufExportFile) } path("downloads") { diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/BackupController.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/BackupController.kt index 84d1dde8..a50c255c 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/BackupController.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/controller/BackupController.kt @@ -73,4 +73,62 @@ object BackupController { } ) } + + /** expects a Tachiyomi protobuf backup in the body */ + fun protobufImport(ctx: Context) { // TODO + ctx.result( + JavalinSetup.future { + LegacyBackupImport.restoreLegacyBackup(ctx.bodyAsInputStream()) + } + ) + } + + /** expects a Tachiyomi protobuf backup as a file upload, the file must be named "backup.proto" */ + fun protobufImportFile(ctx: Context) { // TODO + ctx.result( + JavalinSetup.future { + LegacyBackupImport.restoreLegacyBackup(ctx.uploadedFile("backup.json")!!.content) + } + ) + } + + /** returns a Tachiyomi protobuf backup created from the current database as a body */ + fun protobufExport(ctx: Context) { // TODO + ctx.contentType("application/json") + ctx.result( + JavalinSetup.future { + LegacyBackupExport.createLegacyBackup( + BackupFlags( + includeManga = true, + includeCategories = true, + includeChapters = true, + includeTracking = true, + includeHistory = true, + ) + ) + } + ) + } + + /** returns a Tachiyomi legacy backup json 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.header("Content-Disposition", "attachment; filename=\"tachidesk_$currentDate.json\"") + ctx.result( + JavalinSetup.future { + LegacyBackupExport.createLegacyBackup( + BackupFlags( + includeManga = true, + includeCategories = true, + includeChapters = true, + includeTracking = true, + includeHistory = true, + ) + ) + } + ) + } }