Skip to content

Commit

Permalink
Version Checker and Namespace fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Webreaper committed Mar 15, 2024
1 parent b4df714 commit d299722
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 54 deletions.
2 changes: 2 additions & 0 deletions Damselfly.Core.DbModels/Interfaces/ICachedDataService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Damselfly.Core.DbModels.Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;

namespace Damselfly.Core.ScopedServices.Interfaces;
Expand All @@ -14,4 +15,5 @@ public interface ICachedDataService
Task InitialiseData();
Task<Statistics> GetStatistics();
Task ClearCache();
Task<NewVersionResponse> CheckForNewVersion();
}
1 change: 0 additions & 1 deletion Damselfly.Core.DbModels/Interfaces/IPeopleService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Damselfly.Core.DbModels.Models.API_Models;
namespace Damselfly.Core.DbModels.Models.APIModels;

public class AIMigrationRequest
{
Expand Down
19 changes: 19 additions & 0 deletions Damselfly.Core.DbModels/Models/API Models/NewVersionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace Damselfly.Core.DbModels.Models.APIModels;

public class NewVersionResponse
{
public Version CurrentVersion { get; set; }
public Version? NewVersion { get; set; }
public string? NewReleaseName { get; set; }
public string? ReleaseUrl { get; set; }
public bool? UpgradeAvailable()
{
if( NewVersion != null )
return NewVersion > CurrentVersion;

return null;
}

}
2 changes: 1 addition & 1 deletion Damselfly.Core.DbModels/Models/API Models/SearchHint.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Damselfly.Core.ScopedServices.Interfaces;

namespace Damselfly.Core.DbModels.Models.API_Models;
namespace Damselfly.Core.DbModels.Models.APIModels;

public class SearchHint : ISearchHint
{
Expand Down
3 changes: 1 addition & 2 deletions Damselfly.Core.ScopedServices/BaseSearchService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Globalization;
using Damselfly.Core.Constants;
using Damselfly.Core.DbModels;
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
using Damselfly.Core.Utils;
using Humanizer;
using Microsoft.Extensions.Logging;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public async Task ClearCache()
{
await InitialiseData();
}

public async Task<NewVersionResponse> CheckForNewVersion()
{
return await httpClient.CustomGetFromJsonAsync<NewVersionResponse>("/api/data/newversion");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.ClientServices;
using Damselfly.Core.ScopedServices.Interfaces;
Expand Down
2 changes: 1 addition & 1 deletion Damselfly.Core/Damselfly.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</PackageReference>
<PackageReference Include="MetadataExtractor" />
<PackageReference Include="CommandLineParser" />
<PackageReference Include="Octokit" />
<PackageReference Include="WordPressPCL" />
<PackageReference Include="SixLabors.ImageSharp" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" />
Expand All @@ -41,7 +42,6 @@
<PackageReference Include="EFCore.BulkExtensions" NoWarn="1605" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
<Folder Include="Utils\" />
<Folder Include="ScopedServices\" />
<Folder Include="DbAbstractions\" />
Expand Down
58 changes: 47 additions & 11 deletions Damselfly.Core/ScopedServices/CachedDataService.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Damselfly.Core.DbModels.Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
using Damselfly.Core.Services;
using Microsoft.Extensions.Logging;
using Octokit;

namespace Damselfly.Core.ScopedServices;

public class CachedDataService : ICachedDataService
public class CachedDataService( MetaDataService _metaDataService,
StatisticsService _stats,
ILogger<CachedDataService> _logger) : ICachedDataService
{
private readonly MetaDataService _metaDataService;
private readonly StatisticsService _stats;

public CachedDataService(MetaDataService metaDataService, StatisticsService stats)
{
_stats = stats;
_metaDataService = metaDataService;
}

public string ImagesRootFolder => IndexingService.RootFolder;

public string ExifToolVer => ExifService.ExifToolVer;
Expand All @@ -42,4 +40,42 @@ public Task ClearCache()
// No-op
return Task.CompletedTask;
}
private NewVersionResponse? newVersionState;

/// <summary>
/// Checks for a new version
/// </summary>
/// <returns></returns>
public async Task<NewVersionResponse> CheckForNewVersion()
{
if( newVersionState == null )
{
newVersionState = new NewVersionResponse
{
CurrentVersion = Assembly.GetExecutingAssembly().GetName().Version
};

try
{
var client = new GitHubClient(new ProductHeaderValue("Damselfly"));

var newRelease = await client.Repository.Release.GetLatest("webreaper", "damselfly");
if( newRelease != null && Version.TryParse(newRelease.TagName, out var newVersion) )
{
newVersionState.NewVersion = newVersion;
newVersionState.NewReleaseName = newRelease.Name;
newVersionState.ReleaseUrl = newRelease.HtmlUrl;

_logger.LogInformation(
$"A new version of Damselfly is available: ({newRelease.Name})");
}
}
catch( Exception ex )
{
_logger.LogWarning("Unable to check GitHub for latest version: {ex}", ex);
}
}

return newVersionState;
}
}
1 change: 0 additions & 1 deletion Damselfly.Core/Services/ImageRecognitionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Damselfly.Core.Constants;
using Damselfly.Core.Database;
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Interfaces;
using Damselfly.Core.Models;
Expand Down
9 changes: 9 additions & 0 deletions Damselfly.Web.Client/Damselfly.Web.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>

<ItemGroup>
<Content Update="Shared\DamselflyLogo.razor.css">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<Content Update="Shared\VersionChecker.razor.css">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<ReadLinesFromFile File="../VERSION">
<Output TaskParameter="Lines" PropertyName="VersionNumber" />
Expand Down
3 changes: 2 additions & 1 deletion Damselfly.Web.Client/Shared/About.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<div>
<img src="damselfly-logo.png" height="200" title="Damselfly" />
</div>
<h3>Damselfly v<span />@Version &copy; 2019-@DateTime.Now.Year Mark Otway, All rights reserved.</h3>
<h3>Damselfly v<span />@Version <VersionChecker/></h3>
<h4>&copy; 2019-@DateTime.Now.Year Mark Otway, All rights reserved.</h4>
<h4>Server-based Digital Asset Management system</h4>
<hr />
<h3>Credits/Thanks</h3>
Expand Down
1 change: 1 addition & 0 deletions Damselfly.Web.Client/Shared/DamselflyLogo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<NavLink href="/">
<img src="damselfly-logo.png" title="Damselfly"/>
</NavLink>
<VersionChecker/>
</div>

14 changes: 14 additions & 0 deletions Damselfly.Web.Client/Shared/DamselflyLogo.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.damselfly-logo {
display: flex;
flex-direction: column;
background-color: black;
flex: 0 0 50px;
order: -1;
justify-content: center;
align-items: center;
}

.damselfly-logo img {
max-height: 60px;
object-fit: contain;
}
3 changes: 1 addition & 2 deletions Damselfly.Web.Client/Shared/Dialogs/AIMigrationDialog.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using Damselfly.Core.DbModels.Models.API_Models
@inject IPeopleService peopleService
@inject IPeopleService peopleService

<MudDialog>
<DialogContent>
Expand Down
25 changes: 25 additions & 0 deletions Damselfly.Web.Client/Shared/VersionChecker.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@inject ICachedDataService cachedData

@if( needsUpgrade )
{
<div class="new-version">
<NavLink href="@newVersionState.ReleaseUrl" target="_blank">
v<text>@newVersionState.NewVersion</text> of Damselfly is available
</NavLink>
</div>
}

@code {
private NewVersionResponse newVersionState;
bool needsUpgrade = false;

protected override async Task OnInitializedAsync()
{
newVersionState = await cachedData.CheckForNewVersion();
var checkResult = newVersionState.UpgradeAvailable();
if( checkResult.HasValue )
needsUpgrade = checkResult.Value;

await base.OnInitializedAsync();
}
}
5 changes: 5 additions & 0 deletions Damselfly.Web.Client/Shared/VersionChecker.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.new-version{
display: flex;
font-weight: normal;
padding: 3px;
}
14 changes: 0 additions & 14 deletions Damselfly.Web.Client/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -565,20 +565,6 @@ f
flex-direction: column;
}

.damselfly-logo {
display: flex;
background-color: black;
flex: 0 0 50px;
order: -1;
justify-content: center;
}

.damselfly-logo img {
max-height: 60px;
object-fit: contain;
}


.damselfly-folderlist {
flex-direction: column;
flex: 0 1 100%;
Expand Down
2 changes: 1 addition & 1 deletion Damselfly.Web.Client/wwwroot/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const CACHE_VERSION='4.1.0-20240310210419'
const CACHE_VERSION='4.1.3-20240315223425'
5 changes: 4 additions & 1 deletion Damselfly.Web.Server/AppInitialisation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Damselfly.Core.Constants;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
using Damselfly.Core.Services;
using Damselfly.Core.Utils;
using Damselfly.ML.FaceONNX;
Expand Down Expand Up @@ -33,7 +34,9 @@ public static void SetupServices(this IWebHostEnvironment env, IServiceProvider
services.GetRequiredService<IndexingService>().StartService();
services.GetRequiredService<ImageRecognitionService>().StartService();
services.GetRequiredService<FaceONNXService>().StartService();


services.GetRequiredService<ICachedDataService>().CheckForNewVersion();

// ObjectDetector can throw a segmentation fault if the docker container is pinned
// to a single CPU, so for now, to aid debugging, let's not even try and initialise
// it if AI is disabled. See https://github.com/Webreaper/Damselfly/issues/334
Expand Down
1 change: 0 additions & 1 deletion Damselfly.Web.Server/Controllers/PeopleController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Damselfly.Core.Constants;
using Damselfly.Core.Database;
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
Expand Down
26 changes: 12 additions & 14 deletions Damselfly.Web.Server/Controllers/StaticDataController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Damselfly.Core.Constants;
using Damselfly.Core.Constants;
using Damselfly.Core.DbModels.Models;
using Damselfly.Core.DbModels.Models.APIModels;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
using Damselfly.Core.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -11,20 +12,11 @@ namespace Damselfly.Web.Server.Controllers;
//[Authorize(Policy = PolicyDefinitions.s_IsLoggedIn)]
[ApiController]
[Route("/api/data")]
public class StaticDataController : ControllerBase
public class StaticDataController( ILogger<StaticDataController> _logger,
MetaDataService _metaDataService,
ICachedDataService _cachedData,
StatisticsService _stats) : ControllerBase
{
private readonly ILogger<StaticDataController> _logger;
private readonly MetaDataService _metaDataService;
private readonly StatisticsService _stats;

public StaticDataController(MetaDataService metaDataService, StatisticsService stats,
ILogger<StaticDataController> logger)
{
_metaDataService = metaDataService;
_stats = stats;
_logger = logger;
}

[HttpGet("/api/data/static")]
public Task<StaticData> GetStaticData()
{
Expand Down Expand Up @@ -54,4 +46,10 @@ public async Task<Statistics> GetStatistics()
{
return await _stats.GetStatistics();
}

[HttpGet("/api/data/newversion")]
public async Task<NewVersionResponse> CheckForNewVersion()
{
return await _cachedData.CheckForNewVersion();
}
}

0 comments on commit d299722

Please sign in to comment.