-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Backup and Restore of Extension Repos (#1057)
* Backup/Restore Extension Repos * Refactor * Moving to Under App Settings * Sort by URL, Check existing by SHA and Error Logging Untested. Currently in a lecture and can't test if the changes really work. * Changes to logic * Don't ask me what's happening here * Renaming Variables * Fixing restoreAmount & changes to logic Co-Authored-By: AntsyLich <[email protected]> --------- Co-authored-by: AntsyLich <[email protected]>
- Loading branch information
1 parent
2858ef8
commit 3126308
Showing
9 changed files
with
150 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...c/main/java/eu/kanade/tachiyomi/data/backup/create/creators/ExtensionRepoBackupCreator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package eu.kanade.tachiyomi.data.backup.create.creators | ||
|
||
import eu.kanade.tachiyomi.data.backup.models.BackupExtensionRepos | ||
import eu.kanade.tachiyomi.data.backup.models.backupExtensionReposMapper | ||
import mihon.domain.extensionrepo.interactor.GetExtensionRepo | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
|
||
class ExtensionRepoBackupCreator( | ||
private val getExtensionRepos: GetExtensionRepo = Injekt.get(), | ||
) { | ||
|
||
suspend operator fun invoke(): List<BackupExtensionRepos> { | ||
return getExtensionRepos.getAll() | ||
.map(backupExtensionReposMapper) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/eu/kanade/tachiyomi/data/backup/models/BackupExtensionRepos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package eu.kanade.tachiyomi.data.backup.models | ||
|
||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.protobuf.ProtoNumber | ||
import mihon.domain.extensionrepo.model.ExtensionRepo | ||
|
||
@Suppress("MagicNumber") | ||
@Serializable | ||
class BackupExtensionRepos( | ||
@ProtoNumber(1) var baseUrl: String, | ||
@ProtoNumber(2) var name: String, | ||
@ProtoNumber(3) var shortName: String?, | ||
@ProtoNumber(4) var website: String, | ||
@ProtoNumber(5) var signingKeyFingerprint: String, | ||
) | ||
|
||
val backupExtensionReposMapper = { repo: ExtensionRepo -> | ||
BackupExtensionRepos( | ||
baseUrl = repo.baseUrl, | ||
name = repo.name, | ||
shortName = repo.shortName, | ||
website = repo.website, | ||
signingKeyFingerprint = repo.signingKeyFingerprint, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/eu/kanade/tachiyomi/data/backup/restore/restorers/ExtensionRepoRestorer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package eu.kanade.tachiyomi.data.backup.restore.restorers | ||
|
||
import eu.kanade.tachiyomi.data.backup.models.BackupExtensionRepos | ||
import mihon.domain.extensionrepo.interactor.GetExtensionRepo | ||
import tachiyomi.data.DatabaseHandler | ||
import uy.kohesive.injekt.Injekt | ||
import uy.kohesive.injekt.api.get | ||
|
||
class ExtensionRepoRestorer( | ||
private val handler: DatabaseHandler = Injekt.get(), | ||
private val getExtensionRepos: GetExtensionRepo = Injekt.get() | ||
) { | ||
|
||
suspend operator fun invoke( | ||
backupRepo: BackupExtensionRepos, | ||
) { | ||
val dbRepos = getExtensionRepos.getAll() | ||
val existingReposBySHA = dbRepos.associateBy { it.signingKeyFingerprint } | ||
val existingReposByUrl = dbRepos.associateBy { it.baseUrl } | ||
|
||
val urlExists = existingReposByUrl[backupRepo.baseUrl] | ||
val shaExists = existingReposBySHA[backupRepo.signingKeyFingerprint] | ||
|
||
if (urlExists != null && urlExists.signingKeyFingerprint != backupRepo.signingKeyFingerprint) { | ||
error("Already Exists with different signing key fingerprint") | ||
} else if (shaExists != null) { | ||
error("${shaExists.name} has the same signing key fingerprint") | ||
} else { | ||
handler.await { | ||
extension_reposQueries.insert( | ||
backupRepo.baseUrl, | ||
backupRepo.name, | ||
backupRepo.shortName, | ||
backupRepo.website, | ||
backupRepo.signingKeyFingerprint | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters