[Komga] Add login using API key (#10752)
bump version, add api key login Co-authored-by: WorldTeacher <coding_contact@pm.me>
This commit is contained in:
parent
93ba18cd9c
commit
9c695d0e65
@ -1,7 +1,7 @@
|
|||||||
ext {
|
ext {
|
||||||
extName = 'Komga'
|
extName = 'Komga'
|
||||||
extClass = '.KomgaFactory'
|
extClass = '.KomgaFactory'
|
||||||
extVersionCode = 63
|
extVersionCode = 64
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -76,6 +76,8 @@ open class Komga(private val suffix: String = "") : ConfigurableSource, Unmetere
|
|||||||
|
|
||||||
private val password by lazy { preferences.getString(PREF_PASSWORD, "")!! }
|
private val password by lazy { preferences.getString(PREF_PASSWORD, "")!! }
|
||||||
|
|
||||||
|
private val apiKey by lazy { preferences.getString(PREF_API_KEY, "")!! }
|
||||||
|
|
||||||
private val defaultLibraries
|
private val defaultLibraries
|
||||||
get() = preferences.getStringSet(PREF_DEFAULT_LIBRARIES, emptySet())!!
|
get() = preferences.getStringSet(PREF_DEFAULT_LIBRARIES, emptySet())!!
|
||||||
|
|
||||||
@ -83,12 +85,17 @@ open class Komga(private val suffix: String = "") : ConfigurableSource, Unmetere
|
|||||||
|
|
||||||
override fun headersBuilder() = super.headersBuilder()
|
override fun headersBuilder() = super.headersBuilder()
|
||||||
.set("User-Agent", "TachiyomiKomga/${AppInfo.getVersionName()}")
|
.set("User-Agent", "TachiyomiKomga/${AppInfo.getVersionName()}")
|
||||||
|
.also { builder ->
|
||||||
|
if (apiKey.isNotBlank()) {
|
||||||
|
builder.set("X-API-Key", apiKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override val client: OkHttpClient =
|
override val client: OkHttpClient =
|
||||||
network.cloudflareClient.newBuilder()
|
network.cloudflareClient.newBuilder()
|
||||||
.authenticator { _, response ->
|
.authenticator { _, response ->
|
||||||
if (response.request.header("Authorization") != null) {
|
if (apiKey.isNotBlank() || response.request.header("Authorization") != null) {
|
||||||
null // Give up, we've already failed to authenticate.
|
null // Give up if API key is set or we've already failed to authenticate.
|
||||||
} else {
|
} else {
|
||||||
response.request.newBuilder()
|
response.request.newBuilder()
|
||||||
.addHeader("Authorization", Credentials.basic(username, password))
|
.addHeader("Authorization", Credentials.basic(username, password))
|
||||||
@ -377,21 +384,33 @@ open class Komga(private val suffix: String = "") : ConfigurableSource, Unmetere
|
|||||||
key = PREF_ADDRESS,
|
key = PREF_ADDRESS,
|
||||||
restartRequired = true,
|
restartRequired = true,
|
||||||
)
|
)
|
||||||
|
// API key preference (takes precedence over username/password)
|
||||||
screen.addEditTextPreference(
|
screen.addEditTextPreference(
|
||||||
title = "Username",
|
title = "API key",
|
||||||
default = "",
|
default = "",
|
||||||
summary = username.ifBlank { "The user account email" },
|
summary = if (apiKey.isBlank()) "Optional: Use an API key for authentication" else "*".repeat(apiKey.length),
|
||||||
key = PREF_USERNAME,
|
|
||||||
restartRequired = true,
|
|
||||||
)
|
|
||||||
screen.addEditTextPreference(
|
|
||||||
title = "Password",
|
|
||||||
default = "",
|
|
||||||
summary = if (password.isBlank()) "The user account password" else "*".repeat(password.length),
|
|
||||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
||||||
key = PREF_PASSWORD,
|
key = PREF_API_KEY,
|
||||||
restartRequired = true,
|
restartRequired = true,
|
||||||
)
|
)
|
||||||
|
// Only show username/password if API key is not set
|
||||||
|
if (apiKey.isBlank()) {
|
||||||
|
screen.addEditTextPreference(
|
||||||
|
title = "Username",
|
||||||
|
default = "",
|
||||||
|
summary = username.ifBlank { "The user account email" },
|
||||||
|
key = PREF_USERNAME,
|
||||||
|
restartRequired = true,
|
||||||
|
)
|
||||||
|
screen.addEditTextPreference(
|
||||||
|
title = "Password",
|
||||||
|
default = "",
|
||||||
|
summary = if (password.isBlank()) "The user account password" else "*".repeat(password.length),
|
||||||
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD,
|
||||||
|
key = PREF_PASSWORD,
|
||||||
|
restartRequired = true,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
MultiSelectListPreference(screen.context).apply {
|
MultiSelectListPreference(screen.context).apply {
|
||||||
key = PREF_DEFAULT_LIBRARIES
|
key = PREF_DEFAULT_LIBRARIES
|
||||||
@ -529,6 +548,7 @@ private const val PREF_DISPLAY_NAME = "Source display name"
|
|||||||
private const val PREF_ADDRESS = "Address"
|
private const val PREF_ADDRESS = "Address"
|
||||||
private const val PREF_USERNAME = "Username"
|
private const val PREF_USERNAME = "Username"
|
||||||
private const val PREF_PASSWORD = "Password"
|
private const val PREF_PASSWORD = "Password"
|
||||||
|
private const val PREF_API_KEY = "API key"
|
||||||
private const val PREF_DEFAULT_LIBRARIES = "Default libraries"
|
private const val PREF_DEFAULT_LIBRARIES = "Default libraries"
|
||||||
private const val PREF_CHAPTER_NAME_TEMPLATE = "Chapter name template"
|
private const val PREF_CHAPTER_NAME_TEMPLATE = "Chapter name template"
|
||||||
private const val PREF_CHAPTER_NAME_TEMPLATE_DEFAULT = "{number} - {title} ({size})"
|
private const val PREF_CHAPTER_NAME_TEMPLATE_DEFAULT = "{number} - {title} ({size})"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user