Fix version checking for freshly added servers

This commit is contained in:
tzugen 2021-06-09 19:33:17 +02:00
parent 620239f859
commit 6ab0ff973a
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
4 changed files with 25 additions and 14 deletions

View File

@ -45,7 +45,8 @@ import retrofit2.Call
@Suppress("TooManyFunctions")
internal class ApiVersionCheckWrapper(
val api: SubsonicAPIDefinition,
var currentApiVersion: SubsonicAPIVersions
var currentApiVersion: SubsonicAPIVersions?,
var isRealProtocolVersion: Boolean = false
) : SubsonicAPIDefinition by api {
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
checkVersion(V1_8_0)
@ -325,10 +326,15 @@ internal class ApiVersionCheckWrapper(
}
private fun checkVersion(expectedVersion: SubsonicAPIVersions) {
if (currentApiVersion < expectedVersion) throw ApiNotSupportedException(currentApiVersion)
// If it is true, it is probably the first call with this server
if (!isRealProtocolVersion) return
if (currentApiVersion!! < expectedVersion)
throw ApiNotSupportedException(currentApiVersion!!)
}
private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) {
// If it is true, it is probably the first call with this server
if (!isRealProtocolVersion) return
if (param != null) {
checkVersion(expectedVersion)
}

View File

@ -57,6 +57,7 @@ class SubsonicAPIClient(
field = value
proxyPasswordInterceptor.apiVersion = field
wrappedApi.currentApiVersion = field
wrappedApi.isRealProtocolVersion = true
versionInterceptor.protocolVersion = field
onProtocolChange(field)
}
@ -88,8 +89,8 @@ class SubsonicAPIClient(
.addConverterFactory(
VersionAwareJacksonConverterFactory.create(
{
// Only trigger update on change
if (protocolVersion != it) {
// Only trigger update on change, or if still using the default
if (protocolVersion != it || !config.isRealProtocolVersion) {
protocolVersion = it
}
},
@ -100,7 +101,8 @@ class SubsonicAPIClient(
private val wrappedApi = ApiVersionCheckWrapper(
retrofit.create(SubsonicAPIDefinition::class.java),
config.minimalProtocolVersion
config.minimalProtocolVersion,
config.isRealProtocolVersion
)
val api: SubsonicAPIDefinition get() = wrappedApi

View File

@ -11,5 +11,6 @@ data class SubsonicClientConfiguration(
val clientID: String,
val allowSelfSignedCertificate: Boolean = false,
val enableLdapUserSupport: Boolean = false,
val debug: Boolean = false
val debug: Boolean = false,
val isRealProtocolVersion: Boolean = false
)

View File

@ -49,19 +49,21 @@ val musicServiceModule = module {
}
single {
val server = get<ActiveServerProvider>().getActiveServer()
return@single SubsonicClientConfiguration(
baseUrl = get<ActiveServerProvider>().getActiveServer().url,
username = get<ActiveServerProvider>().getActiveServer().userName,
password = get<ActiveServerProvider>().getActiveServer().password,
baseUrl = server.url,
username = server.userName,
password = server.password,
minimalProtocolVersion = SubsonicAPIVersions.getClosestKnownClientApiVersion(
get<ActiveServerProvider>().getActiveServer().minimumApiVersion
server.minimumApiVersion
?: Constants.REST_PROTOCOL_VERSION
),
clientID = Constants.REST_CLIENT_ID,
allowSelfSignedCertificate = get<ActiveServerProvider>()
.getActiveServer().allowSelfSignedCertificate,
enableLdapUserSupport = get<ActiveServerProvider>().getActiveServer().ldapSupport,
debug = BuildConfig.DEBUG
allowSelfSignedCertificate = server.allowSelfSignedCertificate,
enableLdapUserSupport = server.ldapSupport,
debug = BuildConfig.DEBUG,
isRealProtocolVersion = server.minimumApiVersion != null
)
}