diff options
Diffstat (limited to 'src/main/kotlin/repo')
| -rw-r--r-- | src/main/kotlin/repo/HypixelStaticData.kt | 26 | ||||
| -rw-r--r-- | src/main/kotlin/repo/RepoDownloadManager.kt | 21 |
2 files changed, 23 insertions, 24 deletions
diff --git a/src/main/kotlin/repo/HypixelStaticData.kt b/src/main/kotlin/repo/HypixelStaticData.kt index b0ada77..ed37054 100644 --- a/src/main/kotlin/repo/HypixelStaticData.kt +++ b/src/main/kotlin/repo/HypixelStaticData.kt @@ -1,11 +1,10 @@ package moe.nea.firmament.repo -import io.ktor.client.call.body -import io.ktor.client.request.get import org.apache.logging.log4j.LogManager import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.delay +import kotlinx.coroutines.future.await import kotlinx.coroutines.launch import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -14,6 +13,7 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.apis.CollectionResponse import moe.nea.firmament.apis.CollectionSkillData import moe.nea.firmament.util.SkyblockId +import moe.nea.firmament.util.net.HttpUtil object HypixelStaticData { private val logger = LogManager.getLogger("Firmament.HypixelStaticData") @@ -91,18 +91,19 @@ object HypixelStaticData { } private suspend fun fetchPricesFromMoulberry() { - lowestBin = Firmament.httpClient.get("$moulberryBaseUrl/lowestbin.json") - .body<Map<SkyblockId, Double>>() - avg1dlowestBin = Firmament.httpClient.get("$moulberryBaseUrl/auction_averages_lbin/1day.json") - .body<Map<SkyblockId, Double>>() - avg3dlowestBin = Firmament.httpClient.get("$moulberryBaseUrl/auction_averages_lbin/3day.json") - .body<Map<SkyblockId, Double>>() - avg7dlowestBin = Firmament.httpClient.get("$moulberryBaseUrl/auction_averages_lbin/7day.json") - .body<Map<SkyblockId, Double>>() + lowestBin = HttpUtil.request("$moulberryBaseUrl/lowestbin.json") + .forJson<Map<SkyblockId, Double>>().await() + avg1dlowestBin = HttpUtil.request("$moulberryBaseUrl/auction_averages_lbin/1day.json") + .forJson<Map<SkyblockId, Double>>().await() + avg3dlowestBin = HttpUtil.request("$moulberryBaseUrl/auction_averages_lbin/3day.json") + .forJson<Map<SkyblockId, Double>>().await() + avg7dlowestBin = HttpUtil.request("$moulberryBaseUrl/auction_averages_lbin/7day.json") + .forJson<Map<SkyblockId, Double>>().await() } private suspend fun fetchBazaarPrices() { - val response = Firmament.httpClient.get("$hypixelApiBaseUrl/skyblock/bazaar").body<BazaarResponse>() + val response = HttpUtil.request("$hypixelApiBaseUrl/skyblock/bazaar").forJson<BazaarResponse>() + .await() if (!response.success) { logger.warn("Retrieved unsuccessful bazaar data") } @@ -111,7 +112,8 @@ object HypixelStaticData { private suspend fun updateCollectionData() { val response = - Firmament.httpClient.get("$hypixelApiBaseUrl/resources/skyblock/collections").body<CollectionResponse>() + HttpUtil.request("$hypixelApiBaseUrl/resources/skyblock/collections").forJson<CollectionResponse>() + .await() if (!response.success) { logger.warn("Retrieved unsuccessful collection data") } 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 } |
