Skip to content

Commit

Permalink
Use Backup.serializer() (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 authored Sep 17, 2024
1 parent 841cdc4 commit 654a3cc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import mu.KotlinLogging
import okio.Buffer
import okio.Sink
import okio.buffer
import okio.gzip
import okio.sink
import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.select
Expand All @@ -33,7 +34,6 @@ import suwayomi.tachidesk.manga.impl.backup.proto.models.Backup
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupCategory
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupChapter
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupManga
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSerializer
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSource
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupTracking
import suwayomi.tachidesk.manga.impl.track.Track
Expand All @@ -48,7 +48,6 @@ import suwayomi.tachidesk.server.serverConfig
import suwayomi.tachidesk.util.HAScheduler
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.InputStream
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -189,16 +188,15 @@ object ProtoBackupExport : ProtoBackupBase() {
)
}

val byteArray = parser.encodeToByteArray(BackupSerializer, backup)
val byteArray = parser.encodeToByteArray(Backup.serializer(), backup)

val byteStream = ByteArrayOutputStream()
byteStream
.sink()
val byteStream = Buffer()
(byteStream as Sink)
.gzip()
.buffer()
.use { it.write(byteArray) }

return byteStream.toByteArray().inputStream()
return byteStream.inputStream()
}

private fun backupManga(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import suwayomi.tachidesk.manga.impl.backup.models.Chapter
import suwayomi.tachidesk.manga.impl.backup.models.Manga
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator.ValidationResult
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator.validate
import suwayomi.tachidesk.manga.impl.backup.proto.models.Backup
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupCategory
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupHistory
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupManga
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSerializer
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupTracking
import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager
import suwayomi.tachidesk.manga.impl.track.tracker.model.toTrack
Expand Down Expand Up @@ -166,7 +166,7 @@ object ProtoBackupImport : ProtoBackupBase() {
.gzip()
.buffer()
.use { it.readByteArray() }
val backup = parser.decodeFromByteArray(BackupSerializer, backupString)
val backup = parser.decodeFromByteArray(Backup.serializer(), backupString)

val validationResult = validate(backup)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import okio.source
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.manga.impl.backup.proto.models.Backup
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSerializer
import suwayomi.tachidesk.manga.impl.track.tracker.TrackerManager
import suwayomi.tachidesk.manga.model.table.SourceTable
import java.io.InputStream
Expand Down Expand Up @@ -70,7 +69,7 @@ object ProtoBackupValidator {
.gzip()
.buffer()
.use { it.readByteArray() }
val backup = ProtoBackupImport.parser.decodeFromByteArray(BackupSerializer, backupString)
val backup = ProtoBackupImport.parser.decodeFromByteArray(Backup.serializer(), backupString)

return validate(backup)
}
Expand Down

This file was deleted.

0 comments on commit 654a3cc

Please sign in to comment.