-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
NMSLCore/src/main/kotlin/com/github/purofle/nmsl/download/fabric/FabricVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
NMSLCore/src/test/kotlin/com/github/purofle/nmsl/download/fabric/FabricVersionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters