Fix version checking for freshly added servers
This commit is contained in:
parent
620239f859
commit
6ab0ff973a
|
@ -45,7 +45,8 @@ import retrofit2.Call
|
||||||
@Suppress("TooManyFunctions")
|
@Suppress("TooManyFunctions")
|
||||||
internal class ApiVersionCheckWrapper(
|
internal class ApiVersionCheckWrapper(
|
||||||
val api: SubsonicAPIDefinition,
|
val api: SubsonicAPIDefinition,
|
||||||
var currentApiVersion: SubsonicAPIVersions
|
var currentApiVersion: SubsonicAPIVersions?,
|
||||||
|
var isRealProtocolVersion: Boolean = false
|
||||||
) : SubsonicAPIDefinition by api {
|
) : SubsonicAPIDefinition by api {
|
||||||
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
|
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
|
||||||
checkVersion(V1_8_0)
|
checkVersion(V1_8_0)
|
||||||
|
@ -325,10 +326,15 @@ internal class ApiVersionCheckWrapper(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkVersion(expectedVersion: SubsonicAPIVersions) {
|
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) {
|
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) {
|
if (param != null) {
|
||||||
checkVersion(expectedVersion)
|
checkVersion(expectedVersion)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ class SubsonicAPIClient(
|
||||||
field = value
|
field = value
|
||||||
proxyPasswordInterceptor.apiVersion = field
|
proxyPasswordInterceptor.apiVersion = field
|
||||||
wrappedApi.currentApiVersion = field
|
wrappedApi.currentApiVersion = field
|
||||||
|
wrappedApi.isRealProtocolVersion = true
|
||||||
versionInterceptor.protocolVersion = field
|
versionInterceptor.protocolVersion = field
|
||||||
onProtocolChange(field)
|
onProtocolChange(field)
|
||||||
}
|
}
|
||||||
|
@ -88,8 +89,8 @@ class SubsonicAPIClient(
|
||||||
.addConverterFactory(
|
.addConverterFactory(
|
||||||
VersionAwareJacksonConverterFactory.create(
|
VersionAwareJacksonConverterFactory.create(
|
||||||
{
|
{
|
||||||
// Only trigger update on change
|
// Only trigger update on change, or if still using the default
|
||||||
if (protocolVersion != it) {
|
if (protocolVersion != it || !config.isRealProtocolVersion) {
|
||||||
protocolVersion = it
|
protocolVersion = it
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -100,7 +101,8 @@ class SubsonicAPIClient(
|
||||||
|
|
||||||
private val wrappedApi = ApiVersionCheckWrapper(
|
private val wrappedApi = ApiVersionCheckWrapper(
|
||||||
retrofit.create(SubsonicAPIDefinition::class.java),
|
retrofit.create(SubsonicAPIDefinition::class.java),
|
||||||
config.minimalProtocolVersion
|
config.minimalProtocolVersion,
|
||||||
|
config.isRealProtocolVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
val api: SubsonicAPIDefinition get() = wrappedApi
|
val api: SubsonicAPIDefinition get() = wrappedApi
|
||||||
|
|
|
@ -11,5 +11,6 @@ data class SubsonicClientConfiguration(
|
||||||
val clientID: String,
|
val clientID: String,
|
||||||
val allowSelfSignedCertificate: Boolean = false,
|
val allowSelfSignedCertificate: Boolean = false,
|
||||||
val enableLdapUserSupport: Boolean = false,
|
val enableLdapUserSupport: Boolean = false,
|
||||||
val debug: Boolean = false
|
val debug: Boolean = false,
|
||||||
|
val isRealProtocolVersion: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
|
@ -49,19 +49,21 @@ val musicServiceModule = module {
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
|
val server = get<ActiveServerProvider>().getActiveServer()
|
||||||
|
|
||||||
return@single SubsonicClientConfiguration(
|
return@single SubsonicClientConfiguration(
|
||||||
baseUrl = get<ActiveServerProvider>().getActiveServer().url,
|
baseUrl = server.url,
|
||||||
username = get<ActiveServerProvider>().getActiveServer().userName,
|
username = server.userName,
|
||||||
password = get<ActiveServerProvider>().getActiveServer().password,
|
password = server.password,
|
||||||
minimalProtocolVersion = SubsonicAPIVersions.getClosestKnownClientApiVersion(
|
minimalProtocolVersion = SubsonicAPIVersions.getClosestKnownClientApiVersion(
|
||||||
get<ActiveServerProvider>().getActiveServer().minimumApiVersion
|
server.minimumApiVersion
|
||||||
?: Constants.REST_PROTOCOL_VERSION
|
?: Constants.REST_PROTOCOL_VERSION
|
||||||
),
|
),
|
||||||
clientID = Constants.REST_CLIENT_ID,
|
clientID = Constants.REST_CLIENT_ID,
|
||||||
allowSelfSignedCertificate = get<ActiveServerProvider>()
|
allowSelfSignedCertificate = server.allowSelfSignedCertificate,
|
||||||
.getActiveServer().allowSelfSignedCertificate,
|
enableLdapUserSupport = server.ldapSupport,
|
||||||
enableLdapUserSupport = get<ActiveServerProvider>().getActiveServer().ldapSupport,
|
debug = BuildConfig.DEBUG,
|
||||||
debug = BuildConfig.DEBUG
|
isRealProtocolVersion = server.minimumApiVersion != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue