Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ data class Contributor(
data class Repository(
val name: String,
val commits: Int,
)
) {
val repository: String
get() = name.substringAfterLast("/")
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.aliucord.manager.network.services

import com.aliucord.manager.network.models.BuildInfo
import com.aliucord.manager.network.models.GithubRelease
import com.aliucord.manager.di.cacheControl
import com.aliucord.manager.network.models.*
import com.aliucord.manager.network.utils.ApiResponse
import io.ktor.client.request.header
import io.ktor.client.request.url
import io.ktor.http.HttpHeaders
import io.ktor.http.CacheControl

class AliucordGithubService(
private val http: HttpService,
Expand All @@ -18,7 +17,7 @@ class AliucordGithubService(
url(DATA_JSON_URL)

if (force) {
header(HttpHeaders.CacheControl, "no-cache")
cacheControl(CacheControl.NoCache(null))
}
}

Expand All @@ -28,14 +27,24 @@ class AliucordGithubService(
suspend fun getManagerReleases(): ApiResponse<List<GithubRelease>> {
return http.request {
url("https://api.github.com/repos/$ORG/$MANAGER_REPO/releases")
header(HttpHeaders.CacheControl, "public, max-age=60, s-maxage=60")
cacheControl(CacheControl.MaxAge(maxAgeSeconds = 60))
}
}

/**
* Fetches all the contributors with a 24h local cache.
*/
suspend fun getContributors(): ApiResponse<List<Contributor>> = http.request {
url(CONTRIBUTORS_JSON_URL)
cacheControl(CacheControl.MaxAge(maxAgeSeconds = 60 * 60 * 24))
}

companion object {
const val ORG = "Aliucord"
const val MANAGER_REPO = "Manager"

const val DATA_JSON_URL = "https://builds.aliucord.com/data.json"

private const val CONTRIBUTORS_JSON_URL = "https://builds.aliucord.com/contributors.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun ContributorCommitsItem(
)

Text(
text = user.repositories.joinToString { it.name },
text = user.repositories.joinToString { it.repository },
fontStyle = FontStyle.Italic,
style = MaterialTheme.typography.bodySmall
.copy(color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.aliucord.manager.ui.screens.about

import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import com.aliucord.manager.network.models.Contributor
import com.aliucord.manager.network.services.HttpService
import com.aliucord.manager.network.services.AliucordGithubService
import com.aliucord.manager.network.utils.fold
import com.aliucord.manager.ui.util.toUnsafeImmutable
import com.aliucord.manager.util.launchIO
import io.ktor.client.request.url

class AboutModel(
private val http: HttpService,
private val aliucordGithubService: AliucordGithubService,
) : StateScreenModel<AboutScreenState>(AboutScreenState.Loading) {
init {
fetchContributors()
Expand All @@ -19,15 +17,13 @@ class AboutModel(
fun fetchContributors() = screenModelScope.launchIO {
mutableState.value = AboutScreenState.Loading

val response = http.request<List<Contributor>> { url(CONTRIBUTORS_API_URL) }
val response = aliucordGithubService.getContributors()

mutableState.value = response.fold(
success = { AboutScreenState.Loaded(it.toUnsafeImmutable()) },
success = { contributors ->
AboutScreenState.Loaded(contributors.toUnsafeImmutable())
},
Comment thread
Importantamigo marked this conversation as resolved.
fail = { AboutScreenState.Failure },
)
}

companion object {
private const val CONTRIBUTORS_API_URL = "https://api.rushii.dev/aliucord/contributors"
}
}
Loading