-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/app/revanced/api/configuration/routes/ManagerRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package app.revanced.api.configuration.routes | ||
|
||
import app.revanced.api.configuration.installNotarizedRoute | ||
import app.revanced.api.configuration.schema.APIManagerAsset | ||
import app.revanced.api.configuration.schema.APIRelease | ||
import app.revanced.api.configuration.schema.APIReleaseVersion | ||
import app.revanced.api.configuration.services.ManagerService | ||
import io.bkbn.kompendium.core.metadata.GetInfo | ||
import io.ktor.http.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.plugins.ratelimit.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import org.koin.ktor.ext.get as koinGet | ||
|
||
internal fun Route.managerRoute() = route("manager") { | ||
val managerService = koinGet<ManagerService>() | ||
|
||
route("latest") { | ||
installLatestManagerRouteDocumentation() | ||
|
||
rateLimit(RateLimitName("weak")) { | ||
get { | ||
call.respond(managerService.latestRelease()) | ||
} | ||
|
||
route("version") { | ||
installLatestManagerVersionRouteDocumentation() | ||
|
||
get { | ||
call.respond(managerService.latestVersion()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Route.installLatestManagerRouteDocumentation() = installNotarizedRoute { | ||
tags = setOf("Manager") | ||
|
||
get = GetInfo.builder { | ||
description("Get the latest manager release") | ||
summary("Get latest Manager release") | ||
response { | ||
description("The latest manager release") | ||
mediaTypes("application/json") | ||
responseCode(HttpStatusCode.OK) | ||
responseType<APIRelease<APIManagerAsset>>() | ||
} | ||
} | ||
} | ||
|
||
private fun Route.installLatestManagerVersionRouteDocumentation() = installNotarizedRoute { | ||
tags = setOf("Manager") | ||
|
||
get = GetInfo.builder { | ||
description("Get the latest manager release version") | ||
summary("Get latest manager release version") | ||
response { | ||
description("The latest manager release version") | ||
mediaTypes("application/json") | ||
responseCode(HttpStatusCode.OK) | ||
responseType<APIReleaseVersion>() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/app/revanced/api/configuration/services/ManagerService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.revanced.api.configuration.services | ||
|
||
import app.revanced.api.configuration.repository.BackendRepository | ||
import app.revanced.api.configuration.repository.BackendRepository.BackendOrganization.BackendRepository.BackendRelease.Companion.first | ||
import app.revanced.api.configuration.repository.ConfigurationRepository | ||
import app.revanced.api.configuration.schema.* | ||
|
||
internal class ManagerService( | ||
private val backendRepository: BackendRepository, | ||
private val configurationRepository: ConfigurationRepository, | ||
) { | ||
suspend fun latestRelease(): APIRelease<APIManagerAsset> { | ||
val managerRelease = backendRepository.release( | ||
configurationRepository.organization, | ||
configurationRepository.manager.repository, | ||
) | ||
|
||
val managerAsset = APIManagerAsset( | ||
managerRelease.assets.first(configurationRepository.manager.assetRegex).downloadUrl, | ||
) | ||
|
||
return APIRelease( | ||
managerRelease.tag, | ||
managerRelease.createdAt, | ||
managerRelease.releaseNote, | ||
listOf(managerAsset), | ||
) | ||
} | ||
|
||
suspend fun latestVersion(): APIReleaseVersion { | ||
val managerRelease = backendRepository.release( | ||
configurationRepository.organization, | ||
configurationRepository.manager.repository, | ||
) | ||
|
||
return APIReleaseVersion(managerRelease.tag) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters