feat(browse): Convert GitHub blob URLs (#1302)

Co-authored-by: jmir1 <jhmiramon@gmail.com>
This commit is contained in:
Secozzi 2024-01-16 13:56:00 +00:00 committed by GitHub
parent 89fa0e15c7
commit 07103687de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -1,11 +1,22 @@
package eu.kanade.domain.extension.anime.interactor package eu.kanade.domain.extension.anime.interactor
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import okhttp3.HttpUrl.Companion.toHttpUrl
import tachiyomi.core.preference.plusAssign import tachiyomi.core.preference.plusAssign
class CreateAnimeExtensionRepo(private val preferences: SourcePreferences) { class CreateAnimeExtensionRepo(private val preferences: SourcePreferences) {
fun await(name: String): Result { fun await(name: String): Result {
if (name.matches(githubRepoRegex)) {
val rawUrl = name.toHttpUrl().newBuilder().apply {
removePathSegment(2) // Remove /blob/
host("raw.githubusercontent.com")
}.build().toString()
preferences.animeExtensionRepos() += rawUrl.removeSuffix("/index.min.json")
return Result.Success
}
// Do not allow invalid formats // Do not allow invalid formats
if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_ANIYOMI_REPO_BASE_URL)) { if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_ANIYOMI_REPO_BASE_URL)) {
return Result.InvalidUrl return Result.InvalidUrl
@ -24,3 +35,4 @@ class CreateAnimeExtensionRepo(private val preferences: SourcePreferences) {
const val OFFICIAL_ANIYOMI_REPO_BASE_URL = "https://raw.githubusercontent.com/aniyomiorg/aniyomi-extensions/repo" const val OFFICIAL_ANIYOMI_REPO_BASE_URL = "https://raw.githubusercontent.com/aniyomiorg/aniyomi-extensions/repo"
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
private val githubRepoRegex = """https://github\.com/[^/]+/[^/]+/blob/(?:[^/]+/)+index\.min\.json$""".toRegex()

View file

@ -1,11 +1,22 @@
package eu.kanade.domain.extension.manga.interactor package eu.kanade.domain.extension.manga.interactor
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import okhttp3.HttpUrl.Companion.toHttpUrl
import tachiyomi.core.preference.plusAssign import tachiyomi.core.preference.plusAssign
class CreateMangaExtensionRepo(private val preferences: SourcePreferences) { class CreateMangaExtensionRepo(private val preferences: SourcePreferences) {
fun await(name: String): Result { fun await(name: String): Result {
if (name.matches(githubRepoRegex)) {
val rawUrl = name.toHttpUrl().newBuilder().apply {
removePathSegment(2) // Remove /blob/
host("raw.githubusercontent.com")
}.build().toString()
preferences.mangaExtensionRepos() += rawUrl.removeSuffix("/index.min.json")
return Result.Success
}
// Do not allow invalid formats // Do not allow invalid formats
if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_TACHIYOMI_REPO_BASE_URL)) { if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_TACHIYOMI_REPO_BASE_URL)) {
return Result.InvalidUrl return Result.InvalidUrl
@ -24,3 +35,4 @@ class CreateMangaExtensionRepo(private val preferences: SourcePreferences) {
const val OFFICIAL_TACHIYOMI_REPO_BASE_URL = "https://raw.githubusercontent.com/tachiyomiorg/extensions/repo" const val OFFICIAL_TACHIYOMI_REPO_BASE_URL = "https://raw.githubusercontent.com/tachiyomiorg/extensions/repo"
private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() private val repoRegex = """^https://.*/index\.min\.json$""".toRegex()
private val githubRepoRegex = """https://github\.com/[^/]+/[^/]+/blob/(?:[^/]+/)+index\.min\.json$""".toRegex()