protobuf backup endpoints

This commit is contained in:
Aria Moradi
2021-08-17 20:09:31 +04:30
parent d3a6662c60
commit f3856f051b
2 changed files with 64 additions and 0 deletions
@@ -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") {
@@ -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,
)
)
}
)
}
}