mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-18 00:43:57 +00:00
Compare commits
13 Commits
v1.4.0-dev
...
v1.4.0-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a09b028b7 | ||
|
|
0ddbf5beda | ||
|
|
bf41fa1596 | ||
|
|
8ad614ef4f | ||
|
|
fc40427fba | ||
|
|
e8dfefe6ae | ||
|
|
d42a3a3933 | ||
|
|
bb7aa5b0b4 | ||
|
|
3b6212065a | ||
|
|
3d3b7a7af8 | ||
|
|
f1c10928ae | ||
|
|
a5498aba2b | ||
|
|
f91f3a65c5 |
@@ -13,3 +13,6 @@ AUTH_SHA256_DIGEST=
|
|||||||
JWT_SECRET=
|
JWT_SECRET=
|
||||||
JWT_ISSUER=
|
JWT_ISSUER=
|
||||||
JWT_VALIDITY_IN_MIN=
|
JWT_VALIDITY_IN_MIN=
|
||||||
|
|
||||||
|
# Logging level for the application
|
||||||
|
LOG_LEVEL=INFO
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -41,7 +41,6 @@ persistence/
|
|||||||
configuration.toml
|
configuration.toml
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
patches-public-key.asc
|
patches-public-key.asc
|
||||||
integrations-public-key.asc
|
|
||||||
node_modules/
|
node_modules/
|
||||||
static/
|
static/
|
||||||
about.json
|
about.json
|
||||||
31
CHANGELOG.md
31
CHANGELOG.md
@@ -1,3 +1,34 @@
|
|||||||
|
# [1.4.0-dev.5](https://github.com/ReVanced/revanced-api/compare/v1.4.0-dev.4...v1.4.0-dev.5) (2024-11-05)
|
||||||
|
|
||||||
|
# [1.4.0-dev.4](https://github.com/ReVanced/revanced-api/compare/v1.4.0-dev.3...v1.4.0-dev.4) (2024-11-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Remove "archived" query parameter ([8ad614e](https://github.com/ReVanced/revanced-api/commit/8ad614ef4fdaf45af87a3316ef4db7e7236fd64a))
|
||||||
|
* Use tag name directly instead of ID ([fc40427](https://github.com/ReVanced/revanced-api/commit/fc40427fbaafb523045eb6f5285d90949b206b8b))
|
||||||
|
|
||||||
|
# [1.4.0-dev.3](https://github.com/ReVanced/revanced-api/compare/v1.4.0-dev.2...v1.4.0-dev.3) (2024-11-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Use new patches file extension ([d42a3a3](https://github.com/ReVanced/revanced-api/commit/d42a3a393396a0f4e9085cda46e0af2c12b63cb1))
|
||||||
|
|
||||||
|
# [1.4.0-dev.2](https://github.com/ReVanced/revanced-api/compare/v1.4.0-dev.1...v1.4.0-dev.2) (2024-11-01)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Add missing logging level environment variable to .env.example ([3b62120](https://github.com/ReVanced/revanced-api/commit/3b6212065a5cfb95c303b6d0551747ba1eb317f6))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add URL and use friendly name for `APIContributable` ([a5498ab](https://github.com/ReVanced/revanced-api/commit/a5498aba2b99db89c28a65738cc58cc4c852c327))
|
||||||
|
* Make backend configurable ([f91f3a6](https://github.com/ReVanced/revanced-api/commit/f91f3a65c5e07b5b58ccbff1d4b0a5ba9b15fc50))
|
||||||
|
* Remove ReVanced Integrations ([f1c1092](https://github.com/ReVanced/revanced-api/commit/f1c10928ae3be1c6b1d675819755b3046fad70d8))
|
||||||
|
|
||||||
# [1.4.0-dev.1](https://github.com/ReVanced/revanced-api/compare/v1.3.0...v1.4.0-dev.1) (2024-11-01)
|
# [1.4.0-dev.1](https://github.com/ReVanced/revanced-api/compare/v1.3.0...v1.4.0-dev.1) (2024-11-01)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -68,7 +68,8 @@ API server for ReVanced.
|
|||||||
## ❓ About
|
## ❓ About
|
||||||
|
|
||||||
ReVanced API is a server that is used as the backend for ReVanced.
|
ReVanced API is a server that is used as the backend for ReVanced.
|
||||||
ReVanced API acts as the data source for [ReVanced Website](https://github.com/ReVanced/revanced-website) and powers [ReVanced Manager](https://github.com/ReVanced/revanced-manager)
|
ReVanced API acts as the data source for [ReVanced Website](https://github.com/ReVanced/revanced-website) and
|
||||||
|
powers [ReVanced Manager](https://github.com/ReVanced/revanced-manager)
|
||||||
with updates and ReVanced Patches.
|
with updates and ReVanced Patches.
|
||||||
|
|
||||||
## 💪 Features
|
## 💪 Features
|
||||||
@@ -76,8 +77,8 @@ with updates and ReVanced Patches.
|
|||||||
Some of the features ReVanced API include:
|
Some of the features ReVanced API include:
|
||||||
|
|
||||||
- 📢 **Announcements**: Post and get announcements
|
- 📢 **Announcements**: Post and get announcements
|
||||||
- ℹ️ **About**: Get more information such as a description, ways to donate to,
|
- ℹ️ **About**: Get more information such as a description, ways to donate to,
|
||||||
and links of the hoster of ReVanced API
|
and links of the hoster of ReVanced API
|
||||||
- 🧩 **Patches**: Get the latest updates of ReVanced Patches, directly from ReVanced API
|
- 🧩 **Patches**: Get the latest updates of ReVanced Patches, directly from ReVanced API
|
||||||
- 👥 **Contributors**: List all contributors involved in the project
|
- 👥 **Contributors**: List all contributors involved in the project
|
||||||
- 🔄 **Backwards compatibility**: Proxy an old API for migration purposes and backwards compatibility
|
- 🔄 **Backwards compatibility**: Proxy an old API for migration purposes and backwards compatibility
|
||||||
@@ -90,7 +91,8 @@ ReVanced API can be deployed as a Docker container or used standalone.
|
|||||||
|
|
||||||
To deploy ReVanced API as a Docker container, you can use Docker Compose or Docker CLI.
|
To deploy ReVanced API as a Docker container, you can use Docker Compose or Docker CLI.
|
||||||
The Docker image is published on GitHub Container registry,
|
The Docker image is published on GitHub Container registry,
|
||||||
so before you can pull the image, you need to [authenticate to the Container registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry).
|
so before you can pull the image, you need
|
||||||
|
to [authenticate to the Container registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry).
|
||||||
|
|
||||||
### 🗄️ Docker Compose
|
### 🗄️ Docker Compose
|
||||||
|
|
||||||
@@ -114,8 +116,6 @@ so before you can pull the image, you need to [authenticate to the Container reg
|
|||||||
-v $(pwd)/configuration.toml:/app/configuration.toml \
|
-v $(pwd)/configuration.toml:/app/configuration.toml \
|
||||||
# Mount the patches public key
|
# Mount the patches public key
|
||||||
-v $(pwd)/patches-public-key.asc:/app/patches-public-key.asc \
|
-v $(pwd)/patches-public-key.asc:/app/patches-public-key.asc \
|
||||||
# Mount the integrations public key
|
|
||||||
-v $(pwd)/integrations-public-key.asc:/app/integrations-public-key.asc \
|
|
||||||
# Mount the static folder
|
# Mount the static folder
|
||||||
-v $(pwd)/static:/app/static \
|
-v $(pwd)/static:/app/static \
|
||||||
# Mount the about.json file
|
# Mount the about.json file
|
||||||
@@ -141,7 +141,7 @@ A Java Runtime Environment (JRE) must be installed.
|
|||||||
1. [Download](https://github.com/ReVanced/revanced-api/releases/latest) ReVanced API to a folder
|
1. [Download](https://github.com/ReVanced/revanced-api/releases/latest) ReVanced API to a folder
|
||||||
2. In the same folder, create an `.env` file using [.env.example](.env.example) as a template
|
2. In the same folder, create an `.env` file using [.env.example](.env.example) as a template
|
||||||
3. In the same folder, create a `configuration.toml` file
|
3. In the same folder, create a `configuration.toml` file
|
||||||
using [configuration.example.toml](configuration.example.toml) as a template
|
using [configuration.example.toml](configuration.example.toml) as a template
|
||||||
4. In the same folder, create an `about.json` file using [about.example.json](about.example.json) as a template
|
4. In the same folder, create an `about.json` file using [about.example.json](about.example.json) as a template
|
||||||
5. Run `java -jar revanced-api.jar start` to start the server
|
5. Run `java -jar revanced-api.jar start` to start the server
|
||||||
|
|
||||||
@@ -159,7 +159,8 @@ A Java Development Kit (JDK) and Git must be installed.
|
|||||||
|
|
||||||
### 📙 Contributing
|
### 📙 Contributing
|
||||||
|
|
||||||
Thank you for considering contributing to ReVanced API. You can find the contribution guidelines [here](CONTRIBUTING.md).
|
Thank you for considering contributing to ReVanced API. You can find the contribution
|
||||||
|
guidelines [here](CONTRIBUTING.md).
|
||||||
|
|
||||||
### 🛠️ Building
|
### 🛠️ Building
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,3 @@
|
|||||||
organization = "revanced"
|
|
||||||
patches = { repository = "revanced-patches", asset-regex = "jar$", signature-asset-regex = "asc$", public-key-file = "patches-public-key.asc", public-key-id = 0 }
|
|
||||||
integrations = { repository = "revanced-integrations", asset-regex = "apk$", signature-asset-regex = "asc$", public-key-file = "integrations-public-key.asc", public-key-id = 0 }
|
|
||||||
manager = { repository = "revanced-manager", asset-regex = "apk$" }
|
|
||||||
contributors-repositories = [
|
|
||||||
"revanced-patcher",
|
|
||||||
"revanced-patches",
|
|
||||||
"revanced-integrations",
|
|
||||||
"revanced-website",
|
|
||||||
"revanced-cli",
|
|
||||||
"revanced-manager",
|
|
||||||
]
|
|
||||||
api-version = 1
|
api-version = 1
|
||||||
cors-allowed-hosts = [
|
cors-allowed-hosts = [
|
||||||
"revanced.app",
|
"revanced.app",
|
||||||
@@ -19,4 +7,24 @@ endpoint = "https://api.revanced.app"
|
|||||||
old-api-endpoint = "https://old-api.revanced.app"
|
old-api-endpoint = "https://old-api.revanced.app"
|
||||||
static-files-path = "static/root"
|
static-files-path = "static/root"
|
||||||
versioned-static-files-path = "static/versioned"
|
versioned-static-files-path = "static/versioned"
|
||||||
|
backend-service-name = "GitHub"
|
||||||
about-json-file-path = "about.json"
|
about-json-file-path = "about.json"
|
||||||
|
organization = "revanced"
|
||||||
|
|
||||||
|
[patches]
|
||||||
|
repository = "revanced-patches"
|
||||||
|
asset-regex = "rvp$"
|
||||||
|
signature-asset-regex = "asc$"
|
||||||
|
public-key-file = "static/root/keys.asc"
|
||||||
|
public-key-id = 3897925568445097277
|
||||||
|
|
||||||
|
[manager]
|
||||||
|
repository = "revanced-manager"
|
||||||
|
asset-regex = "apk$"
|
||||||
|
|
||||||
|
[contributors-repositories]
|
||||||
|
revanced-patcher = "ReVanced Patcher"
|
||||||
|
revanced-patches = "ReVanced Patches"
|
||||||
|
revanced-website = "ReVanced Website"
|
||||||
|
revanced-cli = "ReVanced CLI"
|
||||||
|
revanced-manager = "ReVanced Manager"
|
||||||
@@ -7,7 +7,6 @@ services:
|
|||||||
- /data/revanced-api/.env:/app/.env
|
- /data/revanced-api/.env:/app/.env
|
||||||
- /data/revanced-api/configuration.toml:/app/configuration.toml
|
- /data/revanced-api/configuration.toml:/app/configuration.toml
|
||||||
- /data/revanced-api/patches-public-key.asc:/app/patches-public-key.asc
|
- /data/revanced-api/patches-public-key.asc:/app/patches-public-key.asc
|
||||||
- /data/revanced-api/integrations-public-key.asc:/app/integrations-public-key.asc
|
|
||||||
- /data/revanced-api/static:/app/static
|
- /data/revanced-api/static:/app/static
|
||||||
- /data/revanced-api/about.json:/app/about.json
|
- /data/revanced-api/about.json:/app/about.json
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
org.gradle.parallel = true
|
org.gradle.parallel = true
|
||||||
org.gradle.caching = true
|
org.gradle.caching = true
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 1.4.0-dev.1
|
version = 1.4.0-dev.5
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kompendium-core = "3.14.4"
|
kompendium-core = "3.14.4"
|
||||||
kotlin = "2.0.0"
|
kotlin = "2.0.20"
|
||||||
logback = "1.5.6"
|
logback = "1.5.6"
|
||||||
exposed = "0.52.0"
|
exposed = "0.52.0"
|
||||||
h2 = "2.2.224"
|
h2 = "2.2.224"
|
||||||
@@ -10,8 +10,8 @@ ktor = "2.3.7"
|
|||||||
ktoml = "0.5.2"
|
ktoml = "0.5.2"
|
||||||
picocli = "4.7.6"
|
picocli = "4.7.6"
|
||||||
datetime = "0.6.0"
|
datetime = "0.6.0"
|
||||||
revanced-patcher = "20.0.0"
|
revanced-patcher = "21.0.0"
|
||||||
revanced-library = "3.0.1-dev.1"
|
revanced-library = "3.0.2"
|
||||||
caffeine = "3.1.8"
|
caffeine = "3.1.8"
|
||||||
bouncy-castle = "1.78.1"
|
bouncy-castle = "1.78.1"
|
||||||
|
|
||||||
|
|||||||
@@ -5,101 +5,39 @@ import app.revanced.api.configuration.repository.BackendRepository
|
|||||||
import app.revanced.api.configuration.repository.ConfigurationRepository
|
import app.revanced.api.configuration.repository.ConfigurationRepository
|
||||||
import app.revanced.api.configuration.repository.GitHubBackendRepository
|
import app.revanced.api.configuration.repository.GitHubBackendRepository
|
||||||
import app.revanced.api.configuration.services.*
|
import app.revanced.api.configuration.services.*
|
||||||
import app.revanced.api.configuration.services.AnnouncementService
|
|
||||||
import app.revanced.api.configuration.services.ApiService
|
|
||||||
import app.revanced.api.configuration.services.AuthenticationService
|
|
||||||
import app.revanced.api.configuration.services.OldApiService
|
|
||||||
import app.revanced.api.configuration.services.PatchesService
|
|
||||||
import com.akuleshov7.ktoml.Toml
|
import com.akuleshov7.ktoml.Toml
|
||||||
import com.akuleshov7.ktoml.source.decodeFromStream
|
import com.akuleshov7.ktoml.source.decodeFromStream
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.engine.okhttp.*
|
|
||||||
import io.ktor.client.plugins.*
|
|
||||||
import io.ktor.client.plugins.auth.*
|
|
||||||
import io.ktor.client.plugins.auth.providers.*
|
|
||||||
import io.ktor.client.plugins.cache.*
|
|
||||||
import io.ktor.client.plugins.contentnegotiation.*
|
|
||||||
import io.ktor.client.plugins.resources.*
|
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import kotlinx.serialization.ExperimentalSerializationApi
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
import kotlinx.serialization.json.JsonNamingStrategy
|
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
|
||||||
import org.koin.core.module.dsl.singleOf
|
import org.koin.core.module.dsl.singleOf
|
||||||
import org.koin.core.parameter.parameterArrayOf
|
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import org.koin.ktor.plugin.Koin
|
import org.koin.ktor.plugin.Koin
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
|
||||||
fun Application.configureDependencies(
|
fun Application.configureDependencies(
|
||||||
configFile: File,
|
configFile: File,
|
||||||
) {
|
) {
|
||||||
val miscModule = module {
|
|
||||||
factory { params ->
|
|
||||||
val defaultRequestUri: String = params.get<String>()
|
|
||||||
val configBlock = params.getOrNull<(HttpClientConfig<OkHttpConfig>.() -> Unit)>() ?: {}
|
|
||||||
|
|
||||||
HttpClient(OkHttp) {
|
|
||||||
defaultRequest { url(defaultRequestUri) }
|
|
||||||
|
|
||||||
configBlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val repositoryModule = module {
|
val repositoryModule = module {
|
||||||
single<BackendRepository> {
|
single<ConfigurationRepository> { Toml.decodeFromStream(configFile.inputStream()) }
|
||||||
GitHubBackendRepository(
|
|
||||||
get {
|
|
||||||
val defaultRequestUri = "https://api.github.com"
|
|
||||||
val configBlock: HttpClientConfig<OkHttpConfig>.() -> Unit = {
|
|
||||||
install(HttpCache)
|
|
||||||
install(Resources)
|
|
||||||
install(ContentNegotiation) {
|
|
||||||
json(
|
|
||||||
Json {
|
|
||||||
ignoreUnknownKeys = true
|
|
||||||
namingStrategy = JsonNamingStrategy.SnakeCase
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
System.getProperty("BACKEND_API_TOKEN")?.let {
|
|
||||||
install(Auth) {
|
|
||||||
bearer {
|
|
||||||
loadTokens {
|
|
||||||
BearerTokens(
|
|
||||||
accessToken = it,
|
|
||||||
refreshToken = "", // Required dummy value
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
sendWithoutRequest { true }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
parameterArrayOf(defaultRequestUri, configBlock)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
single<ConfigurationRepository> {
|
|
||||||
Toml.decodeFromStream(configFile.inputStream())
|
|
||||||
}
|
|
||||||
|
|
||||||
single {
|
single {
|
||||||
TransactionManager.defaultDatabase = Database.connect(
|
Database.connect(
|
||||||
url = System.getProperty("DB_URL"),
|
url = System.getProperty("DB_URL"),
|
||||||
user = System.getProperty("DB_USER"),
|
user = System.getProperty("DB_USER"),
|
||||||
password = System.getProperty("DB_PASSWORD"),
|
password = System.getProperty("DB_PASSWORD"),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
singleOf(::AnnouncementRepository)
|
||||||
|
singleOf(::GitHubBackendRepository)
|
||||||
|
single<BackendRepository> {
|
||||||
|
val backendServices = mapOf(
|
||||||
|
GitHubBackendRepository.SERVICE_NAME to { get<GitHubBackendRepository>() },
|
||||||
|
// Implement more backend services here.
|
||||||
|
)
|
||||||
|
|
||||||
AnnouncementRepository()
|
val configuration = get<ConfigurationRepository>()
|
||||||
|
val backendFactory = backendServices[configuration.backendServiceName]!!
|
||||||
|
|
||||||
|
backendFactory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,15 +51,7 @@ fun Application.configureDependencies(
|
|||||||
|
|
||||||
AuthenticationService(issuer, validityInMin, jwtSecret, authSHA256DigestString)
|
AuthenticationService(issuer, validityInMin, jwtSecret, authSHA256DigestString)
|
||||||
}
|
}
|
||||||
single {
|
singleOf(::OldApiService)
|
||||||
val configuration = get<ConfigurationRepository>()
|
|
||||||
|
|
||||||
OldApiService(
|
|
||||||
get {
|
|
||||||
parameterArrayOf(configuration.oldApiEndpoint)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
singleOf(::AnnouncementService)
|
singleOf(::AnnouncementService)
|
||||||
singleOf(::SignatureService)
|
singleOf(::SignatureService)
|
||||||
singleOf(::PatchesService)
|
singleOf(::PatchesService)
|
||||||
@@ -131,7 +61,6 @@ fun Application.configureDependencies(
|
|||||||
|
|
||||||
install(Koin) {
|
install(Koin) {
|
||||||
modules(
|
modules(
|
||||||
miscModule,
|
|
||||||
repositoryModule,
|
repositoryModule,
|
||||||
serviceModule,
|
serviceModule,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import app.revanced.api.configuration.schema.ApiResponseAnnouncement
|
|||||||
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
|
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.datetime.*
|
|
||||||
import org.jetbrains.exposed.dao.IntEntity
|
import org.jetbrains.exposed.dao.IntEntity
|
||||||
import org.jetbrains.exposed.dao.IntEntityClass
|
import org.jetbrains.exposed.dao.IntEntityClass
|
||||||
import org.jetbrains.exposed.dao.id.EntityID
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
@@ -15,12 +14,11 @@ import org.jetbrains.exposed.sql.*
|
|||||||
import org.jetbrains.exposed.sql.kotlin.datetime.CurrentDateTime
|
import org.jetbrains.exposed.sql.kotlin.datetime.CurrentDateTime
|
||||||
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
|
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
import java.time.LocalDateTime
|
|
||||||
|
|
||||||
internal class AnnouncementRepository {
|
internal class AnnouncementRepository(private val database: Database) {
|
||||||
// This is better than doing a maxByOrNull { it.id } on every request.
|
// This is better than doing a maxByOrNull { it.id } on every request.
|
||||||
private var latestAnnouncement: Announcement? = null
|
private var latestAnnouncement: Announcement? = null
|
||||||
private val latestAnnouncementByTag = mutableMapOf<Int, Announcement>()
|
private val latestAnnouncementByTag = mutableMapOf<String, Announcement>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
@@ -40,22 +38,23 @@ internal class AnnouncementRepository {
|
|||||||
private fun initializeLatestAnnouncements() {
|
private fun initializeLatestAnnouncements() {
|
||||||
latestAnnouncement = Announcement.all().orderBy(Announcements.id to SortOrder.DESC).firstOrNull()
|
latestAnnouncement = Announcement.all().orderBy(Announcements.id to SortOrder.DESC).firstOrNull()
|
||||||
|
|
||||||
Tag.all().map { it.id.value }.forEach(::updateLatestAnnouncementForTag)
|
Tag.all().map { it.name }.forEach(::updateLatestAnnouncementForTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLatestAnnouncement(new: Announcement) {
|
private fun updateLatestAnnouncement(new: Announcement) {
|
||||||
if (latestAnnouncement == null || latestAnnouncement!!.id.value <= new.id.value) {
|
if (latestAnnouncement == null || latestAnnouncement!!.id.value <= new.id.value) {
|
||||||
latestAnnouncement = new
|
latestAnnouncement = new
|
||||||
new.tags.forEach { tag -> latestAnnouncementByTag[tag.id.value] = new }
|
new.tags.forEach { tag -> latestAnnouncementByTag[tag.name] = new }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateLatestAnnouncementForTag(tag: Int) {
|
private fun updateLatestAnnouncementForTag(tag: String) {
|
||||||
val latestAnnouncementForTag = AnnouncementTags.select(AnnouncementTags.announcement)
|
val latestAnnouncementForTag = Tags.innerJoin(AnnouncementTags)
|
||||||
.where { AnnouncementTags.tag eq tag }
|
.select(AnnouncementTags.announcement)
|
||||||
.map { it[AnnouncementTags.announcement] }
|
.where { Tags.name eq tag }
|
||||||
.mapNotNull { Announcement.findById(it) }
|
.orderBy(AnnouncementTags.announcement to SortOrder.DESC)
|
||||||
.maxByOrNull { it.id }
|
.limit(1)
|
||||||
|
.firstNotNullOfOrNull { Announcement.findById(it[AnnouncementTags.announcement]) }
|
||||||
|
|
||||||
latestAnnouncementForTag?.let { latestAnnouncementByTag[tag] = it }
|
latestAnnouncementForTag?.let { latestAnnouncementByTag[tag] = it }
|
||||||
}
|
}
|
||||||
@@ -64,42 +63,30 @@ internal class AnnouncementRepository {
|
|||||||
latestAnnouncement.toApiResponseAnnouncement()
|
latestAnnouncement.toApiResponseAnnouncement()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun latest(tags: Set<Int>) = transaction {
|
suspend fun latest(tags: Set<String>) = transaction {
|
||||||
tags.mapNotNull { tag -> latestAnnouncementByTag[tag] }.toApiAnnouncement()
|
tags.mapNotNull { tag -> latestAnnouncementByTag[tag] }.toApiAnnouncement()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun latestId() = latestAnnouncement?.id?.value.toApiResponseAnnouncementId()
|
fun latestId() = latestAnnouncement?.id?.value.toApiResponseAnnouncementId()
|
||||||
|
|
||||||
fun latestId(tags: Set<Int>) =
|
fun latestId(tags: Set<String>) =
|
||||||
tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
|
tags.map { tag -> latestAnnouncementByTag[tag]?.id?.value }.toApiResponseAnnouncementId()
|
||||||
|
|
||||||
suspend fun paged(cursor: Int, count: Int, tags: Set<Int>?, archived: Boolean) = transaction {
|
suspend fun paged(cursor: Int, count: Int, tags: Set<String>?) = transaction {
|
||||||
Announcement.find {
|
Announcement.find {
|
||||||
fun idLessEq() = Announcements.id lessEq cursor
|
fun idLessEq() = Announcements.id lessEq cursor
|
||||||
fun archivedAtIsNull() = Announcements.archivedAt.isNull()
|
|
||||||
fun archivedAtGreaterNow() = Announcements.archivedAt greater LocalDateTime.now().toKotlinLocalDateTime()
|
|
||||||
|
|
||||||
if (tags == null) {
|
if (tags == null) {
|
||||||
if (archived) {
|
idLessEq()
|
||||||
idLessEq()
|
|
||||||
} else {
|
|
||||||
idLessEq() and (archivedAtIsNull() or archivedAtGreaterNow())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fun archivedAtGreaterOrNullOrTrue() = if (archived) {
|
fun hasTags() = Announcements.id inSubQuery (
|
||||||
Op.TRUE
|
AnnouncementTags.innerJoin(Tags)
|
||||||
} else {
|
|
||||||
archivedAtIsNull() or archivedAtGreaterNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hasTags() = tags.mapNotNull { Tag.findById(it)?.id }.let { tags ->
|
|
||||||
Announcements.id inSubQuery Announcements.leftJoin(AnnouncementTags)
|
|
||||||
.select(AnnouncementTags.announcement)
|
.select(AnnouncementTags.announcement)
|
||||||
.where { AnnouncementTags.tag inList tags }
|
|
||||||
.withDistinct()
|
.withDistinct()
|
||||||
}
|
.where { Tags.name inList tags }
|
||||||
|
)
|
||||||
|
|
||||||
idLessEq() and archivedAtGreaterOrNullOrTrue() and hasTags()
|
idLessEq() and hasTags()
|
||||||
}
|
}
|
||||||
}.orderBy(Announcements.id to SortOrder.DESC).limit(count).toApiAnnouncement()
|
}.orderBy(Announcements.id to SortOrder.DESC).limit(count).toApiAnnouncement()
|
||||||
}
|
}
|
||||||
@@ -165,7 +152,7 @@ internal class AnnouncementRepository {
|
|||||||
// Delete the tag if no other announcements are referencing it.
|
// Delete the tag if no other announcements are referencing it.
|
||||||
// One count means that the announcement is the only one referencing the tag.
|
// One count means that the announcement is the only one referencing the tag.
|
||||||
announcement.tags.filter { tag -> tag.announcements.count() == 1L }.forEach { tag ->
|
announcement.tags.filter { tag -> tag.announcements.count() == 1L }.forEach { tag ->
|
||||||
latestAnnouncementByTag -= tag.id.value
|
latestAnnouncementByTag -= tag.name
|
||||||
tag.delete()
|
tag.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +174,7 @@ internal class AnnouncementRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun <T> transaction(statement: suspend Transaction.() -> T) =
|
private suspend fun <T> transaction(statement: suspend Transaction.() -> T) =
|
||||||
newSuspendedTransaction(Dispatchers.IO, statement = statement)
|
newSuspendedTransaction(Dispatchers.IO, database, statement = statement)
|
||||||
|
|
||||||
private object Announcements : IntIdTable() {
|
private object Announcements : IntIdTable() {
|
||||||
val author = varchar("author", 32).nullable()
|
val author = varchar("author", 32).nullable()
|
||||||
@@ -250,7 +237,7 @@ internal class AnnouncementRepository {
|
|||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
attachments.map { it.url },
|
attachments.map { it.url },
|
||||||
tags.map { it.id.value },
|
tags.map { it.name },
|
||||||
createdAt,
|
createdAt,
|
||||||
archivedAt,
|
archivedAt,
|
||||||
level,
|
level,
|
||||||
@@ -259,7 +246,7 @@ internal class AnnouncementRepository {
|
|||||||
|
|
||||||
private fun Iterable<Announcement>.toApiAnnouncement() = map { it.toApiResponseAnnouncement()!! }
|
private fun Iterable<Announcement>.toApiAnnouncement() = map { it.toApiResponseAnnouncement()!! }
|
||||||
|
|
||||||
private fun Iterable<Tag>.toApiTag() = map { ApiAnnouncementTag(it.id.value, it.name) }
|
private fun Iterable<Tag>.toApiTag() = map { ApiAnnouncementTag(it.name) }
|
||||||
|
|
||||||
private fun Int?.toApiResponseAnnouncementId() = this?.let { ApiResponseAnnouncementId(this) }
|
private fun Int?.toApiResponseAnnouncementId() = this?.let { ApiResponseAnnouncementId(this) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,59 @@
|
|||||||
package app.revanced.api.configuration.repository
|
package app.revanced.api.configuration.repository
|
||||||
|
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.okhttp.*
|
||||||
|
import io.ktor.client.plugins.*
|
||||||
|
import io.ktor.client.plugins.auth.*
|
||||||
|
import io.ktor.client.plugins.auth.providers.*
|
||||||
|
import io.ktor.client.plugins.cache.*
|
||||||
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.client.plugins.resources.*
|
||||||
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.datetime.LocalDateTime
|
import kotlinx.datetime.LocalDateTime
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.JsonNamingStrategy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The backend of the API used to get data.
|
* The backend of the API used to get data.
|
||||||
*
|
*
|
||||||
* @param client The HTTP client to use for requests.
|
* @param defaultRequestUri The URI to use for requests.
|
||||||
|
* @param website The site of the backend users can visit.
|
||||||
*/
|
*/
|
||||||
abstract class BackendRepository internal constructor(
|
abstract class BackendRepository internal constructor(
|
||||||
protected val client: HttpClient,
|
defaultRequestUri: String,
|
||||||
|
internal val website: String,
|
||||||
) {
|
) {
|
||||||
|
protected val client: HttpClient = HttpClient(OkHttp) {
|
||||||
|
defaultRequest { url(defaultRequestUri) }
|
||||||
|
|
||||||
|
install(HttpCache)
|
||||||
|
install(Resources)
|
||||||
|
install(ContentNegotiation) {
|
||||||
|
json(
|
||||||
|
Json {
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
@Suppress("OPT_IN_USAGE")
|
||||||
|
namingStrategy = JsonNamingStrategy.SnakeCase
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
System.getProperty("BACKEND_API_TOKEN")?.let {
|
||||||
|
install(Auth) {
|
||||||
|
bearer {
|
||||||
|
loadTokens {
|
||||||
|
BearerTokens(
|
||||||
|
accessToken = it,
|
||||||
|
refreshToken = "", // Required dummy value
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendWithoutRequest { true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A user.
|
* A user.
|
||||||
*
|
*
|
||||||
@@ -153,7 +196,10 @@ abstract class BackendRepository internal constructor(
|
|||||||
* @param repository The name of the repository.
|
* @param repository The name of the repository.
|
||||||
* @return The contributors.
|
* @return The contributors.
|
||||||
*/
|
*/
|
||||||
abstract suspend fun contributors(owner: String, repository: String): List<BackendOrganization.BackendRepository.BackendContributor>
|
abstract suspend fun contributors(
|
||||||
|
owner: String,
|
||||||
|
repository: String,
|
||||||
|
): List<BackendOrganization.BackendRepository.BackendContributor>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the members of an organization.
|
* Get the members of an organization.
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ import kotlin.io.path.createDirectories
|
|||||||
/**
|
/**
|
||||||
* The repository storing the configuration for the API.
|
* The repository storing the configuration for the API.
|
||||||
*
|
*
|
||||||
* @property organization The API backends organization name where the repositories for the patches and integrations are.
|
* @property organization The API backends organization name where the repositories are.
|
||||||
* @property patches The source of the patches.
|
* @property patches The source of the patches.
|
||||||
* @property integrations The source of the integrations.
|
|
||||||
* @property manager The source of the manager.
|
* @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 apiVersion The version to use for the API.
|
||||||
* @property corsAllowedHosts The hosts allowed to make requests to the API.
|
* @property corsAllowedHosts The hosts allowed to make requests to the API.
|
||||||
* @property endpoint The endpoint of the API.
|
* @property endpoint The endpoint of the API.
|
||||||
@@ -40,10 +40,11 @@ import kotlin.io.path.createDirectories
|
|||||||
internal class ConfigurationRepository(
|
internal class ConfigurationRepository(
|
||||||
val organization: String,
|
val organization: String,
|
||||||
val patches: SignedAssetConfiguration,
|
val patches: SignedAssetConfiguration,
|
||||||
val integrations: SignedAssetConfiguration,
|
|
||||||
val manager: AssetConfiguration,
|
val manager: AssetConfiguration,
|
||||||
@SerialName("contributors-repositories")
|
@SerialName("contributors-repositories")
|
||||||
val contributorsRepositoryNames: Set<String>,
|
val contributorsRepositoryNames: Map<String, String>,
|
||||||
|
@SerialName("backend-service-name")
|
||||||
|
val backendServiceName: String,
|
||||||
@SerialName("api-version")
|
@SerialName("api-version")
|
||||||
val apiVersion: Int = 1,
|
val apiVersion: Int = 1,
|
||||||
@SerialName("cors-allowed-hosts")
|
@SerialName("cors-allowed-hosts")
|
||||||
|
|||||||
@@ -8,18 +8,19 @@ import app.revanced.api.configuration.repository.GitHubOrganization.GitHubReposi
|
|||||||
import app.revanced.api.configuration.repository.GitHubOrganization.GitHubRepository.GitHubRelease
|
import app.revanced.api.configuration.repository.GitHubOrganization.GitHubRepository.GitHubRelease
|
||||||
import app.revanced.api.configuration.repository.Organization.Repository.Contributors
|
import app.revanced.api.configuration.repository.Organization.Repository.Contributors
|
||||||
import app.revanced.api.configuration.repository.Organization.Repository.Releases
|
import app.revanced.api.configuration.repository.Organization.Repository.Releases
|
||||||
import io.ktor.client.*
|
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.plugins.resources.*
|
import io.ktor.client.plugins.resources.*
|
||||||
import io.ktor.resources.*
|
import io.ktor.resources.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.async
|
||||||
|
import kotlinx.coroutines.awaitAll
|
||||||
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.datetime.toLocalDateTime
|
import kotlinx.datetime.toLocalDateTime
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
class GitHubBackendRepository(client: HttpClient) : BackendRepository(client) {
|
class GitHubBackendRepository : BackendRepository("https://api.github.com", "https://github.com") {
|
||||||
override suspend fun release(
|
override suspend fun release(
|
||||||
owner: String,
|
owner: String,
|
||||||
repository: String,
|
repository: String,
|
||||||
@@ -67,7 +68,8 @@ class GitHubBackendRepository(client: HttpClient) : BackendRepository(client) {
|
|||||||
|
|
||||||
override suspend fun members(organization: String): List<BackendMember> {
|
override suspend fun members(organization: String): List<BackendMember> {
|
||||||
// Get the list of members of the organization.
|
// Get the list of members of the organization.
|
||||||
val publicMembers: List<GitHubOrganization.GitHubMember> = client.get(Organization.PublicMembers(organization)).body()
|
val publicMembers: List<GitHubOrganization.GitHubMember> =
|
||||||
|
client.get(Organization.PublicMembers(organization)).body()
|
||||||
|
|
||||||
return coroutineScope {
|
return coroutineScope {
|
||||||
publicMembers.map { member ->
|
publicMembers.map { member ->
|
||||||
@@ -113,6 +115,10 @@ class GitHubBackendRepository(client: HttpClient) : BackendRepository(client) {
|
|||||||
reset = Instant.fromEpochSeconds(rateLimit.rate.reset).toLocalDateTime(TimeZone.UTC),
|
reset = Instant.fromEpochSeconds(rateLimit.rate.reset).toLocalDateTime(TimeZone.UTC),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val SERVICE_NAME = "GitHub"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IGitHubUser {
|
interface IGitHubUser {
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import app.revanced.api.configuration.schema.ApiAnnouncement
|
|||||||
import app.revanced.api.configuration.schema.ApiResponseAnnouncement
|
import app.revanced.api.configuration.schema.ApiResponseAnnouncement
|
||||||
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
|
import app.revanced.api.configuration.schema.ApiResponseAnnouncementId
|
||||||
import app.revanced.api.configuration.services.AnnouncementService
|
import app.revanced.api.configuration.services.AnnouncementService
|
||||||
import io.bkbn.kompendium.core.metadata.*
|
import io.bkbn.kompendium.core.metadata.DeleteInfo
|
||||||
|
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||||
|
import io.bkbn.kompendium.core.metadata.PatchInfo
|
||||||
|
import io.bkbn.kompendium.core.metadata.PostInfo
|
||||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||||
import io.bkbn.kompendium.oas.payload.Parameter
|
import io.bkbn.kompendium.oas.payload.Parameter
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
@@ -33,9 +36,8 @@ internal fun Route.announcementsRoute() = route("announcements") {
|
|||||||
val cursor = call.parameters["cursor"]?.toInt() ?: Int.MAX_VALUE
|
val cursor = call.parameters["cursor"]?.toInt() ?: Int.MAX_VALUE
|
||||||
val count = call.parameters["count"]?.toInt() ?: 16
|
val count = call.parameters["count"]?.toInt() ?: 16
|
||||||
val tags = call.parameters.getAll("tag")
|
val tags = call.parameters.getAll("tag")
|
||||||
val archived = call.parameters["archived"]?.toBoolean() ?: true
|
|
||||||
|
|
||||||
call.respond(announcementService.paged(cursor, count, tags?.map { it.toInt() }?.toSet(), archived))
|
call.respond(announcementService.paged(cursor, count, tags?.toSet()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ internal fun Route.announcementsRoute() = route("announcements") {
|
|||||||
val tags = call.parameters.getAll("tag")
|
val tags = call.parameters.getAll("tag")
|
||||||
|
|
||||||
if (tags?.isNotEmpty() == true) {
|
if (tags?.isNotEmpty() == true) {
|
||||||
call.respond(announcementService.latest(tags.map { it.toInt() }.toSet()))
|
call.respond(announcementService.latest(tags.toSet()))
|
||||||
} else {
|
} else {
|
||||||
call.respondOrNotFound(announcementService.latest())
|
call.respondOrNotFound(announcementService.latest())
|
||||||
}
|
}
|
||||||
@@ -68,7 +70,7 @@ internal fun Route.announcementsRoute() = route("announcements") {
|
|||||||
val tags = call.parameters.getAll("tag")
|
val tags = call.parameters.getAll("tag")
|
||||||
|
|
||||||
if (tags?.isNotEmpty() == true) {
|
if (tags?.isNotEmpty() == true) {
|
||||||
call.respond(announcementService.latestId(tags.map { it.toInt() }.toSet()))
|
call.respond(announcementService.latestId(tags.toSet()))
|
||||||
} else {
|
} else {
|
||||||
call.respondOrNotFound(announcementService.latestId())
|
call.respondOrNotFound(announcementService.latestId())
|
||||||
}
|
}
|
||||||
@@ -146,15 +148,8 @@ private fun Route.installAnnouncementsRouteDocumentation() = installNotarizedRou
|
|||||||
Parameter(
|
Parameter(
|
||||||
name = "tag",
|
name = "tag",
|
||||||
`in` = Parameter.Location.query,
|
`in` = Parameter.Location.query,
|
||||||
schema = TypeDefinition.INT,
|
schema = TypeDefinition.STRING,
|
||||||
description = "The tag IDs to filter the announcements by. Default is all tags",
|
description = "The tags to filter the announcements by. Default is all tags",
|
||||||
required = false,
|
|
||||||
),
|
|
||||||
Parameter(
|
|
||||||
name = "archived",
|
|
||||||
`in` = Parameter.Location.query,
|
|
||||||
schema = TypeDefinition.BOOLEAN,
|
|
||||||
description = "Whether to include archived announcements. Default is true",
|
|
||||||
required = false,
|
required = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -193,8 +188,8 @@ private fun Route.installAnnouncementsLatestRouteDocumentation() = installNotari
|
|||||||
Parameter(
|
Parameter(
|
||||||
name = "tag",
|
name = "tag",
|
||||||
`in` = Parameter.Location.query,
|
`in` = Parameter.Location.query,
|
||||||
schema = TypeDefinition.INT,
|
schema = TypeDefinition.STRING,
|
||||||
description = "The tag IDs to filter the latest announcements by",
|
description = "The tags to filter the latest announcements by",
|
||||||
required = false,
|
required = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -228,8 +223,8 @@ private fun Route.installAnnouncementsLatestIdRouteDocumentation() = installNota
|
|||||||
Parameter(
|
Parameter(
|
||||||
name = "tag",
|
name = "tag",
|
||||||
`in` = Parameter.Location.query,
|
`in` = Parameter.Location.query,
|
||||||
schema = TypeDefinition.INT,
|
schema = TypeDefinition.STRING,
|
||||||
description = "The tag IDs to filter the latest announcements by",
|
description = "The tags to filter the latest announcements by",
|
||||||
required = false,
|
required = false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package app.revanced.api.configuration.routes
|
package app.revanced.api.configuration.routes
|
||||||
|
|
||||||
import app.revanced.api.configuration.installNotarizedRoute
|
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.ApiRelease
|
||||||
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
||||||
import app.revanced.api.configuration.services.ManagerService
|
import app.revanced.api.configuration.services.ManagerService
|
||||||
@@ -53,7 +52,7 @@ private fun Route.installManagerRouteDocumentation(deprecated: Boolean) = instal
|
|||||||
description("The latest manager release")
|
description("The latest manager release")
|
||||||
mediaTypes("application/json")
|
mediaTypes("application/json")
|
||||||
responseCode(HttpStatusCode.OK)
|
responseCode(HttpStatusCode.OK)
|
||||||
responseType<ApiRelease<ApiManagerAsset>>()
|
responseType<ApiRelease>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ package app.revanced.api.configuration.routes
|
|||||||
|
|
||||||
import app.revanced.api.configuration.installCache
|
import app.revanced.api.configuration.installCache
|
||||||
import app.revanced.api.configuration.installNotarizedRoute
|
import app.revanced.api.configuration.installNotarizedRoute
|
||||||
import app.revanced.api.configuration.schema.ApiAssetPublicKeys
|
import app.revanced.api.configuration.schema.ApiAssetPublicKey
|
||||||
import app.revanced.api.configuration.schema.ApiPatchesAsset
|
|
||||||
import app.revanced.api.configuration.schema.ApiRelease
|
import app.revanced.api.configuration.schema.ApiRelease
|
||||||
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
||||||
import app.revanced.api.configuration.services.PatchesService
|
import app.revanced.api.configuration.services.PatchesService
|
||||||
@@ -61,7 +60,7 @@ private fun Route.configure(deprecated: Boolean = false) {
|
|||||||
installPatchesPublicKeyRouteDocumentation(deprecated)
|
installPatchesPublicKeyRouteDocumentation(deprecated)
|
||||||
|
|
||||||
get {
|
get {
|
||||||
call.respond(patchesService.publicKeys())
|
call.respond(patchesService.publicKey())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +77,7 @@ private fun Route.installPatchesRouteDocumentation(deprecated: Boolean) = instal
|
|||||||
description("The current patches release")
|
description("The current patches release")
|
||||||
mediaTypes("application/json")
|
mediaTypes("application/json")
|
||||||
responseCode(HttpStatusCode.OK)
|
responseCode(HttpStatusCode.OK)
|
||||||
responseType<ApiRelease<ApiPatchesAsset>>()
|
responseType<ApiRelease>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,13 +119,13 @@ private fun Route.installPatchesPublicKeyRouteDocumentation(deprecated: Boolean)
|
|||||||
|
|
||||||
get = GetInfo.builder {
|
get = GetInfo.builder {
|
||||||
if (deprecated) isDeprecated()
|
if (deprecated) isDeprecated()
|
||||||
description("Get the public keys for verifying patches and integrations assets")
|
description("Get the public keys for verifying patches assets")
|
||||||
summary("Get patches and integrations public keys")
|
summary("Get patches public keys")
|
||||||
response {
|
response {
|
||||||
description("The public keys")
|
description("The public keys")
|
||||||
mediaTypes("application/json")
|
mediaTypes("application/json")
|
||||||
responseCode(HttpStatusCode.OK)
|
responseCode(HttpStatusCode.OK)
|
||||||
responseType<ApiAssetPublicKeys>()
|
responseType<ApiAssetPublicKey>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,38 +35,20 @@ class ApiContributor(
|
|||||||
@Serializable
|
@Serializable
|
||||||
class APIContributable(
|
class APIContributable(
|
||||||
val name: String,
|
val name: String,
|
||||||
|
val url: String,
|
||||||
// Using a list instead of a set because set semantics are unnecessary here.
|
// Using a list instead of a set because set semantics are unnecessary here.
|
||||||
val contributors: List<ApiContributor>,
|
val contributors: List<ApiContributor>,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class ApiRelease<T>(
|
class ApiRelease(
|
||||||
val version: String,
|
val version: String,
|
||||||
val createdAt: LocalDateTime,
|
val createdAt: LocalDateTime,
|
||||||
val description: String,
|
val description: String,
|
||||||
// Using a list instead of a set because set semantics are unnecessary here.
|
|
||||||
val assets: List<T>,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class ApiManagerAsset(
|
|
||||||
val downloadUrl: String,
|
val downloadUrl: String,
|
||||||
|
val signatureDownloadUrl: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
|
||||||
class ApiPatchesAsset(
|
|
||||||
val downloadUrl: String,
|
|
||||||
val signatureDownloadUrl: String,
|
|
||||||
// TODO: Remove this eventually when integrations are merged into patches.
|
|
||||||
val name: ApiAssetName,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
enum class ApiAssetName {
|
|
||||||
PATCHES,
|
|
||||||
INTEGRATION,
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class ApiReleaseVersion(
|
class ApiReleaseVersion(
|
||||||
val version: String,
|
val version: String,
|
||||||
@@ -94,7 +76,7 @@ class ApiResponseAnnouncement(
|
|||||||
// Using a list instead of a set because set semantics are unnecessary here.
|
// Using a list instead of a set because set semantics are unnecessary here.
|
||||||
val attachments: List<String> = emptyList(),
|
val attachments: List<String> = emptyList(),
|
||||||
// Using a list instead of a set because set semantics are unnecessary here.
|
// Using a list instead of a set because set semantics are unnecessary here.
|
||||||
val tags: List<Int> = emptyList(),
|
val tags: List<String> = emptyList(),
|
||||||
val createdAt: LocalDateTime,
|
val createdAt: LocalDateTime,
|
||||||
val archivedAt: LocalDateTime? = null,
|
val archivedAt: LocalDateTime? = null,
|
||||||
val level: Int = 0,
|
val level: Int = 0,
|
||||||
@@ -112,7 +94,6 @@ class ApiAnnouncementArchivedAt(
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class ApiAnnouncementTag(
|
class ApiAnnouncementTag(
|
||||||
val id: Int,
|
|
||||||
val name: String,
|
val name: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,9 +105,8 @@ class ApiRateLimit(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class ApiAssetPublicKeys(
|
class ApiAssetPublicKey(
|
||||||
val patchesPublicKey: String,
|
val patchesPublicKey: String,
|
||||||
val integrationsPublicKey: String,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import app.revanced.api.configuration.schema.ApiAnnouncement
|
|||||||
internal class AnnouncementService(
|
internal class AnnouncementService(
|
||||||
private val announcementRepository: AnnouncementRepository,
|
private val announcementRepository: AnnouncementRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun latest(tags: Set<Int>) = announcementRepository.latest(tags)
|
suspend fun latest(tags: Set<String>) = announcementRepository.latest(tags)
|
||||||
|
|
||||||
suspend fun latest() = announcementRepository.latest()
|
suspend fun latest() = announcementRepository.latest()
|
||||||
|
|
||||||
fun latestId(tags: Set<Int>) = announcementRepository.latestId(tags)
|
fun latestId(tags: Set<String>) = announcementRepository.latestId(tags)
|
||||||
|
|
||||||
fun latestId() = announcementRepository.latestId()
|
fun latestId() = announcementRepository.latestId()
|
||||||
|
|
||||||
suspend fun paged(cursor: Int, limit: Int, tags: Set<Int>?, archived: Boolean) =
|
suspend fun paged(cursor: Int, limit: Int, tags: Set<String>?) =
|
||||||
announcementRepository.paged(cursor, limit, tags, archived)
|
announcementRepository.paged(cursor, limit, tags)
|
||||||
|
|
||||||
suspend fun get(id: Int) = announcementRepository.get(id)
|
suspend fun get(id: Int) = announcementRepository.get(id)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package app.revanced.api.configuration.services
|
|||||||
import app.revanced.api.configuration.repository.BackendRepository
|
import app.revanced.api.configuration.repository.BackendRepository
|
||||||
import app.revanced.api.configuration.repository.ConfigurationRepository
|
import app.revanced.api.configuration.repository.ConfigurationRepository
|
||||||
import app.revanced.api.configuration.schema.*
|
import app.revanced.api.configuration.schema.*
|
||||||
|
import io.ktor.http.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.awaitAll
|
import kotlinx.coroutines.awaitAll
|
||||||
@@ -16,11 +17,15 @@ internal class ApiService(
|
|||||||
val about = configurationRepository.about
|
val about = configurationRepository.about
|
||||||
|
|
||||||
suspend fun contributors() = withContext(Dispatchers.IO) {
|
suspend fun contributors() = withContext(Dispatchers.IO) {
|
||||||
configurationRepository.contributorsRepositoryNames.map {
|
configurationRepository.contributorsRepositoryNames.map { (repository, name) ->
|
||||||
async {
|
async {
|
||||||
APIContributable(
|
APIContributable(
|
||||||
it,
|
name,
|
||||||
backendRepository.contributors(configurationRepository.organization, it).map {
|
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)
|
ApiContributor(it.name, it.avatarUrl, it.url, it.contributions)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,27 +3,24 @@ package app.revanced.api.configuration.services
|
|||||||
import app.revanced.api.configuration.repository.BackendRepository
|
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.BackendRepository.BackendOrganization.BackendRepository.BackendRelease.Companion.first
|
||||||
import app.revanced.api.configuration.repository.ConfigurationRepository
|
import app.revanced.api.configuration.repository.ConfigurationRepository
|
||||||
import app.revanced.api.configuration.schema.*
|
import app.revanced.api.configuration.schema.ApiRelease
|
||||||
|
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
||||||
|
|
||||||
internal class ManagerService(
|
internal class ManagerService(
|
||||||
private val backendRepository: BackendRepository,
|
private val backendRepository: BackendRepository,
|
||||||
private val configurationRepository: ConfigurationRepository,
|
private val configurationRepository: ConfigurationRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun latestRelease(): ApiRelease<ApiManagerAsset> {
|
suspend fun latestRelease(): ApiRelease {
|
||||||
val managerRelease = backendRepository.release(
|
val managerRelease = backendRepository.release(
|
||||||
configurationRepository.organization,
|
configurationRepository.organization,
|
||||||
configurationRepository.manager.repository,
|
configurationRepository.manager.repository,
|
||||||
)
|
)
|
||||||
|
|
||||||
val managerAsset = ApiManagerAsset(
|
|
||||||
managerRelease.assets.first(configurationRepository.manager.assetRegex).downloadUrl,
|
|
||||||
)
|
|
||||||
|
|
||||||
return ApiRelease(
|
return ApiRelease(
|
||||||
managerRelease.tag,
|
managerRelease.tag,
|
||||||
managerRelease.createdAt,
|
managerRelease.createdAt,
|
||||||
managerRelease.releaseNote,
|
managerRelease.releaseNote,
|
||||||
listOf(managerAsset),
|
managerRelease.assets.first(configurationRepository.manager.assetRegex).downloadUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package app.revanced.api.configuration.services
|
package app.revanced.api.configuration.services
|
||||||
|
|
||||||
|
import app.revanced.api.configuration.repository.ConfigurationRepository
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.okhttp.*
|
||||||
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
@@ -11,7 +14,11 @@ import io.ktor.server.response.*
|
|||||||
import io.ktor.util.*
|
import io.ktor.util.*
|
||||||
import io.ktor.utils.io.*
|
import io.ktor.utils.io.*
|
||||||
|
|
||||||
internal class OldApiService(private val client: HttpClient) {
|
internal class OldApiService(configurationRepository: ConfigurationRepository) {
|
||||||
|
private val client = HttpClient(OkHttp) {
|
||||||
|
defaultRequest { url(configurationRepository.oldApiEndpoint) }
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(InternalAPI::class)
|
@OptIn(InternalAPI::class)
|
||||||
suspend fun proxy(call: ApplicationCall) {
|
suspend fun proxy(call: ApplicationCall) {
|
||||||
val channel = call.request.receiveChannel()
|
val channel = call.request.receiveChannel()
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package app.revanced.api.configuration.services
|
|||||||
import app.revanced.api.configuration.repository.BackendRepository
|
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.BackendRepository.BackendOrganization.BackendRepository.BackendRelease.Companion.first
|
||||||
import app.revanced.api.configuration.repository.ConfigurationRepository
|
import app.revanced.api.configuration.repository.ConfigurationRepository
|
||||||
import app.revanced.api.configuration.schema.*
|
import app.revanced.api.configuration.schema.ApiAssetPublicKey
|
||||||
|
import app.revanced.api.configuration.schema.ApiRelease
|
||||||
|
import app.revanced.api.configuration.schema.ApiReleaseVersion
|
||||||
import app.revanced.library.serializeTo
|
import app.revanced.library.serializeTo
|
||||||
import app.revanced.patcher.patch.loadPatchesFromJar
|
import app.revanced.patcher.patch.loadPatchesFromJar
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
@@ -17,40 +19,18 @@ internal class PatchesService(
|
|||||||
private val backendRepository: BackendRepository,
|
private val backendRepository: BackendRepository,
|
||||||
private val configurationRepository: ConfigurationRepository,
|
private val configurationRepository: ConfigurationRepository,
|
||||||
) {
|
) {
|
||||||
suspend fun latestRelease(): ApiRelease<ApiPatchesAsset> {
|
suspend fun latestRelease(): ApiRelease {
|
||||||
val patchesRelease = backendRepository.release(
|
val patchesRelease = backendRepository.release(
|
||||||
configurationRepository.organization,
|
configurationRepository.organization,
|
||||||
configurationRepository.patches.repository,
|
configurationRepository.patches.repository,
|
||||||
)
|
)
|
||||||
|
|
||||||
val integrationsRelease = backendRepository.release(
|
|
||||||
configurationRepository.organization,
|
|
||||||
configurationRepository.integrations.repository,
|
|
||||||
)
|
|
||||||
|
|
||||||
fun ConfigurationRepository.SignedAssetConfiguration.asset(
|
|
||||||
release: BackendRepository.BackendOrganization.BackendRepository.BackendRelease,
|
|
||||||
assetName: ApiAssetName,
|
|
||||||
) = ApiPatchesAsset(
|
|
||||||
release.assets.first(assetRegex).downloadUrl,
|
|
||||||
release.assets.first(signatureAssetRegex).downloadUrl,
|
|
||||||
assetName,
|
|
||||||
)
|
|
||||||
|
|
||||||
val patchesAsset = configurationRepository.patches.asset(
|
|
||||||
patchesRelease,
|
|
||||||
ApiAssetName.PATCHES,
|
|
||||||
)
|
|
||||||
val integrationsAsset = configurationRepository.integrations.asset(
|
|
||||||
integrationsRelease,
|
|
||||||
ApiAssetName.INTEGRATION,
|
|
||||||
)
|
|
||||||
|
|
||||||
return ApiRelease(
|
return ApiRelease(
|
||||||
patchesRelease.tag,
|
patchesRelease.tag,
|
||||||
patchesRelease.createdAt,
|
patchesRelease.createdAt,
|
||||||
patchesRelease.releaseNote,
|
patchesRelease.releaseNote,
|
||||||
listOf(patchesAsset, integrationsAsset),
|
patchesRelease.assets.first(configurationRepository.patches.assetRegex).downloadUrl,
|
||||||
|
patchesRelease.assets.first(configurationRepository.patches.signatureAssetRegex).downloadUrl,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +91,5 @@ internal class PatchesService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun publicKeys(): ApiAssetPublicKeys {
|
fun publicKey() = ApiAssetPublicKey(configurationRepository.patches.publicKeyFile.readText())
|
||||||
fun readPublicKey(
|
|
||||||
getSignedAssetConfiguration: ConfigurationRepository.() -> ConfigurationRepository.SignedAssetConfiguration,
|
|
||||||
) = configurationRepository.getSignedAssetConfiguration().publicKeyFile.readText()
|
|
||||||
|
|
||||||
return ApiAssetPublicKeys(
|
|
||||||
readPublicKey { patches },
|
|
||||||
readPublicKey { integrations },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.security.MessageDigest
|
|||||||
internal class SignatureService {
|
internal class SignatureService {
|
||||||
private val signatureCache = Caffeine
|
private val signatureCache = Caffeine
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.maximumSize(2) // Assuming this is enough for patches and integrations.
|
.maximumSize(1) // 1 because currently only the latest patches is needed.
|
||||||
.build<ByteArray, Boolean>() // Hash -> Verified.
|
.build<ByteArray, Boolean>() // Hash -> Verified.
|
||||||
|
|
||||||
fun verify(
|
fun verify(
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import app.revanced.api.configuration.schema.ApiAnnouncement
|
|||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.datetime.toKotlinLocalDateTime
|
import kotlinx.datetime.toKotlinLocalDateTime
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
|
||||||
import org.junit.jupiter.api.*
|
|
||||||
import org.junit.jupiter.api.Assertions.assertNull
|
import org.junit.jupiter.api.Assertions.assertNull
|
||||||
|
import org.junit.jupiter.api.BeforeAll
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
@@ -18,10 +19,9 @@ private object AnnouncementServiceTest {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
TransactionManager.defaultDatabase =
|
val database = Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false")
|
||||||
Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false")
|
|
||||||
|
|
||||||
announcementService = AnnouncementService(AnnouncementRepository())
|
announcementService = AnnouncementService(AnnouncementRepository(database))
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -86,27 +86,22 @@ private object AnnouncementServiceTest {
|
|||||||
announcementService.new(ApiAnnouncement(title = "2", tags = listOf("tag1", "tag3")))
|
announcementService.new(ApiAnnouncement(title = "2", tags = listOf("tag1", "tag3")))
|
||||||
announcementService.new(ApiAnnouncement(title = "3", tags = listOf("tag1", "tag4")))
|
announcementService.new(ApiAnnouncement(title = "3", tags = listOf("tag1", "tag4")))
|
||||||
|
|
||||||
val tag2 = announcementService.tags().find { it.name == "tag2" }!!.id
|
assert(announcementService.latest(setOf("tag2")).first().title == "1")
|
||||||
assert(announcementService.latest(setOf(tag2)).first().title == "1")
|
assert(announcementService.latest(setOf("tag3")).last().title == "2")
|
||||||
|
|
||||||
val tag3 = announcementService.tags().find { it.name == "tag3" }!!.id
|
val announcement2and3 = announcementService.latest(setOf("tag1", "tag3"))
|
||||||
assert(announcementService.latest(setOf(tag3)).last().title == "2")
|
|
||||||
|
|
||||||
val tag1and3 =
|
|
||||||
announcementService.tags().filter { it.name == "tag1" || it.name == "tag3" }.map { it.id }.toSet()
|
|
||||||
val announcement2and3 = announcementService.latest(tag1and3)
|
|
||||||
assert(announcement2and3.size == 2)
|
assert(announcement2and3.size == 2)
|
||||||
assert(announcement2and3.any { it.title == "2" })
|
assert(announcement2and3.any { it.title == "2" })
|
||||||
assert(announcement2and3.any { it.title == "3" })
|
assert(announcement2and3.any { it.title == "3" })
|
||||||
|
|
||||||
announcementService.delete(announcementService.latestId()!!.id)
|
announcementService.delete(announcementService.latestId()!!.id)
|
||||||
assert(announcementService.latest(tag1and3).first().title == "2")
|
assert(announcementService.latest(setOf("tag1", "tag3")).first().title == "2")
|
||||||
|
|
||||||
announcementService.delete(announcementService.latestId()!!.id)
|
announcementService.delete(announcementService.latestId()!!.id)
|
||||||
assert(announcementService.latest(tag1and3).first().title == "1")
|
assert(announcementService.latest(setOf("tag1", "tag3")).first().title == "1")
|
||||||
|
|
||||||
announcementService.delete(announcementService.latestId()!!.id)
|
announcementService.delete(announcementService.latestId()!!.id)
|
||||||
assert(announcementService.latest(tag1and3).isEmpty())
|
assert(announcementService.latest(setOf("tag1", "tag3")).isEmpty())
|
||||||
assert(announcementService.tags().isEmpty())
|
assert(announcementService.tags().isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,11 +153,11 @@ private object AnnouncementServiceTest {
|
|||||||
announcementService.new(ApiAnnouncement(title = "title$it"))
|
announcementService.new(ApiAnnouncement(title = "title$it"))
|
||||||
}
|
}
|
||||||
|
|
||||||
val announcements = announcementService.paged(Int.MAX_VALUE, 5, null, true)
|
val announcements = announcementService.paged(Int.MAX_VALUE, 5, null)
|
||||||
assertEquals(5, announcements.size, "Returns correct number of announcements")
|
assertEquals(5, announcements.size, "Returns correct number of announcements")
|
||||||
assertEquals("title9", announcements.first().title, "Starts from the latest announcement")
|
assertEquals("title9", announcements.first().title, "Starts from the latest announcement")
|
||||||
|
|
||||||
val announcements2 = announcementService.paged(5, 5, null, true)
|
val announcements2 = announcementService.paged(5, 5, null)
|
||||||
assertEquals(5, announcements2.size, "Returns correct number of announcements when starting from the cursor")
|
assertEquals(5, announcements2.size, "Returns correct number of announcements when starting from the cursor")
|
||||||
assertEquals("title4", announcements2.first().title, "Starts from the cursor")
|
assertEquals("title4", announcements2.first().title, "Starts from the cursor")
|
||||||
|
|
||||||
@@ -185,10 +180,7 @@ private object AnnouncementServiceTest {
|
|||||||
val tags = announcementService.tags()
|
val tags = announcementService.tags()
|
||||||
assertEquals(5, tags.size, "Returns correct number of newly created tags")
|
assertEquals(5, tags.size, "Returns correct number of newly created tags")
|
||||||
|
|
||||||
val announcements3 = announcementService.paged(5, 5, setOf(tags[1].id), true)
|
val announcements3 = announcementService.paged(5, 5, setOf(tags[1].name))
|
||||||
assertEquals(4, announcements3.size, "Filters announcements by tag")
|
assertEquals(4, announcements3.size, "Filters announcements by tag")
|
||||||
|
|
||||||
val announcements4 = announcementService.paged(Int.MAX_VALUE, 10, null, false)
|
|
||||||
assertEquals(8, announcements4.size, "Filters out archived announcements")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user