Foundations(iOS Sourceset): Provide implementation for makeAbsoluteIfRelativeUrl() in ServerInfoParser.ios.kt
This commit is contained in:
+23
-3
@@ -20,9 +20,29 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.quartz.nip96FileStorage.info
|
package com.vitorpamplona.quartz.nip96FileStorage.info
|
||||||
|
|
||||||
|
import platform.Foundation.NSURL
|
||||||
|
import platform.Foundation.NSURLComponents
|
||||||
|
|
||||||
actual fun makeAbsoluteIfRelativeUrl(
|
actual fun makeAbsoluteIfRelativeUrl(
|
||||||
baseUrl: String,
|
baseUrl: String,
|
||||||
potentiallyRelativeUrl: String,
|
potentiallyRelativeUrl: String,
|
||||||
): String {
|
): String =
|
||||||
TODO("Not yet implemented")
|
try {
|
||||||
}
|
val refUrl = NSURLComponents(potentiallyRelativeUrl)
|
||||||
|
if (refUrl.scheme != null) {
|
||||||
|
potentiallyRelativeUrl
|
||||||
|
} else {
|
||||||
|
val apiUrlComponents =
|
||||||
|
NSURLComponents(
|
||||||
|
uRL =
|
||||||
|
NSURL(
|
||||||
|
string = potentiallyRelativeUrl,
|
||||||
|
relativeToURL = NSURL(baseUrl, encodingInvalidCharacters = false),
|
||||||
|
),
|
||||||
|
resolvingAgainstBaseURL = true,
|
||||||
|
)
|
||||||
|
apiUrlComponents.string ?: throw Exception("URL resolution failed.")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
potentiallyRelativeUrl
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user