mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix more TypeReference issues and cleanup
This commit is contained in:
parent
05071b4205
commit
e020ae5ed5
11 changed files with 38 additions and 49 deletions
|
@ -31,6 +31,7 @@ import mihon.domain.extensionrepo.interactor.GetExtensionRepoCount
|
||||||
import mihon.domain.extensionrepo.interactor.ReplaceExtensionRepo
|
import mihon.domain.extensionrepo.interactor.ReplaceExtensionRepo
|
||||||
import mihon.domain.extensionrepo.interactor.UpdateExtensionRepo
|
import mihon.domain.extensionrepo.interactor.UpdateExtensionRepo
|
||||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
import tachiyomi.data.category.CategoryRepositoryImpl
|
import tachiyomi.data.category.CategoryRepositoryImpl
|
||||||
import tachiyomi.data.chapter.ChapterRepositoryImpl
|
import tachiyomi.data.chapter.ChapterRepositoryImpl
|
||||||
import tachiyomi.data.history.HistoryRepositoryImpl
|
import tachiyomi.data.history.HistoryRepositoryImpl
|
||||||
|
@ -179,6 +180,7 @@ class DomainModule : InjektModule {
|
||||||
addFactory { TrustExtension(get()) }
|
addFactory { TrustExtension(get()) }
|
||||||
|
|
||||||
addSingletonFactory<ExtensionRepoRepository> { ExtensionRepoRepositoryImpl(get()) }
|
addSingletonFactory<ExtensionRepoRepository> { ExtensionRepoRepositoryImpl(get()) }
|
||||||
|
addFactory { ExtensionRepoService(get(), get()) }
|
||||||
addFactory { GetExtensionRepo(get()) }
|
addFactory { GetExtensionRepo(get()) }
|
||||||
addFactory { GetExtensionRepoCount(get()) }
|
addFactory { GetExtensionRepoCount(get()) }
|
||||||
addFactory { CreateExtensionRepo(get(), get()) }
|
addFactory { CreateExtensionRepo(get(), get()) }
|
||||||
|
|
|
@ -48,7 +48,7 @@ object Migrations {
|
||||||
coroutineScope.launchIO {
|
coroutineScope.launchIO {
|
||||||
for ((index, source) in sourcePreferences.extensionRepos().get().withIndex()) {
|
for ((index, source) in sourcePreferences.extensionRepos().get().withIndex()) {
|
||||||
try {
|
try {
|
||||||
extensionRepoRepository.upsertRepository(
|
extensionRepoRepository.upsertRepo(
|
||||||
source,
|
source,
|
||||||
"Repo #${index + 1}",
|
"Repo #${index + 1}",
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -19,11 +19,11 @@ class ExtensionRepoRepositoryImpl(
|
||||||
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 ExtensionRepoRepositoryImpl(
|
||||||
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 ExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ExtensionRepoRepositoryImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.interactor
|
package mihon.domain.extensionrepo.interactor
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
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.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
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 CreateExtensionRepo(
|
class CreateExtensionRepo(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
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 CreateExtensionRepo(
|
||||||
*/
|
*/
|
||||||
@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.interactor
|
||||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
|
|
||||||
class DeleteExtensionRepo(
|
class DeleteExtensionRepo(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(baseUrl: String) {
|
suspend fun await(baseUrl: String) {
|
||||||
extensionRepoRepository.deleteRepository(baseUrl)
|
repository.deleteRepo(baseUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
|
|
||||||
class GetExtensionRepo(
|
class GetExtensionRepo(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
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.interactor
|
||||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
|
|
||||||
class GetExtensionRepoCount(
|
class GetExtensionRepoCount(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
fun subscribe() = extensionRepoRepository.getCount()
|
fun subscribe() = repository.getCount()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||||
|
|
||||||
class ReplaceExtensionRepo(
|
class ReplaceExtensionRepo(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun await(repo: ExtensionRepo) {
|
suspend fun await(repo: ExtensionRepo) {
|
||||||
extensionRepoRepository.replaceRepository(repo)
|
repository.replaceRepo(repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package mihon.domain.extensionrepo.interactor
|
package mihon.domain.extensionrepo.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.repository.ExtensionRepoRepository
|
||||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
import mihon.domain.extensionrepo.service.ExtensionRepoService
|
||||||
|
|
||||||
class UpdateExtensionRepo(
|
class UpdateExtensionRepo(
|
||||||
private val extensionRepoRepository: ExtensionRepoRepository,
|
private val repository: ExtensionRepoRepository,
|
||||||
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 ExtensionRepoRepository {
|
||||||
|
|
||||||
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 ExtensionRepoRepository {
|
||||||
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 ExtensionRepoRepository {
|
||||||
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 ExtensionRepoRepository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun replaceRepository(newRepo: ExtensionRepo)
|
suspend fun replaceRepo(newRepo: ExtensionRepo)
|
||||||
|
|
||||||
suspend fun deleteRepository(baseUrl: String)
|
suspend fun deleteRepo(baseUrl: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,12 @@ import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import tachiyomi.core.common.util.lang.withIOContext
|
import tachiyomi.core.common.util.lang.withIOContext
|
||||||
import tachiyomi.core.common.util.system.logcat
|
import tachiyomi.core.common.util.system.logcat
|
||||||
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