1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2024-12-21 23:32:40 +00:00

Fixed relative link handling with proxy

This commit is contained in:
Corewala 2022-07-29 15:09:26 -04:00
parent 79a3564569
commit 13f21bc09b
2 changed files with 23 additions and 21 deletions

View file

@ -58,6 +58,7 @@ class OmniTerm(private val listener: Listener) {
link.startsWith("//") -> uri.set("gemini:$link")
link.startsWith("http://") or link.startsWith("https://") -> {
uri.set(link)
println("MALD?")
}
link.contains(":") -> listener.openExternal(link)
else -> uri.resolve(link)

View file

@ -1,6 +1,8 @@
package corewala.buran
const val SCHEME = "gemini://"
import corewala.toURI
const val GEMSCHEME = "gemini://"
const val TRAVERSE = "../"
const val SOLIDUS = "/"
const val DIREND = "/"
@ -15,21 +17,29 @@ class OppenURI constructor(private var ouri: String) {
constructor(): this("")
var host: String = ""
var scheme: String = ""
init {
extractHost()
if(ouri.isNotEmpty()){
host = ouri.toURI().host
scheme = ouri.toURI().scheme
}
}
fun set(ouri: String){
this.ouri = ouri
extractHost()
if(ouri.isNotEmpty()){
host = ouri.toURI().host
scheme = ouri.toURI().scheme
}
}
fun resolve(reference: String): String{
if(ouri == "$SCHEME$host") ouri = "$ouri/"
if(ouri == "$GEMSCHEME$host") ouri = "$ouri/"
println(host)
when {
reference.startsWith(SCHEME) -> set(reference)
reference.startsWith(SOLIDUS) -> ouri = "$SCHEME$host$reference"
reference.startsWith(GEMSCHEME) -> set(reference)
reference.startsWith(SOLIDUS) -> ouri = "$scheme://$host$reference"
reference.startsWith(TRAVERSE) -> {
if(!ouri.endsWith(DIREND)) ouri = ouri.removeFile()
val traversalCount = reference.split(TRAVERSE).size - 1
@ -46,16 +56,16 @@ class OppenURI constructor(private var ouri: String) {
}
fun traverse(): OppenURI{
val path = ouri.removePrefix("$SCHEME$host")
val path = ouri.removePrefix("$GEMSCHEME$host")
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
var nouri = "$SCHEME$host"
var nouri = "$GEMSCHEME$host"
when (ouri) {
"" -> {
}
SCHEME -> ouri = ""
"$nouri/" -> ouri = SCHEME
GEMSCHEME -> ouri = ""
"$nouri/" -> ouri = GEMSCHEME
else -> {
when {
segments.isNotEmpty() -> {
@ -74,10 +84,10 @@ class OppenURI constructor(private var ouri: String) {
}
private fun traverse(count: Int): String{
val path = ouri.removePrefix("$SCHEME$host")
val path = ouri.removePrefix("$GEMSCHEME$host")
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
val segmentCount = segments.size
var nouri = "$SCHEME$host"
var nouri = "$GEMSCHEME$host"
segments.forEachIndexed{ index, segment ->
if(index < segmentCount - count){
@ -89,15 +99,6 @@ class OppenURI constructor(private var ouri: String) {
}
private fun extractHost(){
if(ouri.isEmpty()) return
val urn = ouri.removePrefix(SCHEME)
host = when {
urn.contains(SOLIDUS) -> urn.substring(0, urn.indexOf(SOLIDUS))
else -> urn
}
}
fun copy(): OppenURI = OppenURI(ouri)
override fun toString(): String = ouri