Birthday
hurl file over http file AddControllers Formatting
This commit is contained in:
@ -25,15 +25,15 @@ public class AssetsController(AssetService assetService) : ControllerBase {
|
||||
|
||||
[HttpGet("{ownerId:guid}/random-paths")]
|
||||
public IActionResult GetRandomPaths(Guid ownerId) =>
|
||||
Ok(_AssetService.GetRandomPaths(ownerId));
|
||||
Ok(_AssetService.GetRandomPaths(ownerId, monthDay: null));
|
||||
|
||||
[HttpGet("{ownerId:guid}/archived-tag")]
|
||||
public IActionResult GetArchivedTag(Guid ownerId) =>
|
||||
Content(_AssetService.GetArchivedTag(ownerId) ?? string.Empty, _ContentType);
|
||||
|
||||
[HttpGet("{ownerId:guid}/save-random-paths")]
|
||||
public IActionResult SaveRandomPaths(Guid ownerId) =>
|
||||
Content(_AssetService.SaveRandomPaths(ownerId) ?? string.Empty, _ContentType);
|
||||
public IActionResult SaveRandomPaths(Guid ownerId, string? month_day) =>
|
||||
Content(_AssetService.SaveRandomPaths(ownerId, monthDay: month_day) ?? string.Empty, _ContentType);
|
||||
|
||||
[HttpGet("{ownerId:guid}/sync-immich")]
|
||||
public IActionResult SyncImmich(Guid ownerId) =>
|
||||
|
@ -6,6 +6,7 @@ namespace ImmichToSlideshow.DependencyInjection;
|
||||
public static class ServiceCollectionExtensions {
|
||||
|
||||
public static IServiceCollection AddServices(this IServiceCollection services, AppSettings appSettings) {
|
||||
_ = services.AddControllers();
|
||||
_ = services.AddScoped<AssetService>();
|
||||
_ = services.AddSingleton(_ => appSettings);
|
||||
return services;
|
||||
|
@ -11,28 +11,45 @@ public record AppSettings(string Company, Settings Settings, string URLs, string
|
||||
}
|
||||
|
||||
private static void Verify(AppSettings appSettings) {
|
||||
if (appSettings?.Company is null)
|
||||
if (appSettings?.Company is null) {
|
||||
throw new NullReferenceException(nameof(Company));
|
||||
if (appSettings?.URLs is null)
|
||||
}
|
||||
if (appSettings?.URLs is null) {
|
||||
throw new NullReferenceException(nameof(URLs));
|
||||
if (appSettings?.WithOrigins is null)
|
||||
}
|
||||
if (appSettings?.WithOrigins is null) {
|
||||
throw new NullReferenceException(nameof(WithOrigins));
|
||||
if (appSettings?.Settings?.AddDays is null)
|
||||
}
|
||||
if (appSettings?.Settings?.AddDays is null) {
|
||||
throw new NullReferenceException(nameof(Settings.AddDays));
|
||||
if (appSettings?.Settings?.ArchivedTag is null)
|
||||
}
|
||||
if (appSettings?.Settings?.BirthdayFormat is null) {
|
||||
throw new NullReferenceException(nameof(Settings.BirthdayFormat));
|
||||
}
|
||||
if (appSettings?.Settings?.ArchivedTag is null) {
|
||||
throw new NullReferenceException(nameof(Settings.ArchivedTag));
|
||||
if (appSettings?.Settings?.ConnectionString is null)
|
||||
}
|
||||
if (appSettings?.Settings?.ConnectionString is null) {
|
||||
throw new NullReferenceException(nameof(Settings.ConnectionString));
|
||||
if (appSettings?.Settings?.DigiKam4 is null)
|
||||
}
|
||||
if (appSettings?.Settings?.DigiKam4 is null) {
|
||||
throw new NullReferenceException(nameof(Settings.DigiKam4));
|
||||
if (appSettings?.Settings?.FilterTags is null)
|
||||
}
|
||||
if (appSettings?.Settings?.FilterTags is null) {
|
||||
throw new NullReferenceException(nameof(Settings.FilterTags));
|
||||
if (appSettings?.Settings?.ImmichUploadDirectory is null)
|
||||
}
|
||||
if (appSettings?.Settings?.ImmichUploadDirectory is null) {
|
||||
throw new NullReferenceException(nameof(Settings.ImmichUploadDirectory));
|
||||
if (appSettings?.Settings?.RandomResultsDirectory is null)
|
||||
}
|
||||
if (appSettings?.Settings?.People is null) {
|
||||
throw new NullReferenceException(nameof(Settings.People));
|
||||
}
|
||||
if (appSettings?.Settings?.RandomResultsDirectory is null) {
|
||||
throw new NullReferenceException(nameof(Settings.RandomResultsDirectory));
|
||||
if (appSettings?.Settings?.SyncDirectory is null)
|
||||
}
|
||||
if (appSettings?.Settings?.SyncDirectory is null) {
|
||||
throw new NullReferenceException(nameof(Settings.SyncDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
public static AppSettings Get(IConfigurationRoot configurationRoot) {
|
||||
@ -46,10 +63,12 @@ public record AppSettings(string Company, Settings Settings, string URLs, string
|
||||
if (company is null || settings is null || urls is null || withOrigins is null) {
|
||||
List<string> paths = [];
|
||||
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) {
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider)
|
||||
if (configurationProvider is not Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider jsonConfigurationProvider) {
|
||||
continue;
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider)
|
||||
}
|
||||
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) {
|
||||
continue;
|
||||
}
|
||||
paths.Add(physicalFileProvider.Root);
|
||||
}
|
||||
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");
|
||||
|
@ -5,12 +5,14 @@ namespace ImmichToSlideshow.Models;
|
||||
|
||||
public record Settings(int AddDays,
|
||||
string ArchivedTag,
|
||||
string BirthdayFormat,
|
||||
string ConnectionString,
|
||||
DigiKam4? DigiKam4,
|
||||
string[] FilterTags,
|
||||
string ImmichUploadDirectory,
|
||||
float LowestVersionHistory,
|
||||
string NotNinePath,
|
||||
Dictionary<string, string> People,
|
||||
string RandomResultsDirectory,
|
||||
string SyncDirectory) {
|
||||
|
||||
|
@ -10,7 +10,6 @@ public class Program {
|
||||
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args);
|
||||
_ = webApplicationBuilder.Configuration.AddUserSecrets<Program>();
|
||||
AppSettings appSettings = AppSettings.Get(webApplicationBuilder.Configuration);
|
||||
_ = webApplicationBuilder.Services.AddControllers();
|
||||
_ = webApplicationBuilder.Services.AddServices(appSettings);
|
||||
WebApplication webApplication = webApplicationBuilder.Build();
|
||||
ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>();
|
||||
|
@ -69,8 +69,9 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
|
||||
|
||||
public string? GetAssets(Guid ownerId) {
|
||||
string result;
|
||||
ReadOnlyCollection<string> people = Array.Empty<string>().AsReadOnly();
|
||||
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags.AsReadOnly(), people);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
result = stringBuilder.ToString();
|
||||
if (result.Length == 1) {
|
||||
@ -79,10 +80,19 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
|
||||
return result;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId) {
|
||||
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId, string? monthDay) {
|
||||
string[]? results;
|
||||
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
|
||||
List<string> people = [];
|
||||
if (!string.IsNullOrEmpty(monthDay)) {
|
||||
foreach (KeyValuePair<string, string> keyValuePair in _Settings.People) {
|
||||
if (!keyValuePair.Key.Contains(monthDay)) {
|
||||
continue;
|
||||
}
|
||||
people.Add($"People/{keyValuePair.Value.Trim('/')}");
|
||||
}
|
||||
}
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags.AsReadOnly(), people.AsReadOnly());
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string json = stringBuilder.ToString();
|
||||
Random random = new();
|
||||
@ -114,19 +124,19 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
|
||||
return result;
|
||||
}
|
||||
|
||||
public string? SaveRandomPaths(Guid ownerId) {
|
||||
public string? SaveRandomPaths(Guid ownerId, string? monthDay) {
|
||||
string? results;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
string tomorrow = dateTime.AddDays(1).ToString("MM-dd");
|
||||
monthDay ??= dateTime.AddDays(1).ToString("MM-dd");
|
||||
if (Directory.Exists(_Settings.RandomResultsDirectory)) {
|
||||
_ = Directory.CreateDirectory(_Settings.RandomResultsDirectory);
|
||||
}
|
||||
FileInfo fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{tomorrow}.json"));
|
||||
FileInfo fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{monthDay}.json"));
|
||||
if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_Settings.AddDays)) {
|
||||
results = null;
|
||||
} else {
|
||||
_Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName);
|
||||
ReadOnlyCollection<string>? paths = GetRandomPaths(ownerId);
|
||||
ReadOnlyCollection<string>? paths = GetRandomPaths(ownerId, monthDay);
|
||||
if (paths is null) {
|
||||
results = null;
|
||||
} else {
|
||||
|
@ -1,3 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace ImmichToSlideshow.Services;
|
||||
|
||||
internal static class CommandText {
|
||||
@ -40,7 +42,7 @@ internal static class CommandText {
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
internal static string GetAssetActiveImagePreviewNotDuplicate(float lowestVersionHistory, string[] filterTags) { // cSpell:disable
|
||||
internal static string GetAssetActiveImagePreviewNotDuplicate(float lowestVersionHistory, ReadOnlyCollection<string> filterTags, ReadOnlyCollection<string> people) { // cSpell:disable
|
||||
List<string> results = [
|
||||
" SELECT json_agg(j) ",
|
||||
" FROM ( ",
|
||||
@ -79,7 +81,7 @@ internal static class CommandText {
|
||||
} else {
|
||||
results.Add(" FROM public.asset a ");
|
||||
}
|
||||
results.AddRange(" INNER ");
|
||||
results.Add(" INNER ");
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" JOIN asset_files f ");
|
||||
} else {
|
||||
@ -107,7 +109,28 @@ internal static class CommandText {
|
||||
results.AddRange([
|
||||
" ON g.\"tagsId\" = t.\"id\" ",
|
||||
$" WHERE t.\"value\" in ('{string.Join("','", filterTags)}') ",
|
||||
" ) ",
|
||||
" ) "]);
|
||||
if (people.Count > 0) {
|
||||
results.AddRange([
|
||||
" AND a.\"id\" in ( ",
|
||||
" SELECT \"assetsId\" "
|
||||
]);
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM tag_asset g ");
|
||||
} else {
|
||||
results.Add(" FROM public.tag_asset g ");
|
||||
}
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" JOIN tags t ");
|
||||
} else {
|
||||
results.Add(" JOIN public.tag t ");
|
||||
}
|
||||
results.AddRange([
|
||||
" ON g.\"tagsId\" = t.\"id\" ",
|
||||
$" WHERE t.\"value\" in ('{string.Join("','", people)}') ",
|
||||
" ) "]);
|
||||
}
|
||||
results.AddRange([
|
||||
" AND a.\"isExternal\" = true ",
|
||||
" AND a.\"isOffline\" = false ",
|
||||
" AND a.\"ownerId\" = @ownerId ",
|
||||
|
Reference in New Issue
Block a user