mirror of
https://github.com/AChep/keyguard-app.git
synced 2025-02-02 15:26:53 +01:00
feat: Allow specifying your own Base URL for Addy.io
This commit is contained in:
parent
e097d26453
commit
82db6151bc
@ -11,6 +11,7 @@ import com.artemchep.keyguard.feature.localization.TextHolder
|
||||
data class EmailRelaySchema(
|
||||
val title: TextHolder,
|
||||
val hint: TextHolder? = null,
|
||||
val description: TextHolder? = null,
|
||||
val type: ConfirmationRoute.Args.Item.StringItem.Type = ConfirmationRoute.Args.Item.StringItem.Type.Text,
|
||||
/**
|
||||
* `true` if the empty value is a valid
|
||||
|
@ -7,6 +7,7 @@ import com.artemchep.keyguard.common.service.relays.api.EmailRelay
|
||||
import com.artemchep.keyguard.common.service.relays.api.EmailRelaySchema
|
||||
import com.artemchep.keyguard.feature.confirmation.ConfirmationRoute
|
||||
import com.artemchep.keyguard.feature.localization.TextHolder
|
||||
import com.artemchep.keyguard.provider.bitwarden.api.builder.ensureSuffix
|
||||
import com.artemchep.keyguard.res.Res
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
@ -30,13 +31,16 @@ class AnonAddyEmailRelay(
|
||||
private val httpClient: HttpClient,
|
||||
) : EmailRelay {
|
||||
companion object {
|
||||
private const val ENDPOINT = "https://app.addy.io/api/v1/aliases"
|
||||
private const val ENDPOINT_BASE_URL = "https://app.addy.io/"
|
||||
private const val ENDPOINT_PATH = "api/v1/aliases"
|
||||
|
||||
private const val KEY_API_KEY = "apiKey"
|
||||
private const val HINT_API_KEY =
|
||||
"addy_io_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
private const val KEY_DOMAIN = "domain"
|
||||
private const val HINT_DOMAIN = "anonaddy.me"
|
||||
private const val KEY_BASE_URL = "base_url"
|
||||
private const val HINT_BASE_URL = ENDPOINT_BASE_URL
|
||||
}
|
||||
|
||||
override val type = "AnonAddy"
|
||||
@ -57,6 +61,12 @@ class AnonAddyEmailRelay(
|
||||
hint = TextHolder.Value(HINT_DOMAIN),
|
||||
canBeEmpty = false,
|
||||
),
|
||||
KEY_BASE_URL to EmailRelaySchema(
|
||||
title = TextHolder.Res(Res.strings.emailrelay_base_env_server_url_label),
|
||||
hint = TextHolder.Value(HINT_BASE_URL),
|
||||
description = TextHolder.Res(Res.strings.emailrelay_base_env_note),
|
||||
canBeEmpty = true,
|
||||
),
|
||||
)
|
||||
|
||||
constructor(directDI: DirectDI) : this(
|
||||
@ -73,9 +83,16 @@ class AnonAddyEmailRelay(
|
||||
val domain = requireNotNull(config[KEY_DOMAIN]) {
|
||||
"Domain is required for creating an email alias."
|
||||
}
|
||||
val apiUrl = kotlin.run {
|
||||
val baseUrl = config[KEY_BASE_URL]
|
||||
?.trim()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?: ENDPOINT_BASE_URL
|
||||
baseUrl.ensureSuffix("/") + ENDPOINT_PATH
|
||||
}
|
||||
// https://app.anonaddy.com/docs/#aliases-POSTapi-v1-aliases
|
||||
val response = httpClient
|
||||
.post(ENDPOINT) {
|
||||
.post(apiUrl) {
|
||||
header("Authorization", "Bearer $apiKey")
|
||||
|
||||
val body = AnonAddyRequest(
|
||||
|
@ -92,6 +92,7 @@ fun produceEmailRelayListState(
|
||||
value = itemValue,
|
||||
title = translate(emailRelay.value.title),
|
||||
hint = emailRelay.value.hint?.let { translate(it) },
|
||||
description = emailRelay.value.description?.let { translate(it) },
|
||||
type = emailRelay.value.type,
|
||||
canBeEmpty = emailRelay.value.canBeEmpty,
|
||||
)
|
||||
|
@ -474,6 +474,8 @@
|
||||
<string name="emailrelay_delete_many_confirmation_title">Delete the email forwarders?</string>
|
||||
<string name="emailrelay_integration_title">Email forwarder integration</string>
|
||||
<string name="emailrelay_empty_label">No email forwarders</string>
|
||||
<string name="emailrelay_base_env_server_url_label">Server URL</string>
|
||||
<string name="emailrelay_base_env_note">Specify the base URL of your self-hosted installation.</string>
|
||||
|
||||
<string name="urloverride_header_title">URL override</string>
|
||||
<string name="urloverride_list_header_title">URL overrides</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user