Skip to content

Commit

Permalink
refactor: better version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Aug 18, 2024
1 parent 56e30c4 commit fa2d93f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Shokofin/API/Models/ComponentVersion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Text.Json.Serialization;

Expand All @@ -17,7 +18,8 @@ public class ComponentVersion
/// <summary>
/// Version number.
/// </summary>
public string Version { get; set; } = string.Empty;
[DefaultValue("1.0.0.0")]
public Version Version { get; set; } = new("1.0.0.0");

/// <summary>
/// Commit SHA.
Expand Down
2 changes: 1 addition & 1 deletion Shokofin/API/Models/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Image
/// </summary>
[JsonIgnore]
public virtual bool IsAvailable
=> !string.IsNullOrEmpty(LocalPath) || (Plugin.Instance.Configuration.ServerVersion?.Version is {} version && version is not "4.2.2.0");
=> !string.IsNullOrEmpty(LocalPath) || (Plugin.Instance.Configuration.ServerVersion?.Version is {} version && version > new Version("4.2.2.0"));

/// <summary>
/// Get an URL to both download the image on the backend and preview it for
Expand Down
6 changes: 3 additions & 3 deletions Shokofin/API/ShokoAPIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class ShokoAPIClient : IDisposable
private static readonly DateTime StableCutOffDate = DateTime.Parse("2023-12-16T00:00:00.000Z");

private static bool UseOlderSeriesAndFileEndpoints =>
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == "4.2.2.0") || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < StableCutOffDate));
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == new Version("4.2.2.0")) || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < StableCutOffDate));

private static readonly DateTime ImportFolderCutOffDate = DateTime.Parse("2024-03-28T00:00:00.000Z");

private static bool UseOlderImportFolderFileEndpoints =>
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == "4.2.2.0") || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < ImportFolderCutOffDate));
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == new Version("4.2.2.0")) || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < ImportFolderCutOffDate));

public static bool AllowEpisodeImages =>
ServerVersion is { } serverVersion && serverVersion.Version[0..6] is not "4.2.2." && serverVersion.Version.Split('.').Last() is not "0";
ServerVersion is { } serverVersion && serverVersion.Version > new Version("4.2.2.0");

private readonly GuardedMemoryCache _cache;

Expand Down
2 changes: 1 addition & 1 deletion Shokofin/SignalR/SignalRConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SignalRConnectionManager
private static readonly DateTime EventChangedDate = DateTime.Parse("2024-04-01T04:04:00.000Z");

private static bool UseOlderEvents =>
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == "4.2.2.0") || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < EventChangedDate));
ServerVersion != null && ((ServerVersion.ReleaseChannel == ReleaseChannel.Stable && ServerVersion.Version == new Version("4.2.2.0")) || (ServerVersion.ReleaseDate.HasValue && ServerVersion.ReleaseDate.Value < EventChangedDate));

private const string HubUrl = "/signalr/aggregate?feeds=shoko";

Expand Down

0 comments on commit fa2d93f

Please sign in to comment.