Skip to content

Commit 64f9431

Browse files
authored
feat: Add downloaders route (#208)
1 parent 9525a16 commit 64f9431

5 files changed

Lines changed: 109 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Some of the features ReVanced API include:
7979
- 📢 **Announcements**: Post and get announcements
8080
- ℹ️ **About**: Get more information such as a description, ways to donate to,
8181
and links of the hoster of ReVanced API
82+
- 💊 **Manager**: Get the latest updates of ReVanced Manager and its downloaders
8283
- 🧩 **Patches**: Get the latest updates of ReVanced Patches, directly from ReVanced API
8384
- 👥 **Contributors**: List all contributors involved in the project
8485

configuration.example.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public-key-id = 3897925568445097277
2020
[manager]
2121
repository = "revanced-manager"
2222
asset-regex = "apk$"
23+
downloaders-repository = "revanced-manager-downloaders"
24+
downloaders-asset-regex = "apk$"
2325

2426
[contributors-repositories]
2527
revanced-patcher = "ReVanced Patcher"

src/main/kotlin/app/revanced/api/configuration/repository/ConfigurationRepository.kt

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import kotlin.io.path.createDirectories
2323
* The repository storing the configuration for the API.
2424
*
2525
* @property organization The API backends organization name where the repositories are.
26-
* @property patches The source of the patches.
27-
* @property manager The source of the manager.
26+
* @property patches The configuration for patches.
27+
* @property manager The configuration for the manager.
2828
* @property contributorsRepositoryNames The friendly name of repos mapped to the repository names to get contributors from.
2929
* @property backendServiceName The name of the backend service to use for the repositories, contributors, etc.
3030
* @property apiVersion The version to use for the API.
@@ -38,8 +38,8 @@ import kotlin.io.path.createDirectories
3838
@Serializable
3939
internal class ConfigurationRepository(
4040
val organization: String,
41-
val patches: SignedAssetConfiguration,
42-
val manager: AssetConfiguration,
41+
val patches: PatchesConfiguration,
42+
val manager: ManagerConfiguration,
4343
@SerialName("contributors-repositories")
4444
val contributorsRepositoryNames: Map<String, String>,
4545
@SerialName("backend-service-name")
@@ -65,22 +65,20 @@ internal class ConfigurationRepository(
6565
}
6666

6767
/**
68-
* Am asset configuration whose asset is signed.
68+
* A configuration for [PatchesService].
6969
*
70-
* [PatchesService] for example uses [BackendRepository] to get assets from its releases.
71-
* A release contains multiple assets.
72-
*
73-
* This configuration is used in [ConfigurationRepository]
74-
* to determine which release assets from repositories to get and to verify them.
75-
*
76-
* @property repository The repository in which releases are made to get an asset.
77-
* @property assetRegex The regex matching the asset name.
78-
* @property signatureAssetRegex The regex matching the signature asset name to verify the asset.
79-
* @property publicKeyFile The public key file to verify the signature of the asset.
80-
* @property publicKeyId The ID of the public key to verify the signature of the asset.
70+
* @property repository The patches repository.
71+
* @property assetRegex The regex matching the patches asset name
72+
* in releases from the patches repository.
73+
* @property signatureAssetRegex The regex matching the patches signature asset name
74+
* in releases from the patches repository.
75+
* @property publicKeyFile The public key file to verify the signature of the patches asset
76+
* in releases from the patches repository.
77+
* @property publicKeyId The ID of the public key to verify the signature of the patches asset
78+
* in releases from the patches repository.
8179
*/
8280
@Serializable
83-
internal class SignedAssetConfiguration(
81+
internal class PatchesConfiguration(
8482
val repository: String,
8583
@Serializable(with = RegexSerializer::class)
8684
@SerialName("asset-regex")
@@ -96,23 +94,26 @@ internal class ConfigurationRepository(
9694
)
9795

9896
/**
99-
* Am asset configuration.
100-
*
101-
* [ManagerService] for example uses [BackendRepository] to get assets from its releases.
102-
* A release contains multiple assets.
103-
*
104-
* This configuration is used in [ConfigurationRepository]
105-
* to determine which release assets from repositories to get and to verify them.
106-
*
107-
* @property repository The repository in which releases are made to get an asset.
108-
* @property assetRegex The regex matching the asset name.
97+
* A configuration for [ManagerService].
98+
99+
* @property repository The manager repository.
100+
* @property assetRegex The regex matching the manager asset name
101+
* in releases from the manager repository.
102+
* @property downloadersRepository The manager downloaders repository.
103+
* @property downloadersAssetRegex The regex matching the manager downloaders asset name
104+
* in releases from the manager downloaders repository.
109105
*/
110106
@Serializable
111-
internal class AssetConfiguration(
107+
internal class ManagerConfiguration(
112108
val repository: String,
113109
@Serializable(with = RegexSerializer::class)
114110
@SerialName("asset-regex")
115111
val assetRegex: Regex,
112+
@SerialName("downloaders-repository")
113+
val downloadersRepository: String,
114+
@Serializable(with = RegexSerializer::class)
115+
@SerialName("downloaders-asset-regex")
116+
val downloadersAssetRegex: Regex,
116117
)
117118
}
118119

src/main/kotlin/app/revanced/api/configuration/routes/ManagerRoute.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ internal fun Route.managerRoute() = route("manager") {
3535
call.respond(managerService.latestVersion(prerelease))
3636
}
3737
}
38+
39+
route("downloaders") {
40+
installManagerDownloadersRouteDocumentation()
41+
42+
get {
43+
val prerelease = call.parameters["prerelease"]?.toBoolean() ?: false
44+
45+
call.respond(managerService.latestDownloadersRelease(prerelease))
46+
}
47+
48+
route("version") {
49+
installManagerDownloadersVersionRouteDocumentation()
50+
51+
get {
52+
val prerelease = call.parameters["prerelease"]?.toBoolean() ?: false
53+
54+
call.respond(managerService.latestDownloadersVersion(prerelease))
55+
}
56+
}
57+
}
3858
}
3959
}
4060

@@ -77,3 +97,35 @@ private fun Route.installManagerVersionRouteDocumentation() = installNotarizedRo
7797
}
7898
}
7999
}
100+
101+
private fun Route.installManagerDownloadersRouteDocumentation() = installNotarizedRoute {
102+
tags = setOf("Manager")
103+
104+
get = GetInfo.builder {
105+
description("Get the current manager downloaders release")
106+
summary("Get current manager downloaders release")
107+
parameters(prereleaseParameter)
108+
response {
109+
description("The latest manager downloaders release")
110+
mediaTypes("application/json")
111+
responseCode(HttpStatusCode.OK)
112+
responseType<ApiRelease>()
113+
}
114+
}
115+
}
116+
117+
private fun Route.installManagerDownloadersVersionRouteDocumentation() = installNotarizedRoute {
118+
tags = setOf("Manager")
119+
120+
get = GetInfo.builder {
121+
description("Get the current manager downloaders release version")
122+
summary("Get current manager downloaders release version")
123+
parameters(prereleaseParameter)
124+
response {
125+
description("The current manager downloaders release version")
126+
mediaTypes("application/json")
127+
responseCode(HttpStatusCode.OK)
128+
responseType<ApiReleaseVersion>()
129+
}
130+
}
131+
}

src/main/kotlin/app/revanced/api/configuration/services/ManagerService.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,29 @@ internal class ManagerService(
3434

3535
return ApiReleaseVersion(managerRelease.tag)
3636
}
37+
38+
suspend fun latestDownloadersRelease(prerelease: Boolean): ApiRelease {
39+
val downloaderPluginsRelease = backendRepository.release(
40+
configurationRepository.organization,
41+
configurationRepository.manager.downloadersRepository,
42+
prerelease,
43+
)
44+
45+
return ApiRelease(
46+
downloaderPluginsRelease.tag,
47+
downloaderPluginsRelease.createdAt,
48+
downloaderPluginsRelease.releaseNote,
49+
downloaderPluginsRelease.assets.first(configurationRepository.manager.downloadersAssetRegex).downloadUrl,
50+
)
51+
}
52+
53+
suspend fun latestDownloadersVersion(prerelease: Boolean): ApiReleaseVersion {
54+
val downloaderPluginsRelease = backendRepository.release(
55+
configurationRepository.organization,
56+
configurationRepository.manager.downloadersRepository,
57+
prerelease,
58+
)
59+
60+
return ApiReleaseVersion(downloaderPluginsRelease.tag)
61+
}
3762
}

0 commit comments

Comments
 (0)