Skip to content

Commit

Permalink
FabricVersion: 实现获取 fabric 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
purofle committed Jan 2, 2024
1 parent d0985fc commit d1528ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
package com.github.purofle.nmsl.download.fabric

import com.github.purofle.nmsl.utils.io.HttpRequest
import kotlinx.serialization.Serializable

//TODO
object FabricVersion {
private const val GAME_META_URL = "https://meta.fabricmc.net/v2/versions/game"
private const val LOADER_META_URL = "https://meta.fabricmc.net/v2/versions/loader"
private suspend fun getGameVersions(url: String): List<String> {
return HttpRequest.getJson<List<GameVersion>>(url).map { it.version }
}

suspend fun getFabricVersion(): List<RemoteFabricVersion> {
val gameVersions = getGameVersions(GAME_META_URL)
val loaderVersions = getGameVersions(LOADER_META_URL)

return gameVersions.zip(loaderVersions)
.map { (gameVersion, loaderVersion) ->
RemoteFabricVersion(
gameVersion = gameVersion,
fabricVersion = loaderVersion,
metaUrl = "https://meta.fabricmc.net/v2/versions/loader/$gameVersion/$loaderVersion"
)
}
}

@Serializable
data class GameVersion(
val version: String,
val stable: Boolean,
val maven: String? = null,
)

@Serializable
data class RemoteFabricVersion(
val gameVersion: String,
val fabricVersion: String,
val metaUrl: String
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.purofle.nmsl.download.fabric

import kotlinx.coroutines.runBlocking
import kotlin.test.Test

class FabricVersionTest {
@Test
fun getFabricVersionTest() = runBlocking {
val fabricVersion = FabricVersion.getFabricVersion()
println(fabricVersion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class HttpRequestTest {
files = manifest.versions.map {
HttpRequest.DownloadInfo(it.url, File.createTempFile(it.id, ".json"))
},
progress = { url, bytesSentTotal, contentLength ->
println("$url: $bytesSentTotal/$contentLength")
},
)
}
}
Expand Down

0 comments on commit d1528ea

Please sign in to comment.