Rename recommendedVersion to minimumVersion

The recommended version should always be the latest server version (which is stored in apiVersion). The minimumVersion should be the latest server version without significant API changes and is manually updated.
This commit is contained in:
Niels van Velzen 2021-04-28 21:50:58 +02:00
parent a1d7596c4e
commit 4b3e640175
3 changed files with 19 additions and 10 deletions

View File

@ -11,7 +11,7 @@ public final class org/jellyfin/sdk/Jellyfin {
public final class org/jellyfin/sdk/Jellyfin$Companion {
public final fun getApiVersion ()Lorg/jellyfin/sdk/model/ServerVersion;
public final fun getRecommendedVersion ()Lorg/jellyfin/sdk/model/ServerVersion;
public final fun getMinimumVersion ()Lorg/jellyfin/sdk/model/ServerVersion;
}
public final class org/jellyfin/sdk/JellyfinOptions {

View File

@ -58,7 +58,14 @@ public class Jellyfin(
}
public companion object {
public val recommendedVersion: ServerVersion = ServerVersion(10, 7, 0, 0)
/**
* The minimum server version expected to work. Lower versions may work but are not supported.
*/
public val minimumVersion: ServerVersion = ServerVersion(10, 7, 0, 0)
/**
* The exact server version used to generate the API. Should be equal or higher than [minimumVersion].
*/
public val apiVersion: ServerVersion = ServerVersion.fromString(ApiConstants.apiVersion)!!
}
}

View File

@ -11,14 +11,14 @@ import org.slf4j.LoggerFactory
import java.net.ConnectException
public class RecommendedServerDiscovery(
private val jellyfin: Jellyfin
private val jellyfin: Jellyfin,
) {
private val logger = LoggerFactory.getLogger("RecommendedServerDiscovery")
private data class SystemInfoResult(
val address: String,
val systemInfo: PublicSystemInfo?,
val responseTime: Long
val responseTime: Long,
)
private suspend fun getSystemInfoResult(address: String): SystemInfoResult? {
@ -28,6 +28,7 @@ public class RecommendedServerDiscovery(
val api = SystemApi(client)
val startTime = System.currentTimeMillis()
@Suppress("TooGenericExceptionCaught")
val info = try {
api.getPublicSystemInfo()
@ -66,13 +67,14 @@ public class RecommendedServerDiscovery(
val version = result.systemInfo?.version?.let(ServerVersion::fromString)
if (version != null) {
if (version >= Jellyfin.apiVersion) points += 1
if (version == Jellyfin.recommendedVersion) points += 2
else if (version > Jellyfin.recommendedVersion) points += 1
if (version >= Jellyfin.minimumVersion) points += 1
}
val productName = result.systemInfo?.productName
if (productName != null && !productName.equals("Jellyfin Server", ignoreCase = true)) points = 0
// Minimum amount of points: 0
// Maximum amount of points: 9
// Maximum amount of points: 8
val score = when {
points < 3 -> RecommendedServerInfoScore.BAD
points < 6 -> RecommendedServerInfoScore.OK
@ -85,7 +87,7 @@ public class RecommendedServerDiscovery(
public suspend fun discover(
servers: List<String>,
includeAppendedServers: Boolean,
minimumScore: RecommendedServerInfoScore
minimumScore: RecommendedServerInfoScore,
): Flow<RecommendedServerInfo> = discover(
servers = servers.asFlow(),
includeAppendedServers = includeAppendedServers,
@ -95,7 +97,7 @@ public class RecommendedServerDiscovery(
public suspend fun discover(
servers: Flow<String>,
includeAppendedServers: Boolean,
minimumScore: RecommendedServerInfoScore
minimumScore: RecommendedServerInfoScore,
): Flow<RecommendedServerInfo> = withContext(Dispatchers.IO) {
flow {
servers.onEach parentEach@{ server ->