[build] Encode URL parts to escape HTML chars for build-index

This commit is contained in:
Him188 2023-03-19 15:03:23 +00:00
parent 43b5e710ef
commit 9b86d3be8f
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2019-2022 Mamoe Technologies and contributors. * Copyright 2019-2023 Mamoe Technologies and contributors.
* *
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@ -52,13 +52,14 @@ suspend fun HttpClient.getExistingIndex(
commitRef: String, commitRef: String,
): Index? { ): Index? {
// https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39 // https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39
val resp = get("https://build.mirai.mamoe.net/v1/$module/$branch/indexes/") { val resp =
basicAuth( get("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}/indexes/") {
System.getenv("mirai.build.index.auth.username"), basicAuth(
System.getenv("mirai.build.index.auth.password") System.getenv("mirai.build.index.auth.username"),
) System.getenv("mirai.build.index.auth.password")
parameter("commitRef", commitRef) )
} parameter("commitRef", commitRef)
}
if (!resp.status.isSuccess()) { if (!resp.status.isSuccess()) {
val body = runCatching { resp.bodyAsText() }.getOrNull() val body = runCatching { resp.bodyAsText() }.getOrNull()
throw IllegalStateException("Request failed: ${resp.status} $body") throw IllegalStateException("Request failed: ${resp.status} $body")
@ -74,7 +75,7 @@ suspend fun HttpClient.createBranch(
branch: String, branch: String,
): Boolean { ): Boolean {
// https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39 // https://build.mirai.mamoe.net/v1/mirai-core/dev/indexes/?commitRef=29121565132bed6e996f3de32faaf49106ae8e39
val resp = put("https://build.mirai.mamoe.net/v1/$module/$branch") { val resp = put("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}") {
basicAuth( basicAuth(
System.getenv("mirai.build.index.auth.username"), System.getenv("mirai.build.index.auth.username"),
System.getenv("mirai.build.index.auth.password") System.getenv("mirai.build.index.auth.password")
@ -88,13 +89,14 @@ suspend fun HttpClient.postNextIndex(
branch: String, branch: String,
commitRef: String, commitRef: String,
): Index { ): Index {
val resp = post("https://build.mirai.mamoe.net/v1/$module/$branch/indexes/next") { val resp =
basicAuth( post("https://build.mirai.mamoe.net/v1/${module.encodeURLPathPart()}/${branch.encodeURLPathPart()}/indexes/next") {
System.getenv("mirai.build.index.auth.username"), basicAuth(
System.getenv("mirai.build.index.auth.password") System.getenv("mirai.build.index.auth.username"),
) System.getenv("mirai.build.index.auth.password")
parameter("commitRef", commitRef) )
} parameter("commitRef", commitRef)
}
if (!resp.status.isSuccess()) { if (!resp.status.isSuccess()) {
val body = runCatching { resp.bodyAsText() }.getOrNull() val body = runCatching { resp.bodyAsText() }.getOrNull()
throw IllegalStateException("Request failed: ${resp.status} $body") throw IllegalStateException("Request failed: ${resp.status} $body")