Skip to content

Commit

Permalink
include list of mangas missing source in restore report (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaMoradi authored Oct 19, 2022
1 parent f305ac6 commit d029e65
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package suwayomi.tachidesk.manga.controller

import io.javalin.http.HttpCode
import suwayomi.tachidesk.manga.impl.backup.AbstractBackupValidator
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupExport
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
Expand Down Expand Up @@ -144,7 +143,7 @@ object BackupController {
)
},
withResults = {
json<AbstractBackupValidator.ValidationResult>(HttpCode.OK)
json<ProtoBackupValidator.ValidationResult>(HttpCode.OK)
}
)

Expand All @@ -168,7 +167,7 @@ object BackupController {
)
},
withResults = {
json<AbstractBackupValidator.ValidationResult>(HttpCode.OK)
json<ProtoBackupValidator.ValidationResult>(HttpCode.OK)
}
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.update
import suwayomi.tachidesk.manga.impl.Category
import suwayomi.tachidesk.manga.impl.CategoryManga
import suwayomi.tachidesk.manga.impl.backup.AbstractBackupValidator.ValidationResult
import suwayomi.tachidesk.manga.impl.backup.models.Chapter
import suwayomi.tachidesk.manga.impl.backup.models.Manga
import suwayomi.tachidesk.manga.impl.backup.models.Track
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.BackupCategory
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupHistory
Expand Down Expand Up @@ -77,6 +77,8 @@ object ProtoBackupImport : ProtoBackupBase() {
Restore Summary:
- Missing Sources:
${validationResult.missingSources.joinToString("\n ")}
- Titles missing Sources:
${validationResult.mangasMissingSources.joinToString("\n ")}
- Missing Trackers:
${validationResult.missingTrackers.joinToString("\n ")}
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ import okio.gzip
import okio.source
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import suwayomi.tachidesk.manga.impl.backup.AbstractBackupValidator
import suwayomi.tachidesk.manga.impl.backup.proto.models.Backup
import suwayomi.tachidesk.manga.impl.backup.proto.models.BackupSerializer
import suwayomi.tachidesk.manga.model.table.SourceTable
import java.io.InputStream

object ProtoBackupValidator : AbstractBackupValidator() {
object ProtoBackupValidator {
data class ValidationResult(
val missingSources: List<String>,
val missingTrackers: List<String>,
val mangasMissingSources: List<String>
)

fun validate(backup: Backup): ValidationResult {
if (backup.backupManga.isEmpty()) {
throw Exception("Backup does not contain any manga.")
Expand All @@ -33,6 +38,12 @@ object ProtoBackupValidator : AbstractBackupValidator() {
.sorted()
}

val brokenSourceIds = backup.brokenBackupSources.map { it.sourceId }

val mangasMissingSources = backup.backupManga
.filter { it.source in brokenSourceIds }
.map { manga -> "${manga.title} (from ${backup.brokenBackupSources.first { it.sourceId == manga.source }.name})" }

// val trackers = backup.backupManga
// .flatMap { it.tracking }
// .map { it.syncId }
Expand All @@ -45,7 +56,7 @@ object ProtoBackupValidator : AbstractBackupValidator() {
// .map { context.getString(it.nameRes()) }
// .sorted()

return ValidationResult(missingSources, missingTrackers)
return ValidationResult(missingSources, missingTrackers, mangasMissingSources)
}

suspend fun validate(sourceStream: InputStream): ValidationResult {
Expand Down

0 comments on commit d029e65

Please sign in to comment.