Skip to content

Commit 37b5de1

Browse files
committed
GitLab Links
* Add new OkHttpClient for Aurora. * Try to find apk in GitLab links. * Fixes #506
1 parent 164126b commit 37b5de1

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.apkupdater.data.gitlab
22

33

4-
data class GitLabAssets(val sources: List<GitLabAsset>)
4+
data class GitLabAssets(
5+
val sources: List<GitLabAsset>,
6+
val links: List<GitLabLink>
7+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.apkupdater.data.gitlab
2+
3+
4+
data class GitLabLink(val url: String)

app/src/main/kotlin/com/apkupdater/di/MainModule.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ val mainModule = module {
127127

128128
single {
129129
val client = OkHttpClient.Builder().followRedirects(true).cache(get()).build()
130+
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()
130131
val apkPureClient = OkHttpClient.Builder().followRedirects(true).cache(get()).addUserAgentInterceptor("APKPure/3.19.39 (Aegon)").build()
131132
val dir = File(androidContext().cacheDir, "downloads").apply { mkdirs() }
132-
Downloader(client, apkPureClient, dir)
133+
Downloader(client, apkPureClient, auroraClient, dir)
133134
}
134135

135136
single { ApkMirrorRepository(get(), get(), androidContext().packageManager) }

app/src/main/kotlin/com/apkupdater/repository/GitLabRepository.kt

+5-9
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,11 @@ class GitLabRepository(
100100
): String {
101101
// TODO: Take into account arch
102102
val source = release.assets.sources.find { it.url.endsWith(".apk", true) }
103-
if (source != null) {
104-
return source.url
105-
} else if (packageName == "com.aurora.store") {
106-
// For whatever reason Aurora doesn't store the APK as an asset.
107-
// Instead there is a markdown link to the APK.
108-
Regex("\\[(.+)]\\(([^ ]+?)( \"(.+)\")?\\)").find(release.description)?.let {
109-
return "https://gitlab.com/AuroraOSS/AuroraStore" + it.groups[2]!!.value
110-
}
111-
}
103+
if (source != null) return source.url
104+
105+
val link = release.assets.links.find { it.url.endsWith(".apk", true) }
106+
if (link != null) return link.url
107+
112108
return ""
113109
}
114110

app/src/main/kotlin/com/apkupdater/util/Downloader.kt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.io.InputStream
1010
class Downloader(
1111
private val client: OkHttpClient,
1212
private val apkPureClient: OkHttpClient,
13+
private val auroraClient: OkHttpClient,
1314
private val dir: File
1415
) {
1516

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

0 commit comments

Comments
 (0)