From 22d8aad598bea8f00f2831779e45a6645392ca0f Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:50:22 +0600 Subject: [PATCH] Auto format extension repo URLs Closes #1392 Closes #1393 --- CHANGELOG.md | 1 + .../extensionrepo/interactor/CreateExtensionRepo.kt | 12 +++++++----- .../extensionrepo/service/ExtensionRepoService.kt | 5 +---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71dc2b032..cf41c076e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Improved - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) +- Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) ## [v0.17.0] - 2024-10-26 ### Added diff --git a/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt b/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt index c44006970..02623d8af 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/interactor/CreateExtensionRepo.kt @@ -5,6 +5,7 @@ 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.HttpUrl.Companion.toHttpUrlOrNull import tachiyomi.core.common.util.system.logcat class CreateExtensionRepo( @@ -13,12 +14,13 @@ class CreateExtensionRepo( ) { private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() - suspend fun await(repoUrl: String): Result { - if (!repoUrl.matches(repoRegex)) { - return Result.InvalidUrl - } + suspend fun await(indexUrl: String): Result { + val formattedIndexUrl = indexUrl.toHttpUrlOrNull() + ?.toString() + ?.takeIf { it.matches(repoRegex) } + ?: return Result.InvalidUrl - val baseUrl = repoUrl.removeSuffix("/index.min.json") + val baseUrl = formattedIndexUrl.removeSuffix("/index.min.json") return service.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl } diff --git a/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt b/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt index 27e00f3a2..2d86b89d1 100644 --- a/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt +++ b/domain/src/main/java/mihon/domain/extensionrepo/service/ExtensionRepoService.kt @@ -1,6 +1,5 @@ package mihon.domain.extensionrepo.service -import androidx.core.net.toUri import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.awaitSuccess @@ -21,11 +20,9 @@ class ExtensionRepoService( repo: String, ): ExtensionRepo? { return withIOContext { - val url = "$repo/repo.json".toUri() - try { with(json) { - client.newCall(GET(url.toString())) + client.newCall(GET("$repo/repo.json")) .awaitSuccess() .parseAs() .toExtensionRepo(baseUrl = repo)