mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-03 23:58:55 +01:00 
			
		
		
		
	Fix more TypeReference issues and cleanup
This commit is contained in:
		@@ -1,37 +1,30 @@
 | 
			
		||||
package mihon.domain.extensionrepo.interactor
 | 
			
		||||
 | 
			
		||||
import eu.kanade.tachiyomi.network.NetworkHelper
 | 
			
		||||
import logcat.LogPriority
 | 
			
		||||
import mihon.domain.extensionrepo.exception.SaveExtensionRepoException
 | 
			
		||||
import mihon.domain.extensionrepo.model.ExtensionRepo
 | 
			
		||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
 | 
			
		||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
 | 
			
		||||
import okhttp3.OkHttpClient
 | 
			
		||||
import tachiyomi.core.common.util.system.logcat
 | 
			
		||||
 | 
			
		||||
class CreateExtensionRepo(
 | 
			
		||||
    private val extensionRepoRepository: ExtensionRepoRepository,
 | 
			
		||||
    private val networkHelper: NetworkHelper,
 | 
			
		||||
    private val repository: ExtensionRepoRepository,
 | 
			
		||||
    private val service: ExtensionRepoService,
 | 
			
		||||
) {
 | 
			
		||||
    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 {
 | 
			
		||||
        if (!repoUrl.matches(repoRegex)) {
 | 
			
		||||
            return Result.InvalidUrl
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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 {
 | 
			
		||||
        return try {
 | 
			
		||||
            extensionRepoRepository.insertRepository(
 | 
			
		||||
            repository.insertRepo(
 | 
			
		||||
                repo.baseUrl,
 | 
			
		||||
                repo.name,
 | 
			
		||||
                repo.shortName,
 | 
			
		||||
@@ -57,12 +50,11 @@ class CreateExtensionRepo(
 | 
			
		||||
     */
 | 
			
		||||
    @Suppress("ReturnCount")
 | 
			
		||||
    private suspend fun handleInsertionError(repo: ExtensionRepo): Result {
 | 
			
		||||
        val repoExists = extensionRepoRepository.getRepository(repo.baseUrl)
 | 
			
		||||
        val repoExists = repository.getRepo(repo.baseUrl)
 | 
			
		||||
        if (repoExists != null) {
 | 
			
		||||
            return Result.RepoAlreadyExists
 | 
			
		||||
        }
 | 
			
		||||
        val matchingFingerprintRepo =
 | 
			
		||||
            extensionRepoRepository.getRepositoryBySigningKeyFingerprint(repo.signingKeyFingerprint)
 | 
			
		||||
        val matchingFingerprintRepo = repository.getRepoBySigningKeyFingerprint(repo.signingKeyFingerprint)
 | 
			
		||||
        if (matchingFingerprintRepo != null) {
 | 
			
		||||
            return Result.DuplicateFingerprint(matchingFingerprintRepo, repo)
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,9 @@ package mihon.domain.extensionrepo.interactor
 | 
			
		||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
 | 
			
		||||
 | 
			
		||||
class DeleteExtensionRepo(
 | 
			
		||||
    private val extensionRepoRepository: ExtensionRepoRepository,
 | 
			
		||||
    private val repository: ExtensionRepoRepository,
 | 
			
		||||
) {
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
class ReplaceExtensionRepo(
 | 
			
		||||
    private val extensionRepoRepository: ExtensionRepoRepository,
 | 
			
		||||
    private val repository: ExtensionRepoRepository,
 | 
			
		||||
) {
 | 
			
		||||
    suspend fun await(repo: ExtensionRepo) {
 | 
			
		||||
        extensionRepoRepository.replaceRepository(repo)
 | 
			
		||||
        repository.replaceRepo(repo)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
package mihon.domain.extensionrepo.interactor
 | 
			
		||||
 | 
			
		||||
import eu.kanade.tachiyomi.network.NetworkHelper
 | 
			
		||||
import kotlinx.coroutines.async
 | 
			
		||||
import kotlinx.coroutines.awaitAll
 | 
			
		||||
import kotlinx.coroutines.coroutineScope
 | 
			
		||||
@@ -9,25 +8,23 @@ import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
 | 
			
		||||
import mihon.domain.extensionrepo.service.ExtensionRepoService
 | 
			
		||||
 | 
			
		||||
class UpdateExtensionRepo(
 | 
			
		||||
    private val extensionRepoRepository: ExtensionRepoRepository,
 | 
			
		||||
    networkService: NetworkHelper,
 | 
			
		||||
    private val repository: ExtensionRepoRepository,
 | 
			
		||||
    private val service: ExtensionRepoService,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    private val extensionRepoService = ExtensionRepoService(networkService.client)
 | 
			
		||||
 | 
			
		||||
    suspend fun awaitAll() = coroutineScope {
 | 
			
		||||
        extensionRepoRepository.getAll()
 | 
			
		||||
        repository.getAll()
 | 
			
		||||
            .map { async { await(it) } }
 | 
			
		||||
            .awaitAll()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    suspend fun await(repo: ExtensionRepo) {
 | 
			
		||||
        val newRepo = extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return
 | 
			
		||||
        val newRepo = service.fetchRepoDetails(repo.baseUrl) ?: return
 | 
			
		||||
        if (
 | 
			
		||||
            repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
 | 
			
		||||
            repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
 | 
			
		||||
        ) {
 | 
			
		||||
            extensionRepoRepository.upsertRepository(newRepo)
 | 
			
		||||
            repository.upsertRepo(newRepo)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,13 +9,13 @@ interface ExtensionRepoRepository {
 | 
			
		||||
 | 
			
		||||
    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>
 | 
			
		||||
 | 
			
		||||
    suspend fun insertRepository(
 | 
			
		||||
    suspend fun insertRepo(
 | 
			
		||||
        baseUrl: String,
 | 
			
		||||
        name: String,
 | 
			
		||||
        shortName: String?,
 | 
			
		||||
@@ -23,7 +23,7 @@ interface ExtensionRepoRepository {
 | 
			
		||||
        signingKeyFingerprint: String,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    suspend fun upsertRepository(
 | 
			
		||||
    suspend fun upsertRepo(
 | 
			
		||||
        baseUrl: String,
 | 
			
		||||
        name: String,
 | 
			
		||||
        shortName: String?,
 | 
			
		||||
@@ -31,8 +31,8 @@ interface ExtensionRepoRepository {
 | 
			
		||||
        signingKeyFingerprint: String,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    suspend fun upsertRepository(repo: ExtensionRepo) {
 | 
			
		||||
        upsertRepository(
 | 
			
		||||
    suspend fun upsertRepo(repo: ExtensionRepo) {
 | 
			
		||||
        upsertRepo(
 | 
			
		||||
            baseUrl = repo.baseUrl,
 | 
			
		||||
            name = repo.name,
 | 
			
		||||
            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 tachiyomi.core.common.util.lang.withIOContext
 | 
			
		||||
import tachiyomi.core.common.util.system.logcat
 | 
			
		||||
import uy.kohesive.injekt.injectLazy
 | 
			
		||||
 | 
			
		||||
class ExtensionRepoService(
 | 
			
		||||
    private val client: OkHttpClient,
 | 
			
		||||
    private val json: Json,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
    private val json: Json by injectLazy()
 | 
			
		||||
 | 
			
		||||
    @Suppress("TooGenericExceptionCaught")
 | 
			
		||||
    suspend fun fetchRepoDetails(
 | 
			
		||||
        repo: String,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user