aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo/RepoDownloadManager.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-10-13 22:10:38 +0200
committerLinnea Gräf <nea@nea.moe>2025-10-13 22:10:38 +0200
commit733f01be8c2ca986e594816e73cb89ee1c8d105d (patch)
tree7709f194f714b0bcfdbab0c65ec5aa7b3fe49c14 /src/main/kotlin/repo/RepoDownloadManager.kt
parent05160314e6899ece75779dbd2e5b691ed581c2b9 (diff)
downloadFirmament-733f01be8c2ca986e594816e73cb89ee1c8d105d.tar.gz
Firmament-733f01be8c2ca986e594816e73cb89ee1c8d105d.tar.bz2
Firmament-733f01be8c2ca986e594816e73cb89ee1c8d105d.zip
feat: remove ktor (for a smaller binary)
Diffstat (limited to 'src/main/kotlin/repo/RepoDownloadManager.kt')
-rw-r--r--src/main/kotlin/repo/RepoDownloadManager.kt21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/main/kotlin/repo/RepoDownloadManager.kt b/src/main/kotlin/repo/RepoDownloadManager.kt
index 150a9ca..36ded5c 100644
--- a/src/main/kotlin/repo/RepoDownloadManager.kt
+++ b/src/main/kotlin/repo/RepoDownloadManager.kt
@@ -1,9 +1,5 @@
package moe.nea.firmament.repo
-import io.ktor.client.call.body
-import io.ktor.client.request.get
-import io.ktor.client.statement.bodyAsChannel
-import io.ktor.utils.io.copyTo
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
@@ -11,6 +7,7 @@ import java.nio.file.StandardOpenOption
import java.util.zip.ZipInputStream
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.future.await
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlin.io.path.createDirectories
@@ -23,6 +20,7 @@ import moe.nea.firmament.Firmament
import moe.nea.firmament.Firmament.logger
import moe.nea.firmament.repo.RepoDownloadManager.latestSavedVersionHash
import moe.nea.firmament.util.iterate
+import moe.nea.firmament.util.net.HttpUtil
object RepoDownloadManager {
@@ -59,18 +57,17 @@ object RepoDownloadManager {
RepoManager.TConfig.branch = "master"
}
val response =
- Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.TConfig.username}/${RepoManager.TConfig.reponame}/commits/${branchOverride ?: RepoManager.TConfig.branch}")
- if (response.status.value != 200) {
- return null
- }
- return response.body<GithubCommitsResponse>().sha
+ HttpUtil.request("https://api.github.com/repos/${RepoManager.TConfig.username}/${RepoManager.TConfig.reponame}/commits/${branchOverride ?: RepoManager.TConfig.branch}")
+ .forJson<GithubCommitsResponse>()
+ .await()
+ return response.sha
}
private suspend fun downloadGithubArchive(url: String): Path = withContext(IO) {
- val response = Firmament.httpClient.get(url)
+ val response = HttpUtil.request(url)
val targetFile = Files.createTempFile("firmament-repo", ".zip")
- val outputChannel = Files.newByteChannel(targetFile, StandardOpenOption.CREATE, StandardOpenOption.WRITE)
- response.bodyAsChannel().copyTo(outputChannel)
+ val outputChannel = Files.newOutputStream(targetFile, StandardOpenOption.CREATE, StandardOpenOption.WRITE)
+ response.forInputStream().await().copyTo(outputChannel)
targetFile
}