mirror of
https://github.com/recloudstream/gradle.git
synced 2024-08-14 23:56:59 +00:00
start adding support for hosters other than github
This commit is contained in:
parent
1e0b457503
commit
17997e15c0
1 changed files with 41 additions and 14 deletions
|
@ -24,16 +24,44 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) {
|
||||||
apkinfo!!.urlPrefix = url
|
apkinfo!!.urlPrefix = url
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setRepo(user: String, repo: String) {
|
fun setRepo(user: String, repo: String, url: String, rawLinkFormat: String) {
|
||||||
repository = Repo(user, repo)
|
repository = Repo(user, repo, url, rawLinkFormat)
|
||||||
}
|
}
|
||||||
fun setRepo(identifier: String) {
|
fun setRepo(user: String, repo: String, type: String) {
|
||||||
val split = identifier
|
when {
|
||||||
|
type == "github" -> setRepo(user, repo, "https://github.com/${user}/${repo}", "https://raw.githubusercontent.com/${user}/${repo}/%branch%/%filename%")
|
||||||
|
type == "gitlab" -> setRepo(user, repo, "https://gitlab.com/${user}/${repo}", "https://gitlab.com/${user}/${repo}/-/raw/%branch%/%filename%")
|
||||||
|
type.startsWith("gitlab-") -> {
|
||||||
|
val domain = type.removePrefix("gitlab-")
|
||||||
|
setRepo(user, repo, "https://${domain}/${user}/${repo}", "https://${domain}/${user}/${repo}/-/raw/%branch%/%filename%")
|
||||||
|
}
|
||||||
|
type.startsWith("gitea-") -> {
|
||||||
|
val domain = type.removePrefix("gitea-")
|
||||||
|
setRepo(user, repo, "https://${domain}/${user}/${repo}", "https://${domain}/${user}/${repo}/raw/branch/%branch%/%filename%")
|
||||||
|
}
|
||||||
|
else -> throw IllegalArgumentException("Unknown type ${type}. Use github, gitlab, gitlab-<domain> or gitea-<domain> or set repository via setRepo(user, repo, url, rawLinkFormat)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun setRepo(url: String) {
|
||||||
|
when {
|
||||||
|
url.startsWith("https://github.com") -> {
|
||||||
|
val split = url
|
||||||
.removePrefix("https://")
|
.removePrefix("https://")
|
||||||
.removePrefix("github.com")
|
.removePrefix("github.com")
|
||||||
.removeSurrounding("/")
|
.removeSurrounding("/")
|
||||||
.split("/")
|
.split("/")
|
||||||
repository = Repo(split[0], split[1])
|
setRepo(split[0], split[1], "github")
|
||||||
|
}
|
||||||
|
url.startsWith("https://gitlab.com") -> {
|
||||||
|
val split = url
|
||||||
|
.removePrefix("https://")
|
||||||
|
.removePrefix("gitlab.com")
|
||||||
|
.removeSurrounding("/")
|
||||||
|
.split("/")
|
||||||
|
setRepo(split[0], split[1], "gitlab")
|
||||||
|
}
|
||||||
|
else -> throw IllegalArgumentException("Unknown domain, please set repository via setRepo(user, repo, type)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var pluginClassName: String? = null
|
internal var pluginClassName: String? = null
|
||||||
|
@ -55,12 +83,11 @@ class ApkInfo(extension: CloudstreamExtension, release: String) {
|
||||||
val jarFile = cache.resolve("cloudstream.jar")
|
val jarFile = cache.resolve("cloudstream.jar")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Repo(val user: String, val repo: String) {
|
class Repo(val user: String, val repo: String, val url: String, val rawLinkFormat: String) {
|
||||||
val url: String
|
|
||||||
get() = "https://github.com/${user}/${repo}"
|
|
||||||
|
|
||||||
fun getRawLink(filename: String, branch: String): String {
|
fun getRawLink(filename: String, branch: String): String {
|
||||||
return "https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}"
|
return rawLinkFormat
|
||||||
|
.replace("%filename%", filename)
|
||||||
|
.replace("%branch%", branch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue