Skip to content

Commit

Permalink
refactor: update internal model for web ui version info
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Oct 20, 2024
1 parent b5832e3 commit 808d7ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
25 changes: 15 additions & 10 deletions Shoko.Server/API/WebUI/WebUIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,28 @@ public static partial class WebUIHelper
/// <summary>
/// Web UI Version Info.
/// </summary>
public record WebUIVersionInfo {
public record WebUIVersionInfo
{
/// <summary>
/// Package version.
/// </summary>
public string package = "1.0.0";
[JsonProperty("package")]
public string Package { get; set; } = "1.0.0";
/// <summary>
/// Short-form git commit sha digest.
/// </summary>
public string git = "0000000";
[JsonProperty("git")]
public string Git { get; set; } = "0000000";
/// <summary>
/// True if this is a debug package.
/// </summary>
public bool debug = false;
[JsonProperty("debug")]
public bool Debug { get; set; } = false;
/// <summary>
/// Release date for web ui release.
/// </summary>
public DateTime? date = null;
[JsonProperty("date")]
public DateTime? Date { get; set; } = null;
}

/// <summary>
Expand Down Expand Up @@ -158,12 +163,12 @@ private static void AddReleaseDate(DateTime releaseDate)
if (webUIFileInfo.Exists)
{
// Load the web ui version info from disk.
var webuiVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<WebUIVersionInfo>(System.IO.File.ReadAllText(webUIFileInfo.FullName));
var webuiVersion = JsonConvert.DeserializeObject<WebUIVersionInfo>(System.IO.File.ReadAllText(webUIFileInfo.FullName));
// Set the release data and save the info again if the date is not set.
if (webuiVersion is not null && !webuiVersion.date.HasValue)
if (webuiVersion is not null && !webuiVersion.Date.HasValue)
{
webuiVersion.date = releaseDate;
System.IO.File.WriteAllText(webUIFileInfo.FullName, Newtonsoft.Json.JsonConvert.SerializeObject(webuiVersion));
webuiVersion.Date = releaseDate;
File.WriteAllText(webUIFileInfo.FullName, JsonConvert.SerializeObject(webuiVersion));
}
}
}
Expand All @@ -172,7 +177,7 @@ private static void AddReleaseDate(DateTime releaseDate)
{
var webUIFileInfo = new FileInfo(Path.Combine(Utils.ApplicationPath, "webui/version.json"));
if (webUIFileInfo.Exists)
return Newtonsoft.Json.JsonConvert.DeserializeObject<WebUIVersionInfo>(System.IO.File.ReadAllText(webUIFileInfo.FullName));
return JsonConvert.DeserializeObject<WebUIVersionInfo>(File.ReadAllText(webUIFileInfo.FullName));
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions Shoko.Server/API/v3/Controllers/InitController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public ComponentVersionSet GetVersion()
{
versionSet.WebUI = new()
{
Version = webuiVersion.package,
ReleaseChannel = webuiVersion.debug ? ReleaseChannel.Debug : webuiVersion.package.Contains("-dev") ? ReleaseChannel.Dev : ReleaseChannel.Stable,
Commit = webuiVersion.git,
ReleaseDate = webuiVersion.date,
Version = webuiVersion.Package,
ReleaseChannel = webuiVersion.Debug ? ReleaseChannel.Debug : webuiVersion.Package.Contains("-dev") ? ReleaseChannel.Dev : ReleaseChannel.Stable,
Commit = webuiVersion.Git,
ReleaseDate = webuiVersion.Date,
};
}

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/API/v3/Controllers/WebUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ private static ReleaseChannel GetCurrentWebUIReleaseChannel()
{
var webuiVersion = WebUIHelper.LoadWebUIVersionInfo();
if (webuiVersion != null)
return webuiVersion.debug ? ReleaseChannel.Debug : webuiVersion.package.Contains("-dev") ? ReleaseChannel.Dev : ReleaseChannel.Stable;
return webuiVersion.Debug ? ReleaseChannel.Debug : webuiVersion.Package.Contains("-dev") ? ReleaseChannel.Dev : ReleaseChannel.Stable;
return GetCurrentServerReleaseChannel();
}

Expand Down

0 comments on commit 808d7ae

Please sign in to comment.