diff --git a/ImmichFrame.WebApi/Helpers/ImmichServerVersionLogger.cs b/ImmichFrame.WebApi/Helpers/ImmichServerVersionLogger.cs new file mode 100644 index 00000000..251f7f1b --- /dev/null +++ b/ImmichFrame.WebApi/Helpers/ImmichServerVersionLogger.cs @@ -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 accounts; + try + { + accounts = services.GetRequiredService().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(); + + 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); + } + } + } + } +} diff --git a/ImmichFrame.WebApi/Program.cs b/ImmichFrame.WebApi/Program.cs index f2d68244..a94ed997 100644 --- a/ImmichFrame.WebApi/Program.cs +++ b/ImmichFrame.WebApi/Program.cs @@ -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); @@ -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); + } }); @@ -112,6 +118,8 @@ _ _ __ ___ _ __ ___ _ ___| |__ | |_ _ __ __ _ _ __ ___ ___ app.MapFallbackToFile("/index.html"); +await ImmichServerVersionLogger.LogServerVersions(app.Services, app.Logger); + app.Run(); // Make Program public for WebApplicationFactory