mirror of
https://github.com/revanced/revanced-api.git
synced 2025-05-01 23:24:39 +02:00
feat: Add backend rate limit route
This commit is contained in:
parent
71f58cf352
commit
b9671703be
@ -41,7 +41,6 @@ abstract class BackendRepository internal constructor(
|
|||||||
* @property bio The bio of the member.
|
* @property bio The bio of the member.
|
||||||
* @property gpgKeys The GPG key of the member.
|
* @property gpgKeys The GPG key of the member.
|
||||||
*/
|
*/
|
||||||
@Serializable
|
|
||||||
class BackendMember(
|
class BackendMember(
|
||||||
override val name: String,
|
override val name: String,
|
||||||
override val avatarUrl: String,
|
override val avatarUrl: String,
|
||||||
@ -110,6 +109,19 @@ abstract class BackendRepository internal constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rate limit of the backend.
|
||||||
|
*
|
||||||
|
* @property limit The limit of the rate limit.
|
||||||
|
* @property remaining The remaining requests of the rate limit.
|
||||||
|
* @property reset The date and time the rate limit resets.
|
||||||
|
*/
|
||||||
|
class BackendRateLimit(
|
||||||
|
val limit: Int,
|
||||||
|
val remaining: Int,
|
||||||
|
val reset: LocalDateTime,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a release of a repository.
|
* Get a release of a repository.
|
||||||
*
|
*
|
||||||
@ -140,4 +152,11 @@ abstract class BackendRepository internal constructor(
|
|||||||
* @return The members.
|
* @return The members.
|
||||||
*/
|
*/
|
||||||
abstract suspend fun members(organization: String): Set<BackendOrganization.BackendMember>
|
abstract suspend fun members(organization: String): Set<BackendOrganization.BackendMember>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rate limit of the backend.
|
||||||
|
*
|
||||||
|
* @return The rate limit.
|
||||||
|
*/
|
||||||
|
abstract suspend fun rateLimit(): BackendRateLimit?
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package app.revanced.api.configuration.routing.routes
|
package app.revanced.api.configuration.routing.routes
|
||||||
|
|
||||||
|
import app.revanced.api.configuration.respondOrNotFound
|
||||||
import app.revanced.api.configuration.services.ApiService
|
import app.revanced.api.configuration.services.ApiService
|
||||||
import app.revanced.api.configuration.services.AuthService
|
import app.revanced.api.configuration.services.AuthService
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
@ -28,6 +29,10 @@ internal fun Route.rootRoute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("backend/rate_limit") {
|
||||||
|
call.respondOrNotFound(apiService.rateLimit())
|
||||||
|
}
|
||||||
|
|
||||||
authenticate("basic") {
|
authenticate("basic") {
|
||||||
get("token") {
|
get("token") {
|
||||||
call.respond(authService.newToken())
|
call.respond(authService.newToken())
|
||||||
|
@ -106,3 +106,10 @@ class APILatestAnnouncement(
|
|||||||
class APIAnnouncementArchivedAt(
|
class APIAnnouncementArchivedAt(
|
||||||
val archivedAt: LocalDateTime,
|
val archivedAt: LocalDateTime,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class APIRateLimit(
|
||||||
|
val limit: Int,
|
||||||
|
val remaining: Int,
|
||||||
|
val reset: LocalDateTime,
|
||||||
|
)
|
||||||
|
@ -42,4 +42,8 @@ internal class ApiService(
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun rateLimit() = backendRepository.rateLimit()?.let {
|
||||||
|
APIRateLimit(it.limit, it.remaining, it.reset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user