mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-16 11:41:16 +01:00
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")
|
||||
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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user