Added API endpoint to check for latest release.
This commit is contained in:
@@ -113,10 +113,31 @@ namespace CarCareTracker.Controllers
|
|||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("/api/version")]
|
[Route("/api/version")]
|
||||||
public IActionResult ServerVersion()
|
public async Task<IActionResult> ServerVersion(bool checkForUpdate = false)
|
||||||
{
|
{
|
||||||
var serverVersion = StaticHelper.VersionNumber;
|
var viewModel = new ReleaseVersion
|
||||||
return Json(serverVersion);
|
{
|
||||||
|
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]
|
[HttpGet]
|
||||||
[Route("/api/vehicles")]
|
[Route("/api/vehicles")]
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace CarCareTracker.Helper
|
|||||||
public const string DefaultAllowedFileExtensions = ".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx";
|
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 SponsorsPath = "https://hargata.github.io/hargata/sponsors.json";
|
||||||
public const string TranslationPath = "https://hargata.github.io/lubelog_translations";
|
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 TranslationDirectoryPath = $"{TranslationPath}/directory.json";
|
||||||
public const string ReportNote = "Report generated by LubeLogger, a Free and Open Source Vehicle Maintenance Tracker - LubeLogger.com";
|
public const string ReportNote = "Report generated by LubeLogger, a Free and Open Source Vehicle Maintenance Tracker - LubeLogger.com";
|
||||||
public static string GetTitleCaseReminderUrgency(ReminderUrgency input)
|
public static string GetTitleCaseReminderUrgency(ReminderUrgency input)
|
||||||
|
|||||||
18
Models/API/ReleaseVersion.cs
Normal file
18
Models/API/ReleaseVersion.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,20 @@
|
|||||||
No Params
|
No Params
|
||||||
</div>
|
</div>
|
||||||
</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="row api-method">
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<span class="badge bg-success">GET</span>
|
<span class="badge bg-success">GET</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user