feat: Add URL and use friendly name for APIContributable

This commit is contained in:
oSumAtrIX
2024-11-01 18:43:39 +01:00
parent f91f3a65c5
commit a5498aba2b
4 changed files with 17 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ import kotlin.io.path.createDirectories
* @property patches The source of the patches.
* @property integrations The source of the integrations.
* @property manager The source of the manager.
* @property contributorsRepositoryNames The names of the repositories to get contributors from.
* @property contributorsRepositoryNames The friendly name of repos mapped to the repository names to get contributors from.
* @property backendServiceName The name of the backend service to use for the repositories, contributors, etc.
* @property apiVersion The version to use for the API.
* @property corsAllowedHosts The hosts allowed to make requests to the API.
@@ -44,7 +44,7 @@ internal class ConfigurationRepository(
val integrations: SignedAssetConfiguration,
val manager: AssetConfiguration,
@SerialName("contributors-repositories")
val contributorsRepositoryNames: Set<String>,
val contributorsRepositoryNames: Map<String, String>,
@SerialName("backend-service-name")
val backendServiceName: String,
@SerialName("api-version")

View File

@@ -35,6 +35,7 @@ class ApiContributor(
@Serializable
class APIContributable(
val name: String,
val url: String,
// Using a list instead of a set because set semantics are unnecessary here.
val contributors: List<ApiContributor>,
)

View File

@@ -3,6 +3,7 @@ package app.revanced.api.configuration.services
import app.revanced.api.configuration.repository.BackendRepository
import app.revanced.api.configuration.repository.ConfigurationRepository
import app.revanced.api.configuration.schema.*
import io.ktor.http.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
@@ -16,11 +17,15 @@ internal class ApiService(
val about = configurationRepository.about
suspend fun contributors() = withContext(Dispatchers.IO) {
configurationRepository.contributorsRepositoryNames.map {
configurationRepository.contributorsRepositoryNames.map { (repository, name) ->
async {
APIContributable(
it,
backendRepository.contributors(configurationRepository.organization, it).map {
name,
URLBuilder().apply {
takeFrom(backendRepository.website)
path(configurationRepository.organization, repository)
}.buildString(),
backendRepository.contributors(configurationRepository.organization, repository).map {
ApiContributor(it.name, it.avatarUrl, it.url, it.contributions)
},
)