Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include list of mangas missing source in restore report #421

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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