Skip to content

Commit

Permalink
GitLab Links
Browse files Browse the repository at this point in the history
* Add new OkHttpClient for Aurora.
* Try to find apk in GitLab links.
* Fixes #506
  • Loading branch information
rumboalla committed Feb 8, 2024
1 parent 164126b commit 37b5de1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.apkupdater.data.gitlab


data class GitLabAssets(val sources: List<GitLabAsset>)
data class GitLabAssets(
val sources: List<GitLabAsset>,
val links: List<GitLabLink>
)
4 changes: 4 additions & 0 deletions app/src/main/kotlin/com/apkupdater/data/gitlab/GitLabLink.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.apkupdater.data.gitlab


data class GitLabLink(val url: String)
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/apkupdater/di/MainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ val mainModule = module {

single {
val client = OkHttpClient.Builder().followRedirects(true).cache(get()).build()
val auroraClient = OkHttpClient.Builder().followRedirects(true).cache(get()).addUserAgentInterceptor("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36").build()
val apkPureClient = OkHttpClient.Builder().followRedirects(true).cache(get()).addUserAgentInterceptor("APKPure/3.19.39 (Aegon)").build()
val dir = File(androidContext().cacheDir, "downloads").apply { mkdirs() }
Downloader(client, apkPureClient, dir)
Downloader(client, apkPureClient, auroraClient, dir)
}

single { ApkMirrorRepository(get(), get(), androidContext().packageManager) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,11 @@ class GitLabRepository(
): String {
// TODO: Take into account arch
val source = release.assets.sources.find { it.url.endsWith(".apk", true) }
if (source != null) {
return source.url
} else if (packageName == "com.aurora.store") {
// For whatever reason Aurora doesn't store the APK as an asset.
// Instead there is a markdown link to the APK.
Regex("\\[(.+)]\\(([^ ]+?)( \"(.+)\")?\\)").find(release.description)?.let {
return "https://gitlab.com/AuroraOSS/AuroraStore" + it.groups[2]!!.value
}
}
if (source != null) return source.url

val link = release.assets.links.find { it.url.endsWith(".apk", true) }
if (link != null) return link.url

return ""
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/com/apkupdater/util/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.io.InputStream
class Downloader(
private val client: OkHttpClient,
private val apkPureClient: OkHttpClient,
private val auroraClient: OkHttpClient,
private val dir: File
) {

Expand All @@ -26,6 +27,7 @@ class Downloader(
fun downloadStream(url: String): InputStream? = runCatching {
val c = when {
url.contains("apkpure") -> apkPureClient
url.contains("aurora") -> auroraClient
else -> client
}
val response = c.newCall(downloadRequest(url)).execute()
Expand Down

0 comments on commit 37b5de1

Please sign in to comment.