Add filters only with selfoss >= 2.19
Source filters have been implemented in 2014 (commit 849957ca) but there is no reliable way to determine whether the selfoss instance does support source filters.
This commit is contained in:
parent
566930ba84
commit
9e140aefa6
@ -642,14 +642,13 @@ class SelfossApi(
|
||||
): SuccessResponse =
|
||||
maybeResponse(
|
||||
if (appSettingsService.getApiVersion() > 1) {
|
||||
createSource("tags[]", title, url, spout, tags, filter)
|
||||
createSource(title, url, spout, tags, filter)
|
||||
} else {
|
||||
createSource("tags", title, url, spout, tags, filter)
|
||||
createSourceOld(title, url, spout, tags)
|
||||
},
|
||||
)
|
||||
|
||||
private suspend fun createSource(
|
||||
tagsParamName: String,
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
@ -668,7 +667,47 @@ class SelfossApi(
|
||||
append("url", url)
|
||||
append("spout", spout)
|
||||
append("filter", filter)
|
||||
append(tagsParamName, tags)
|
||||
append("tags[]", tags)
|
||||
},
|
||||
block = {
|
||||
if (appSettingsService
|
||||
.getBasicUserName()
|
||||
.isNotEmpty() &&
|
||||
appSettingsService.getBasicPassword().isNotEmpty()
|
||||
) {
|
||||
headers {
|
||||
append(
|
||||
HttpHeaders.Authorization,
|
||||
constructBasicAuthValue(
|
||||
BasicAuthCredentials(
|
||||
username = appSettingsService.getBasicUserName(),
|
||||
password = appSettingsService.getBasicPassword(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
private suspend fun createSourceOld(
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
tags: String,
|
||||
): HttpResponse? =
|
||||
client.tryToSubmitForm(
|
||||
url = url("/source"),
|
||||
formParameters =
|
||||
Parameters.build {
|
||||
if (!shouldHavePostLogin()) {
|
||||
append("username", appSettingsService.getUserName())
|
||||
append("password", appSettingsService.getPassword())
|
||||
}
|
||||
append("title", title)
|
||||
append("url", url)
|
||||
append("spout", spout)
|
||||
append("tags", tags)
|
||||
},
|
||||
block = {
|
||||
if (appSettingsService
|
||||
@ -701,15 +740,14 @@ class SelfossApi(
|
||||
): SuccessResponse =
|
||||
maybeResponse(
|
||||
if (appSettingsService.getApiVersion() > 1) {
|
||||
updateSource(id, "tags[]", title, url, spout, tags, filter)
|
||||
updateSource(id, title, url, spout, tags, filter)
|
||||
} else {
|
||||
updateSource(id, "tags", title, url, spout, tags, filter)
|
||||
updateSourceOld(id, title, url, spout, tags)
|
||||
},
|
||||
)
|
||||
|
||||
private suspend fun updateSource(
|
||||
id: Int,
|
||||
tagsParamName: String,
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
@ -727,7 +765,7 @@ class SelfossApi(
|
||||
append("title", title)
|
||||
append("url", url)
|
||||
append("spout", spout)
|
||||
append(tagsParamName, tags)
|
||||
append("tags[]", tags)
|
||||
append("filter", filter)
|
||||
},
|
||||
block = {
|
||||
@ -751,6 +789,47 @@ class SelfossApi(
|
||||
},
|
||||
)
|
||||
|
||||
private suspend fun updateSourceOld(
|
||||
id: Int,
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
tags: String,
|
||||
): HttpResponse? =
|
||||
client.tryToSubmitForm(
|
||||
url = url("/source/$id"),
|
||||
formParameters =
|
||||
Parameters.build {
|
||||
if (!shouldHavePostLogin()) {
|
||||
append("username", appSettingsService.getUserName())
|
||||
append("password", appSettingsService.getPassword())
|
||||
}
|
||||
append("title", title)
|
||||
append("url", url)
|
||||
append("spout", spout)
|
||||
append("tags", tags)
|
||||
},
|
||||
block = {
|
||||
if (appSettingsService
|
||||
.getBasicUserName()
|
||||
.isNotEmpty() &&
|
||||
appSettingsService.getBasicPassword().isNotEmpty()
|
||||
) {
|
||||
headers {
|
||||
append(
|
||||
HttpHeaders.Authorization,
|
||||
constructBasicAuthValue(
|
||||
BasicAuthCredentials(
|
||||
username = appSettingsService.getBasicUserName(),
|
||||
password = appSettingsService.getBasicPassword(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
suspend fun deleteSource(id: Int): SuccessResponse =
|
||||
maybeResponse(
|
||||
client.tryToDelete(url("/source/$id")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user