Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions ImmichFrame.WebApi/Helpers/ImmichServerVersionLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using ImmichFrame.Core.Api;
using ImmichFrame.Core.Helpers;
using ImmichFrame.Core.Interfaces;

namespace ImmichFrame.WebApi.Helpers
{
public static class ImmichServerVersionLogger
{
private static readonly TimeSpan RequestTimeout = TimeSpan.FromSeconds(5);

public static async Task LogServerVersions(IServiceProvider services, ILogger logger)
{
IEnumerable<IAccountSettings> accounts;
try
{
accounts = services.GetRequiredService<IServerSettings>().Accounts;
}
catch (Exception ex)
{
logger.LogWarning("Could not check Immich server versions, config could not be loaded: {Message}", ex.Message);
return;
}

var httpClientFactory = services.GetRequiredService<IHttpClientFactory>();

foreach (var account in accounts)
{
try
{
var httpClient = httpClientFactory.CreateClient("ImmichApiAccountClient");
httpClient.UseApiKey(account.ApiKey);
var immichApi = new ImmichApi(account.ImmichServerUrl, httpClient);

using var cts = new CancellationTokenSource(RequestTimeout);
var version = await immichApi.GetServerVersionAsync(cts.Token);

logger.LogInformation("Immich server {Url} is running v{Major}.{Minor}.{Patch}",
account.ImmichServerUrl, version.Major, version.Minor, version.Patch);

if (version.Major < 3)
{
logger.LogWarning("Immich server {Url} is running v{Major}.{Minor}.{Patch}, but this version of ImmichFrame requires Immich v3 or newer. Please update your Immich server.",
account.ImmichServerUrl, version.Major, version.Minor, version.Patch);
}
}
catch (Exception ex)
{
logger.LogWarning("Could not determine Immich server version for {Url}: {Message}",
account.ImmichServerUrl, ex.Message);
}
}
}
}
}
8 changes: 8 additions & 0 deletions ImmichFrame.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using ImmichFrame.Core.Logic;
using ImmichFrame.Core.Logic.AccountSelection;
using ImmichFrame.WebApi.Helpers;
using ImmichFrame.WebApi.Helpers.Config;

var builder = WebApplication.CreateBuilder(args);
Expand Down Expand Up @@ -42,6 +43,11 @@ _ _ __ ___ _ __ ___ _ ___| |__ | |_ _ __ __ _ _ __ ___ ___
builder.AddFilter("Microsoft.AspNetCore.SpaProxy", LogLevel.Warning);
// Disable AspNetCore info logs
builder.AddFilter("Microsoft.AspNetCore", LogLevel.Warning);
// Only show HttpClient request info logs when LOG_LEVEL is Debug or lower
if (level > LogLevel.Debug)
{
builder.AddFilter("System.Net.Http.HttpClient", LogLevel.Warning);
}
});


Expand Down Expand Up @@ -112,6 +118,8 @@ _ _ __ ___ _ __ ___ _ ___| |__ | |_ _ __ __ _ _ __ ___ ___

app.MapFallbackToFile("/index.html");

await ImmichServerVersionLogger.LogServerVersions(app.Services, app.Logger);

app.Run();

// Make Program public for WebApplicationFactory
Expand Down
Loading