From 07103687ded9c0c82445c349e9a2580621a4eebe Mon Sep 17 00:00:00 2001 From: Secozzi <49240133+Secozzi@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:56:00 +0000 Subject: [PATCH] feat(browse): Convert GitHub blob URLs (#1302) Co-authored-by: jmir1 --- .../anime/interactor/CreateAniyomiExtensionRepo.kt | 12 ++++++++++++ .../manga/interactor/CreateMangaExtensionRepo.kt | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/src/main/java/eu/kanade/domain/extension/anime/interactor/CreateAniyomiExtensionRepo.kt b/app/src/main/java/eu/kanade/domain/extension/anime/interactor/CreateAniyomiExtensionRepo.kt index 02d2c7663..972d89156 100644 --- a/app/src/main/java/eu/kanade/domain/extension/anime/interactor/CreateAniyomiExtensionRepo.kt +++ b/app/src/main/java/eu/kanade/domain/extension/anime/interactor/CreateAniyomiExtensionRepo.kt @@ -1,11 +1,22 @@ package eu.kanade.domain.extension.anime.interactor import eu.kanade.domain.source.service.SourcePreferences +import okhttp3.HttpUrl.Companion.toHttpUrl import tachiyomi.core.preference.plusAssign class CreateAnimeExtensionRepo(private val preferences: SourcePreferences) { 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 if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_ANIYOMI_REPO_BASE_URL)) { 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" private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() +private val githubRepoRegex = """https://github\.com/[^/]+/[^/]+/blob/(?:[^/]+/)+index\.min\.json$""".toRegex() diff --git a/app/src/main/java/eu/kanade/domain/extension/manga/interactor/CreateMangaExtensionRepo.kt b/app/src/main/java/eu/kanade/domain/extension/manga/interactor/CreateMangaExtensionRepo.kt index 184c2d86c..6b069c7dc 100644 --- a/app/src/main/java/eu/kanade/domain/extension/manga/interactor/CreateMangaExtensionRepo.kt +++ b/app/src/main/java/eu/kanade/domain/extension/manga/interactor/CreateMangaExtensionRepo.kt @@ -1,11 +1,22 @@ package eu.kanade.domain.extension.manga.interactor import eu.kanade.domain.source.service.SourcePreferences +import okhttp3.HttpUrl.Companion.toHttpUrl import tachiyomi.core.preference.plusAssign class CreateMangaExtensionRepo(private val preferences: SourcePreferences) { 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 if (!name.matches(repoRegex) || name.startsWith(OFFICIAL_TACHIYOMI_REPO_BASE_URL)) { 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" private val repoRegex = """^https://.*/index\.min\.json$""".toRegex() +private val githubRepoRegex = """https://github\.com/[^/]+/[^/]+/blob/(?:[^/]+/)+index\.min\.json$""".toRegex()