mirror of
https://github.com/AChep/keyguard-app.git
synced 2025-02-01 14:56:49 +01:00
fix: Correctly form Send urls if the Web vault url is specified
This commit is contained in:
parent
2cad9a12e3
commit
e450fb3fec
@ -1,5 +1,6 @@
|
|||||||
package com.artemchep.keyguard.provider.bitwarden.api.builder
|
package com.artemchep.keyguard.provider.bitwarden.api.builder
|
||||||
|
|
||||||
|
import arrow.core.identity
|
||||||
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
|
import com.artemchep.keyguard.provider.bitwarden.ServerEnv
|
||||||
import io.ktor.http.Url
|
import io.ktor.http.Url
|
||||||
|
|
||||||
@ -12,7 +13,6 @@ fun ServerEnv.buildHost() = buildWebVaultUrl()
|
|||||||
|
|
||||||
fun ServerEnv.buildWebVaultUrl() = buildUrl(
|
fun ServerEnv.buildWebVaultUrl() = buildUrl(
|
||||||
url = webVaultUrl,
|
url = webVaultUrl,
|
||||||
suffix = "",
|
|
||||||
default = when (region) {
|
default = when (region) {
|
||||||
ServerEnv.Region.US -> "https://vault.$BITWARDEN_DOMAIN_US/"
|
ServerEnv.Region.US -> "https://vault.$BITWARDEN_DOMAIN_US/"
|
||||||
ServerEnv.Region.EU -> "https://vault.$BITWARDEN_DOMAIN_EU/"
|
ServerEnv.Region.EU -> "https://vault.$BITWARDEN_DOMAIN_EU/"
|
||||||
@ -21,7 +21,7 @@ fun ServerEnv.buildWebVaultUrl() = buildUrl(
|
|||||||
|
|
||||||
fun ServerEnv.buildApiUrl() = buildUrl(
|
fun ServerEnv.buildApiUrl() = buildUrl(
|
||||||
url = apiUrl,
|
url = apiUrl,
|
||||||
suffix = "api/",
|
baseUrlModifier = { "${it}api/" },
|
||||||
default = when (region) {
|
default = when (region) {
|
||||||
ServerEnv.Region.US -> "https://vault.$BITWARDEN_DOMAIN_US/api/"
|
ServerEnv.Region.US -> "https://vault.$BITWARDEN_DOMAIN_US/api/"
|
||||||
ServerEnv.Region.EU -> "https://vault.$BITWARDEN_DOMAIN_EU/api/"
|
ServerEnv.Region.EU -> "https://vault.$BITWARDEN_DOMAIN_EU/api/"
|
||||||
@ -30,7 +30,7 @@ fun ServerEnv.buildApiUrl() = buildUrl(
|
|||||||
|
|
||||||
fun ServerEnv.buildIdentityUrl() = buildUrl(
|
fun ServerEnv.buildIdentityUrl() = buildUrl(
|
||||||
url = identityUrl,
|
url = identityUrl,
|
||||||
suffix = "identity/",
|
baseUrlModifier = { "${it}identity/" },
|
||||||
default = when (region) {
|
default = when (region) {
|
||||||
ServerEnv.Region.US -> "https://identity.$BITWARDEN_DOMAIN_US/"
|
ServerEnv.Region.US -> "https://identity.$BITWARDEN_DOMAIN_US/"
|
||||||
ServerEnv.Region.EU -> "https://identity.$BITWARDEN_DOMAIN_EU/"
|
ServerEnv.Region.EU -> "https://identity.$BITWARDEN_DOMAIN_EU/"
|
||||||
@ -39,27 +39,32 @@ fun ServerEnv.buildIdentityUrl() = buildUrl(
|
|||||||
|
|
||||||
fun ServerEnv.buildIconsUrl() = buildUrl(
|
fun ServerEnv.buildIconsUrl() = buildUrl(
|
||||||
url = iconsUrl,
|
url = iconsUrl,
|
||||||
suffix = "icons/",
|
baseUrlModifier = { "${it}icons/" },
|
||||||
default = "https://icons.bitwarden.net/",
|
default = "https://icons.bitwarden.net/",
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ServerEnv.buildNotificationsUrl() = buildUrl(
|
fun ServerEnv.buildNotificationsUrl() = buildUrl(
|
||||||
url = notificationsUrl,
|
url = notificationsUrl,
|
||||||
suffix = "notifications/",
|
baseUrlModifier = { "${it}notifications/" },
|
||||||
default = when (region) {
|
default = when (region) {
|
||||||
ServerEnv.Region.US -> "https://notifications.$BITWARDEN_DOMAIN_US/"
|
ServerEnv.Region.US -> "https://notifications.$BITWARDEN_DOMAIN_US/"
|
||||||
ServerEnv.Region.EU -> "https://notifications.$BITWARDEN_DOMAIN_EU/"
|
ServerEnv.Region.EU -> "https://notifications.$BITWARDEN_DOMAIN_EU/"
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
fun ServerEnv.buildSendUrl() = buildUrl(
|
fun ServerEnv.buildSendUrl() = run {
|
||||||
|
fun urlModifier(url: String): String = "$url#/send/"
|
||||||
|
|
||||||
|
buildUrl(
|
||||||
url = webVaultUrl,
|
url = webVaultUrl,
|
||||||
suffix = "#/send/",
|
urlModifier = ::urlModifier,
|
||||||
|
baseUrlModifier = ::urlModifier,
|
||||||
default = when (region) {
|
default = when (region) {
|
||||||
ServerEnv.Region.US -> "https://send.$BITWARDEN_DOMAIN_US/#"
|
ServerEnv.Region.US -> "https://send.$BITWARDEN_DOMAIN_US/#"
|
||||||
ServerEnv.Region.EU -> "https://send.$BITWARDEN_DOMAIN_EU/#"
|
ServerEnv.Region.EU -> "https://send.$BITWARDEN_DOMAIN_EU/#"
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun ServerEnv.buildIconsRequestUrl(domain: String) = kotlin.run {
|
fun ServerEnv.buildIconsRequestUrl(domain: String) = kotlin.run {
|
||||||
val baseUrl = buildIconsUrl()
|
val baseUrl = buildIconsUrl()
|
||||||
@ -68,14 +73,15 @@ fun ServerEnv.buildIconsRequestUrl(domain: String) = kotlin.run {
|
|||||||
|
|
||||||
private fun ServerEnv.buildUrl(
|
private fun ServerEnv.buildUrl(
|
||||||
url: String,
|
url: String,
|
||||||
suffix: String,
|
urlModifier: (String) -> String = ::identity,
|
||||||
|
baseUrlModifier: (String) -> String = ::identity,
|
||||||
default: String,
|
default: String,
|
||||||
) = url
|
) = ensureValidBaseUrlOrNull(url)?.let(urlModifier)
|
||||||
.takeUnless { it.isBlank() }
|
?: ensureValidBaseUrlOrNull(baseUrl)?.let(baseUrlModifier)
|
||||||
?: baseUrl
|
|
||||||
.takeUnless { it.isBlank() }
|
|
||||||
?.ensureSuffix("/")
|
|
||||||
?.let { it + suffix }
|
|
||||||
?: default
|
?: default
|
||||||
|
|
||||||
|
private fun ensureValidBaseUrlOrNull(url: String) = url
|
||||||
|
.takeUnless { it.isBlank() }
|
||||||
|
?.ensureSuffix("/")
|
||||||
|
|
||||||
fun String.ensureSuffix(suffix: String) = if (endsWith(suffix)) this else this + suffix
|
fun String.ensureSuffix(suffix: String) = if (endsWith(suffix)) this else this + suffix
|
||||||
|
Loading…
x
Reference in New Issue
Block a user