Skip to content

Commit

Permalink
feat: Remove ReVanced Integrations
Browse files Browse the repository at this point in the history
There is no need for them anymore in Patcher v20+
  • Loading branch information
oSumAtrIX committed Nov 1, 2024
1 parent a5498ab commit f1c1092
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 90 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ persistence/
configuration.toml
docker-compose.yml
patches-public-key.asc
integrations-public-key.asc
node_modules/
static/
about.json
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ API server for ReVanced.
## ❓ About

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.

## 💪 Features

Some of the features ReVanced API include:

- 📢 **Announcements**: Post and get announcements
- ℹ️ **About**: Get more information such as a description, ways to donate to,
and links of the hoster of ReVanced API
- ℹ️ **About**: Get more information such as a description, ways to donate to,
and links of the hoster of ReVanced API
- 🧩 **Patches**: Get the latest updates of ReVanced Patches, directly from ReVanced API
- 👥 **Contributors**: List all contributors involved in the project
- 🔄 **Backwards compatibility**: Proxy an old API for migration purposes and backwards compatibility
Expand All @@ -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.
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

Expand All @@ -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 \
# Mount the patches public key
-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
-v $(pwd)/static:/app/static \
# Mount the about.json file
Expand All @@ -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
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
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
5. Run `java -jar revanced-api.jar start` to start the server

Expand All @@ -159,7 +159,8 @@ A Java Development Kit (JDK) and Git must be installed.

### 📙 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

Expand Down
1 change: 0 additions & 1 deletion configuration.example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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$" }
api-version = 1
cors-allowed-hosts = [
Expand Down
1 change: 0 additions & 1 deletion docker-compose.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
- /data/revanced-api/.env:/app/.env
- /data/revanced-api/configuration.toml:/app/configuration.toml
- /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/about.json:/app/about.json
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import kotlin.io.path.createDirectories
/**
* 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 integrations The source of the integrations.
* @property manager The source of the manager.
* @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.
Expand All @@ -41,7 +40,6 @@ import kotlin.io.path.createDirectories
internal class ConfigurationRepository(
val organization: String,
val patches: SignedAssetConfiguration,
val integrations: SignedAssetConfiguration,
val manager: AssetConfiguration,
@SerialName("contributors-repositories")
val contributorsRepositoryNames: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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
Expand Down Expand Up @@ -53,7 +52,7 @@ private fun Route.installManagerRouteDocumentation(deprecated: Boolean) = instal
description("The latest manager release")
mediaTypes("application/json")
responseCode(HttpStatusCode.OK)
responseType<ApiRelease<ApiManagerAsset>>()
responseType<ApiRelease>()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package app.revanced.api.configuration.routes

import app.revanced.api.configuration.installCache
import app.revanced.api.configuration.installNotarizedRoute
import app.revanced.api.configuration.schema.ApiAssetPublicKeys
import app.revanced.api.configuration.schema.ApiPatchesAsset
import app.revanced.api.configuration.schema.ApiAssetPublicKey
import app.revanced.api.configuration.schema.ApiRelease
import app.revanced.api.configuration.schema.ApiReleaseVersion
import app.revanced.api.configuration.services.PatchesService
Expand Down Expand Up @@ -61,7 +60,7 @@ private fun Route.configure(deprecated: Boolean = false) {
installPatchesPublicKeyRouteDocumentation(deprecated)

get {
call.respond(patchesService.publicKeys())
call.respond(patchesService.publicKey())
}
}
}
Expand All @@ -78,7 +77,7 @@ private fun Route.installPatchesRouteDocumentation(deprecated: Boolean) = instal
description("The current patches release")
mediaTypes("application/json")
responseCode(HttpStatusCode.OK)
responseType<ApiRelease<ApiPatchesAsset>>()
responseType<ApiRelease>()
}
}
}
Expand Down Expand Up @@ -120,13 +119,13 @@ private fun Route.installPatchesPublicKeyRouteDocumentation(deprecated: Boolean)

get = GetInfo.builder {
if (deprecated) isDeprecated()
description("Get the public keys for verifying patches and integrations assets")
summary("Get patches and integrations public keys")
description("Get the public keys for verifying patches assets")
summary("Get patches public keys")
response {
description("The public keys")
mediaTypes("application/json")
responseCode(HttpStatusCode.OK)
responseType<ApiAssetPublicKeys>()
responseType<ApiAssetPublicKey>()
}
}
}
26 changes: 3 additions & 23 deletions src/main/kotlin/app/revanced/api/configuration/schema/APISchema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,14 @@ class APIContributable(
)

@Serializable
class ApiRelease<T>(
class ApiRelease(
val version: String,
val createdAt: LocalDateTime,
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 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
class ApiReleaseVersion(
val version: String,
Expand Down Expand Up @@ -125,9 +106,8 @@ class ApiRateLimit(
)

@Serializable
class ApiAssetPublicKeys(
class ApiAssetPublicKey(
val patchesPublicKey: String,
val integrationsPublicKey: String,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@ 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.*
import app.revanced.api.configuration.schema.ApiRelease
import app.revanced.api.configuration.schema.ApiReleaseVersion

internal class ManagerService(
private val backendRepository: BackendRepository,
private val configurationRepository: ConfigurationRepository,
) {
suspend fun latestRelease(): ApiRelease<ApiManagerAsset> {
suspend fun latestRelease(): ApiRelease {
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),
managerRelease.assets.first(configurationRepository.manager.assetRegex).downloadUrl,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ 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.*
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.patcher.patch.loadPatchesFromJar
import com.github.benmanes.caffeine.cache.Caffeine
Expand All @@ -17,40 +19,18 @@ internal class PatchesService(
private val backendRepository: BackendRepository,
private val configurationRepository: ConfigurationRepository,
) {
suspend fun latestRelease(): ApiRelease<ApiPatchesAsset> {
suspend fun latestRelease(): ApiRelease {
val patchesRelease = backendRepository.release(
configurationRepository.organization,
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(
patchesRelease.tag,
patchesRelease.createdAt,
patchesRelease.releaseNote,
listOf(patchesAsset, integrationsAsset),
patchesRelease.assets.first(configurationRepository.patches.assetRegex).downloadUrl,
patchesRelease.assets.first(configurationRepository.patches.signatureAssetRegex).downloadUrl,
)
}

Expand Down Expand Up @@ -111,14 +91,5 @@ internal class PatchesService(
}
}

fun publicKeys(): ApiAssetPublicKeys {
fun readPublicKey(
getSignedAssetConfiguration: ConfigurationRepository.() -> ConfigurationRepository.SignedAssetConfiguration,
) = configurationRepository.getSignedAssetConfiguration().publicKeyFile.readText()

return ApiAssetPublicKeys(
readPublicKey { patches },
readPublicKey { integrations },
)
}
fun publicKey() = ApiAssetPublicKey(configurationRepository.patches.publicKeyFile.readText())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.security.MessageDigest
internal class SignatureService {
private val signatureCache = Caffeine
.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.

fun verify(
Expand Down

0 comments on commit f1c1092

Please sign in to comment.