Skip to content

Commit

Permalink
Fix URL redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Dec 23, 2023
1 parent 27a2533 commit 7682a93
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 42 deletions.
11 changes: 1 addition & 10 deletions src/main/kotlin/me/shedaniel/linkie/namespaces/MCPNamespace.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.shedaniel.linkie.namespaces

import com.soywiz.korio.stream.readAvailable
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer
Expand All @@ -13,15 +12,7 @@ import me.shedaniel.linkie.Namespace
import me.shedaniel.linkie.parser.apply
import me.shedaniel.linkie.parser.srg
import me.shedaniel.linkie.parser.tsrg
import me.shedaniel.linkie.parser.visitor
import me.shedaniel.linkie.utils.Version
import me.shedaniel.linkie.utils.filterNotBlank
import me.shedaniel.linkie.utils.lines
import me.shedaniel.linkie.utils.readText
import me.shedaniel.linkie.utils.toAsyncZip
import me.shedaniel.linkie.utils.toVersion
import me.shedaniel.linkie.utils.tryToVersion
import java.net.URL
import me.shedaniel.linkie.utils.*

object MCPNamespace : Namespace("mcp") {
const val tmpMcpVersionsUrl = "https://gist.githubusercontent.com/shedaniel/afc2748c6d5dd827d4cde161a49687ec/raw/mcp_versions.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import me.shedaniel.linkie.*
import me.shedaniel.linkie.utils.onlyClass
import me.shedaniel.linkie.utils.readLines
import me.shedaniel.linkie.utils.readText
import me.shedaniel.linkie.utils.singleSequenceOf
import me.shedaniel.linkie.utils.toVersion
import me.shedaniel.linkie.utils.tryToVersion
import java.net.URL
import me.shedaniel.linkie.utils.*
import kotlin.collections.List
import kotlin.collections.Set
import kotlin.collections.asSequence
import kotlin.collections.forEach
import kotlin.collections.listOf
import kotlin.collections.mutableMapOf
import kotlin.collections.set
import kotlin.collections.setOf

object MojangNamespace : Namespace("mojang") {
val versionJsonMap = mutableMapOf<String, String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ package me.shedaniel.linkie.namespaces

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import me.shedaniel.linkie.MappingsContainer
import me.shedaniel.linkie.MappingsMember
import me.shedaniel.linkie.*
import me.shedaniel.linkie.MappingsSource.MOJANG_TSRG
import me.shedaniel.linkie.MappingsSource.MOJANG_TSRG2
import me.shedaniel.linkie.Namespace
import me.shedaniel.linkie.buildMappings
import me.shedaniel.linkie.getMappedDesc
import me.shedaniel.linkie.namespaces.MCPNamespace.loadTsrgFromURLZip
import me.shedaniel.linkie.rearrangeClassMap
import me.shedaniel.linkie.rewireIntermediaryFrom
import me.shedaniel.linkie.utils.URL
import me.shedaniel.linkie.utils.Version
import me.shedaniel.linkie.utils.readText
import me.shedaniel.linkie.utils.toVersion
import java.net.URL

object MojangSrgNamespace : Namespace("mojang_srg") {
const val tmpTsrg2VersionsUrl = "https://gist.githubusercontent.com/shedaniel/68c5a5f8a56a30f48f994e105351b15f/raw/official-mcpconfig.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import me.shedaniel.linkie.Namespace
import me.shedaniel.linkie.namespaces.YarnNamespace.loadIntermediaryFromTinyFile
import me.shedaniel.linkie.namespaces.YarnNamespace.loadNamedFromTinyJar
import me.shedaniel.linkie.simpleCachedSupplier
import me.shedaniel.linkie.utils.URL
import me.shedaniel.linkie.utils.readText
import me.shedaniel.linkie.utils.singleSequenceOf
import java.net.URL
import kotlin.properties.Delegates

object PlasmaNamespace : Namespace("plasma") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import me.shedaniel.linkie.namespaces.YarnNamespace.loadIntermediaryFromTinyInpu
import me.shedaniel.linkie.namespaces.YarnNamespace.loadNamedFromTinyInputStream
import me.shedaniel.linkie.utils.*
import org.dom4j.io.SAXReader
import java.net.URL
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
Expand Down
12 changes: 1 addition & 11 deletions src/main/kotlin/me/shedaniel/linkie/namespaces/YarnNamespace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ import me.shedaniel.linkie.MappingsSource
import me.shedaniel.linkie.Method
import me.shedaniel.linkie.MethodArg
import me.shedaniel.linkie.Namespace
import me.shedaniel.linkie.getClassByObfName
import me.shedaniel.linkie.getClassByOptimumName
import me.shedaniel.linkie.getMethodByOptimum
import me.shedaniel.linkie.isSpecialGenerated
import me.shedaniel.linkie.utils.Version
import me.shedaniel.linkie.utils.ZipFile
import me.shedaniel.linkie.utils.filterNotBlank
import me.shedaniel.linkie.utils.lines
import me.shedaniel.linkie.utils.readText
import me.shedaniel.linkie.utils.toAsyncZip
import me.shedaniel.linkie.utils.tryToVersion
import me.shedaniel.linkie.utils.warn
import net.fabricmc.mappings.ExtendedMappings
import me.shedaniel.linkie.utils.*
import java.io.InputStream
import java.net.URL
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.collections.set
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/me/shedaniel/linkie/utils/IOUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@ import com.soywiz.korio.stream.AsyncStream
import com.soywiz.korio.stream.openAsync
import com.soywiz.korio.stream.readAvailable
import okio.BufferedSource
import java.net.URL
import java.util.zip.ZipInputStream
import kotlin.io.readText

val httpClient = createHttpClient()
val defaultRequestConfig = HttpClient.RequestConfig(
followRedirects = false,
throwErrors = true
)

suspend fun AsyncInputStream.readText(): String = readBytes().decodeToString()
suspend fun AsyncInputStream.lines(): Sequence<String> = readText().lineSequence()
suspend fun AsyncInputStream.readBytes() = readAvailable()
suspend fun URL.readText() = readText(Charsets.UTF_8)
suspend fun URL.readBytes() = httpClient.readBytes(this.toString(), defaultRequestConfig)
suspend fun URL.readText() = readBytes().decodeToString()
suspend fun URL.readLines() = readText().lineSequence()
suspend fun ByteArray.lines() = decodeToString().lineSequence()
suspend fun URL.toAsyncZip(): ZipFile = toAsyncStream().zip()
Expand All @@ -32,6 +30,11 @@ fun BufferedSource.lines() = readUtf8().lines()

fun getMillis(): Long = System.currentTimeMillis()

@JvmInline
value class URL(val path: String) {
override fun toString(): String = path
}

class ZipFile(val bytes: ByteArray) {
suspend fun forEachEntry(action: suspend (path: String, entry: ZipEntry) -> Unit) {
ZipInputStream(bytes.inputStream()).use { stream ->
Expand Down

0 comments on commit 7682a93

Please sign in to comment.