mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-22 12:48:15 +03:00
Fix more TypeReference issues and cleanup
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
parent
233af962cd
commit
1ea107226c
19 changed files with 74 additions and 92 deletions
|
@ -57,6 +57,7 @@ import mihon.domain.extensionrepo.manga.interactor.GetMangaExtensionRepoCount
|
||||||
import mihon.domain.extensionrepo.manga.interactor.ReplaceMangaExtensionRepo
|
import mihon.domain.extensionrepo.manga.interactor.ReplaceMangaExtensionRepo
|
||||||
import mihon.domain.extensionrepo.manga.interactor.UpdateMangaExtensionRepo
|
import mihon.domain.extensionrepo.manga.interactor.UpdateMangaExtensionRepo
|
||||||
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
||||||
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
import tachiyomi.data.category.anime.AnimeCategoryRepositoryImpl
|
import tachiyomi.data.category.anime.AnimeCategoryRepositoryImpl
|
||||||
import tachiyomi.data.category.manga.MangaCategoryRepositoryImpl
|
import tachiyomi.data.category.manga.MangaCategoryRepositoryImpl
|
||||||
import tachiyomi.data.entries.anime.AnimeRepositoryImpl
|
import tachiyomi.data.entries.anime.AnimeRepositoryImpl
|
||||||
|
@ -343,6 +344,8 @@ class DomainModule : InjektModule {
|
||||||
addFactory { TrustAnimeExtension(get()) }
|
addFactory { TrustAnimeExtension(get()) }
|
||||||
addFactory { TrustMangaExtension(get()) }
|
addFactory { TrustMangaExtension(get()) }
|
||||||
|
|
||||||
|
addFactory { ExtensionRepoService(get(), get()) }
|
||||||
|
|
||||||
addSingletonFactory<AnimeExtensionRepoRepository> { AnimeExtensionRepoRepositoryImpl(get()) }
|
addSingletonFactory<AnimeExtensionRepoRepository> { AnimeExtensionRepoRepositoryImpl(get()) }
|
||||||
addFactory { GetAnimeExtensionRepo(get()) }
|
addFactory { GetAnimeExtensionRepo(get()) }
|
||||||
addFactory { GetAnimeExtensionRepoCount(get()) }
|
addFactory { GetAnimeExtensionRepoCount(get()) }
|
||||||
|
|
|
@ -618,7 +618,7 @@ object Migrations {
|
||||||
coroutineScope.launchIO {
|
coroutineScope.launchIO {
|
||||||
for ((index, source) in sourcePreferences.animeExtensionRepos().get().withIndex()) {
|
for ((index, source) in sourcePreferences.animeExtensionRepos().get().withIndex()) {
|
||||||
try {
|
try {
|
||||||
animeExtensionRepoRepository.upsertRepository(
|
animeExtensionRepoRepository.upsertRepo(
|
||||||
source,
|
source,
|
||||||
"Repo #${index + 1}",
|
"Repo #${index + 1}",
|
||||||
null,
|
null,
|
||||||
|
@ -635,7 +635,7 @@ object Migrations {
|
||||||
|
|
||||||
for ((index, source) in sourcePreferences.mangaExtensionRepos().get().withIndex()) {
|
for ((index, source) in sourcePreferences.mangaExtensionRepos().get().withIndex()) {
|
||||||
try {
|
try {
|
||||||
mangaExtensionRepoRepository.upsertRepository(
|
mangaExtensionRepoRepository.upsertRepo(
|
||||||
source,
|
source,
|
||||||
"Repo #${index + 1}",
|
"Repo #${index + 1}",
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -19,11 +19,11 @@ class AnimeExtensionRepoRepositoryImpl(
|
||||||
return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRepository(baseUrl: String): ExtensionRepo? {
|
override suspend fun getRepo(baseUrl: String): ExtensionRepo? {
|
||||||
return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) }
|
return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? {
|
override suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? {
|
||||||
return handler.awaitOneOrNull {
|
return handler.awaitOneOrNull {
|
||||||
extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo)
|
extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class AnimeExtensionRepoRepositoryImpl(
|
||||||
return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() }
|
return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun insertRepository(
|
override suspend fun insertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -47,7 +47,7 @@ class AnimeExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun upsertRepository(
|
override suspend fun upsertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -61,7 +61,7 @@ class AnimeExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun replaceRepository(newRepo: ExtensionRepo) {
|
override suspend fun replaceRepo(newRepo: ExtensionRepo) {
|
||||||
handler.await {
|
handler.await {
|
||||||
extension_reposQueries.replace(
|
extension_reposQueries.replace(
|
||||||
newRepo.baseUrl,
|
newRepo.baseUrl,
|
||||||
|
@ -73,7 +73,7 @@ class AnimeExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteRepository(baseUrl: String) {
|
override suspend fun deleteRepo(baseUrl: String) {
|
||||||
return handler.await { extension_reposQueries.delete(baseUrl) }
|
return handler.await { extension_reposQueries.delete(baseUrl) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ class MangaExtensionRepoRepositoryImpl(
|
||||||
return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRepository(baseUrl: String): ExtensionRepo? {
|
override suspend fun getRepo(baseUrl: String): ExtensionRepo? {
|
||||||
return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) }
|
return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? {
|
override suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? {
|
||||||
return handler.awaitOneOrNull {
|
return handler.awaitOneOrNull {
|
||||||
extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo)
|
extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo)
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class MangaExtensionRepoRepositoryImpl(
|
||||||
return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() }
|
return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun insertRepository(
|
override suspend fun insertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -47,7 +47,7 @@ class MangaExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun upsertRepository(
|
override suspend fun upsertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -61,7 +61,7 @@ class MangaExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun replaceRepository(newRepo: ExtensionRepo) {
|
override suspend fun replaceRepo(newRepo: ExtensionRepo) {
|
||||||
handler.await {
|
handler.await {
|
||||||
extension_reposQueries.replace(
|
extension_reposQueries.replace(
|
||||||
newRepo.baseUrl,
|
newRepo.baseUrl,
|
||||||
|
@ -73,7 +73,7 @@ class MangaExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteRepository(baseUrl: String) {
|
override suspend fun deleteRepo(baseUrl: String) {
|
||||||
return handler.await { extension_reposQueries.delete(baseUrl) }
|
return handler.await { extension_reposQueries.delete(baseUrl) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,30 @@
|
||||||
package mihon.domain.extensionrepo.anime.interactor
|
package mihon.domain.extensionrepo.anime.interactor
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.exception.SaveExtensionRepoException
|
import mihon.domain.extensionrepo.exception.SaveExtensionRepoException
|
||||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
|
||||||
class CreateAnimeExtensionRepo(
|
class CreateAnimeExtensionRepo(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
private val networkHelper: NetworkHelper,
|
private val service: ExtensionRepoService,
|
||||||
) {
|
) {
|
||||||
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
|
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
|
||||||
|
|
||||||
private val client: OkHttpClient
|
|
||||||
get() = networkHelper.client
|
|
||||||
|
|
||||||
private val extensionRepoService = ExtensionRepoService(client)
|
|
||||||
|
|
||||||
suspend fun await(repoUrl: String): Result {
|
suspend fun await(repoUrl: String): Result {
|
||||||
if (!repoUrl.matches(repoRegex)) {
|
if (!repoUrl.matches(repoRegex)) {
|
||||||
return Result.InvalidUrl
|
return Result.InvalidUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
val baseUrl = repoUrl.removeSuffix("/index.min.json")
|
val baseUrl = repoUrl.removeSuffix("/index.min.json")
|
||||||
return extensionRepoService.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
return service.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun insert(repo: ExtensionRepo): Result {
|
private suspend fun insert(repo: ExtensionRepo): Result {
|
||||||
return try {
|
return try {
|
||||||
extensionRepoRepository.insertRepository(
|
repository.insertRepo(
|
||||||
repo.baseUrl,
|
repo.baseUrl,
|
||||||
repo.name,
|
repo.name,
|
||||||
repo.shortName,
|
repo.shortName,
|
||||||
|
@ -57,12 +50,11 @@ class CreateAnimeExtensionRepo(
|
||||||
*/
|
*/
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount")
|
||||||
private suspend fun handleInsertionError(repo: ExtensionRepo): Result {
|
private suspend fun handleInsertionError(repo: ExtensionRepo): Result {
|
||||||
val repoExists = extensionRepoRepository.getRepository(repo.baseUrl)
|
val repoExists = repository.getRepo(repo.baseUrl)
|
||||||
if (repoExists != null) {
|
if (repoExists != null) {
|
||||||
return Result.RepoAlreadyExists
|
return Result.RepoAlreadyExists
|
||||||
}
|
}
|
||||||
val matchingFingerprintRepo =
|
val matchingFingerprintRepo = repository.getRepoBySigningKeyFingerprint(repo.signingKeyFingerprint)
|
||||||
extensionRepoRepository.getRepositoryBySigningKeyFingerprint(repo.signingKeyFingerprint)
|
|
||||||
if (matchingFingerprintRepo != null) {
|
if (matchingFingerprintRepo != null) {
|
||||||
return Result.DuplicateFingerprint(matchingFingerprintRepo, repo)
|
return Result.DuplicateFingerprint(matchingFingerprintRepo, repo)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.anime.interactor
|
||||||
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
||||||
|
|
||||||
class DeleteAnimeExtensionRepo(
|
class DeleteAnimeExtensionRepo(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(baseUrl: String) {
|
suspend fun await(baseUrl: String) {
|
||||||
extensionRepoRepository.deleteRepository(baseUrl)
|
repository.deleteRepo(baseUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
|
|
||||||
class GetAnimeExtensionRepo(
|
class GetAnimeExtensionRepo(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
fun subscribeAll(): Flow<List<ExtensionRepo>> = extensionRepoRepository.subscribeAll()
|
fun subscribeAll(): Flow<List<ExtensionRepo>> = repository.subscribeAll()
|
||||||
|
|
||||||
suspend fun getAll(): List<ExtensionRepo> = extensionRepoRepository.getAll()
|
suspend fun getAll(): List<ExtensionRepo> = repository.getAll()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package mihon.domain.extensionrepo.anime.interactor
|
||||||
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
||||||
|
|
||||||
class GetAnimeExtensionRepoCount(
|
class GetAnimeExtensionRepoCount(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
fun subscribe() = extensionRepoRepository.getCount()
|
fun subscribe() = repository.getCount()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.anime.repository.AnimeExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
|
|
||||||
class ReplaceAnimeExtensionRepo(
|
class ReplaceAnimeExtensionRepo(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(repo: ExtensionRepo) {
|
suspend fun await(repo: ExtensionRepo) {
|
||||||
extensionRepoRepository.replaceRepository(repo)
|
repository.replaceRepo(repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package mihon.domain.extensionrepo.anime.interactor
|
package mihon.domain.extensionrepo.anime.interactor
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
@ -9,25 +8,23 @@ import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
|
|
||||||
class UpdateAnimeExtensionRepo(
|
class UpdateAnimeExtensionRepo(
|
||||||
private val extensionRepoRepository: AnimeExtensionRepoRepository,
|
private val repository: AnimeExtensionRepoRepository,
|
||||||
networkService: NetworkHelper,
|
private val service: ExtensionRepoService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val extensionRepoService = ExtensionRepoService(networkService.client)
|
|
||||||
|
|
||||||
suspend fun awaitAll() = coroutineScope {
|
suspend fun awaitAll() = coroutineScope {
|
||||||
extensionRepoRepository.getAll()
|
repository.getAll()
|
||||||
.map { async { await(it) } }
|
.map { async { await(it) } }
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun await(repo: ExtensionRepo) {
|
suspend fun await(repo: ExtensionRepo) {
|
||||||
val newRepo = extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return
|
val newRepo = service.fetchRepoDetails(repo.baseUrl) ?: return
|
||||||
if (
|
if (
|
||||||
repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
|
repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
|
||||||
repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
|
repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
|
||||||
) {
|
) {
|
||||||
extensionRepoRepository.upsertRepository(newRepo)
|
repository.upsertRepo(newRepo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ interface AnimeExtensionRepoRepository {
|
||||||
|
|
||||||
suspend fun getAll(): List<ExtensionRepo>
|
suspend fun getAll(): List<ExtensionRepo>
|
||||||
|
|
||||||
suspend fun getRepository(baseUrl: String): ExtensionRepo?
|
suspend fun getRepo(baseUrl: String): ExtensionRepo?
|
||||||
|
|
||||||
suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo?
|
suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo?
|
||||||
|
|
||||||
fun getCount(): Flow<Int>
|
fun getCount(): Flow<Int>
|
||||||
|
|
||||||
suspend fun insertRepository(
|
suspend fun insertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -23,7 +23,7 @@ interface AnimeExtensionRepoRepository {
|
||||||
signingKeyFingerprint: String,
|
signingKeyFingerprint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun upsertRepository(
|
suspend fun upsertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -31,8 +31,8 @@ interface AnimeExtensionRepoRepository {
|
||||||
signingKeyFingerprint: String,
|
signingKeyFingerprint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun upsertRepository(repo: ExtensionRepo) {
|
suspend fun upsertRepo(repo: ExtensionRepo) {
|
||||||
upsertRepository(
|
upsertRepo(
|
||||||
baseUrl = repo.baseUrl,
|
baseUrl = repo.baseUrl,
|
||||||
name = repo.name,
|
name = repo.name,
|
||||||
shortName = repo.shortName,
|
shortName = repo.shortName,
|
||||||
|
@ -41,7 +41,7 @@ interface AnimeExtensionRepoRepository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun replaceRepository(newRepo: ExtensionRepo)
|
suspend fun replaceRepo(newRepo: ExtensionRepo)
|
||||||
|
|
||||||
suspend fun deleteRepository(baseUrl: String)
|
suspend fun deleteRepo(baseUrl: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,28 +10,23 @@ import okhttp3.OkHttpClient
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
|
|
||||||
class CreateMangaExtensionRepo(
|
class CreateMangaExtensionRepo(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
private val networkHelper: NetworkHelper,
|
private val service: ExtensionRepoService,
|
||||||
) {
|
) {
|
||||||
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
|
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
|
||||||
|
|
||||||
private val client: OkHttpClient
|
|
||||||
get() = networkHelper.client
|
|
||||||
|
|
||||||
private val extensionRepoService = ExtensionRepoService(client)
|
|
||||||
|
|
||||||
suspend fun await(repoUrl: String): Result {
|
suspend fun await(repoUrl: String): Result {
|
||||||
if (!repoUrl.matches(repoRegex)) {
|
if (!repoUrl.matches(repoRegex)) {
|
||||||
return Result.InvalidUrl
|
return Result.InvalidUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
val baseUrl = repoUrl.removeSuffix("/index.min.json")
|
val baseUrl = repoUrl.removeSuffix("/index.min.json")
|
||||||
return extensionRepoService.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
return service.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun insert(repo: ExtensionRepo): Result {
|
private suspend fun insert(repo: ExtensionRepo): Result {
|
||||||
return try {
|
return try {
|
||||||
extensionRepoRepository.insertRepository(
|
repository.insertRepo(
|
||||||
repo.baseUrl,
|
repo.baseUrl,
|
||||||
repo.name,
|
repo.name,
|
||||||
repo.shortName,
|
repo.shortName,
|
||||||
|
@ -57,12 +52,11 @@ class CreateMangaExtensionRepo(
|
||||||
*/
|
*/
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount")
|
||||||
private suspend fun handleInsertionError(repo: ExtensionRepo): Result {
|
private suspend fun handleInsertionError(repo: ExtensionRepo): Result {
|
||||||
val repoExists = extensionRepoRepository.getRepository(repo.baseUrl)
|
val repoExists = repository.getRepo(repo.baseUrl)
|
||||||
if (repoExists != null) {
|
if (repoExists != null) {
|
||||||
return Result.RepoAlreadyExists
|
return Result.RepoAlreadyExists
|
||||||
}
|
}
|
||||||
val matchingFingerprintRepo =
|
val matchingFingerprintRepo = repository.getRepoBySigningKeyFingerprint(repo.signingKeyFingerprint)
|
||||||
extensionRepoRepository.getRepositoryBySigningKeyFingerprint(repo.signingKeyFingerprint)
|
|
||||||
if (matchingFingerprintRepo != null) {
|
if (matchingFingerprintRepo != null) {
|
||||||
return Result.DuplicateFingerprint(matchingFingerprintRepo, repo)
|
return Result.DuplicateFingerprint(matchingFingerprintRepo, repo)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.manga.interactor
|
||||||
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
||||||
|
|
||||||
class DeleteMangaExtensionRepo(
|
class DeleteMangaExtensionRepo(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(baseUrl: String) {
|
suspend fun await(baseUrl: String) {
|
||||||
extensionRepoRepository.deleteRepository(baseUrl)
|
repository.deleteRepo(baseUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
|
|
||||||
class GetMangaExtensionRepo(
|
class GetMangaExtensionRepo(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
fun subscribeAll(): Flow<List<ExtensionRepo>> = extensionRepoRepository.subscribeAll()
|
fun subscribeAll(): Flow<List<ExtensionRepo>> = repository.subscribeAll()
|
||||||
|
|
||||||
suspend fun getAll(): List<ExtensionRepo> = extensionRepoRepository.getAll()
|
suspend fun getAll(): List<ExtensionRepo> = repository.getAll()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package mihon.domain.extensionrepo.manga.interactor
|
||||||
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
||||||
|
|
||||||
class GetMangaExtensionRepoCount(
|
class GetMangaExtensionRepoCount(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
fun subscribe() = extensionRepoRepository.getCount()
|
fun subscribe() = repository.getCount()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.manga.repository.MangaExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
|
|
||||||
class ReplaceMangaExtensionRepo(
|
class ReplaceMangaExtensionRepo(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(repo: ExtensionRepo) {
|
suspend fun await(repo: ExtensionRepo) {
|
||||||
extensionRepoRepository.replaceRepository(repo)
|
repository.replaceRepo(repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package mihon.domain.extensionrepo.manga.interactor
|
package mihon.domain.extensionrepo.manga.interactor
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
|
@ -9,25 +8,23 @@ import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
|
|
||||||
class UpdateMangaExtensionRepo(
|
class UpdateMangaExtensionRepo(
|
||||||
private val extensionRepoRepository: MangaExtensionRepoRepository,
|
private val repository: MangaExtensionRepoRepository,
|
||||||
networkService: NetworkHelper,
|
private val service: ExtensionRepoService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val extensionRepoService = ExtensionRepoService(networkService.client)
|
|
||||||
|
|
||||||
suspend fun awaitAll() = coroutineScope {
|
suspend fun awaitAll() = coroutineScope {
|
||||||
extensionRepoRepository.getAll()
|
repository.getAll()
|
||||||
.map { async { await(it) } }
|
.map { async { await(it) } }
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun await(repo: ExtensionRepo) {
|
suspend fun await(repo: ExtensionRepo) {
|
||||||
val newRepo = extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return
|
val newRepo = service.fetchRepoDetails(repo.baseUrl) ?: return
|
||||||
if (
|
if (
|
||||||
repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
|
repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
|
||||||
repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
|
repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
|
||||||
) {
|
) {
|
||||||
extensionRepoRepository.upsertRepository(newRepo)
|
repository.upsertRepo(newRepo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ interface MangaExtensionRepoRepository {
|
||||||
|
|
||||||
suspend fun getAll(): List<ExtensionRepo>
|
suspend fun getAll(): List<ExtensionRepo>
|
||||||
|
|
||||||
suspend fun getRepository(baseUrl: String): ExtensionRepo?
|
suspend fun getRepo(baseUrl: String): ExtensionRepo?
|
||||||
|
|
||||||
suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo?
|
suspend fun getRepoBySigningKeyFingerprint(fingerprint: String): ExtensionRepo?
|
||||||
|
|
||||||
fun getCount(): Flow<Int>
|
fun getCount(): Flow<Int>
|
||||||
|
|
||||||
suspend fun insertRepository(
|
suspend fun insertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -23,7 +23,7 @@ interface MangaExtensionRepoRepository {
|
||||||
signingKeyFingerprint: String,
|
signingKeyFingerprint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun upsertRepository(
|
suspend fun upsertRepo(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
name: String,
|
name: String,
|
||||||
shortName: String?,
|
shortName: String?,
|
||||||
|
@ -31,8 +31,8 @@ interface MangaExtensionRepoRepository {
|
||||||
signingKeyFingerprint: String,
|
signingKeyFingerprint: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun upsertRepository(repo: ExtensionRepo) {
|
suspend fun upsertRepo(repo: ExtensionRepo) {
|
||||||
upsertRepository(
|
upsertRepo(
|
||||||
baseUrl = repo.baseUrl,
|
baseUrl = repo.baseUrl,
|
||||||
name = repo.name,
|
name = repo.name,
|
||||||
shortName = repo.shortName,
|
shortName = repo.shortName,
|
||||||
|
@ -41,7 +41,7 @@ interface MangaExtensionRepoRepository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun replaceRepository(newRepo: ExtensionRepo)
|
suspend fun replaceRepo(newRepo: ExtensionRepo)
|
||||||
|
|
||||||
suspend fun deleteRepository(baseUrl: String)
|
suspend fun deleteRepo(baseUrl: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,9 @@ import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class ExtensionRepoService(
|
class ExtensionRepoService(
|
||||||
private val client: OkHttpClient,
|
private val client: OkHttpClient,
|
||||||
|
private val json: Json,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val json: Json by injectLazy()
|
|
||||||
|
|
||||||
@Suppress("TooGenericExceptionCaught")
|
@Suppress("TooGenericExceptionCaught")
|
||||||
suspend fun fetchRepoDetails(
|
suspend fun fetchRepoDetails(
|
||||||
repo: String,
|
repo: String,
|
||||||
|
|
Loading…
Reference in a new issue