Added API endpoint to check for latest release.

This commit is contained in:
DESKTOP-T0O5CDB\DESK-555BD
2025-05-17 10:14:36 -06:00
parent 732a628c20
commit 723eb1a769
4 changed files with 57 additions and 3 deletions

View File

@@ -113,10 +113,31 @@ namespace CarCareTracker.Controllers
}
[HttpGet]
[Route("/api/version")]
public IActionResult ServerVersion()
public async Task<IActionResult> ServerVersion(bool checkForUpdate = false)
{
var serverVersion = StaticHelper.VersionNumber;
return Json(serverVersion);
var viewModel = new ReleaseVersion
{
CurrentVersion = StaticHelper.VersionNumber,
LatestVersion = StaticHelper.VersionNumber
};
if (checkForUpdate)
{
try
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("request");
var releaseResponse = await httpClient.GetFromJsonAsync<ReleaseResponse>(StaticHelper.ReleasePath) ?? new ReleaseResponse();
if (!string.IsNullOrWhiteSpace(releaseResponse.tag_name))
{
viewModel.LatestVersion = releaseResponse.tag_name;
}
}
catch (Exception ex)
{
return Json(OperationResponse.Failed($"Unable to retrieve latest version from GitHub API: {ex.Message}"));
}
}
return Json(viewModel);
}
[HttpGet]
[Route("/api/vehicles")]

View File

@@ -22,6 +22,7 @@ namespace CarCareTracker.Helper
public const string DefaultAllowedFileExtensions = ".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx";
public const string SponsorsPath = "https://hargata.github.io/hargata/sponsors.json";
public const string TranslationPath = "https://hargata.github.io/lubelog_translations";
public const string ReleasePath = "https://api.github.com/repos/hargata/lubelog/releases/latest";
public const string TranslationDirectoryPath = $"{TranslationPath}/directory.json";
public const string ReportNote = "Report generated by LubeLogger, a Free and Open Source Vehicle Maintenance Tracker - LubeLogger.com";
public static string GetTitleCaseReminderUrgency(ReminderUrgency input)

View File

@@ -0,0 +1,18 @@
namespace CarCareTracker.Models
{
/// <summary>
/// For deserializing GitHub response for latest version
/// </summary>
public class ReleaseResponse
{
public string tag_name { get; set; }
}
/// <summary>
/// For returning the version numbers via API.
/// </summary>
public class ReleaseVersion
{
public string CurrentVersion { get; set; }
public string LatestVersion { get; set; }
}
}

View File

@@ -40,6 +40,20 @@
No Params
</div>
</div>
<div class="row api-method">
<div class="col-1">
<span class="badge bg-success">GET</span>
</div>
<div class="col-5 copyable testable">
<code>/api/version</code>
</div>
<div class="col-3">
Returns current version of LubeLogger and checks for updates
</div>
<div class="col-3">
CheckForUpdate(bool) - checks for update(optional)
</div>
</div>
<div class="row api-method">
<div class="col-1">
<span class="badge bg-success">GET</span>