Compare commits

1 Commits

Author SHA1 Message Date
8034f79753 Birthday
hurl file over http file

AddControllers

Formatting
2025-09-20 14:18:46 -07:00
13 changed files with 307 additions and 193 deletions

View File

@ -28,7 +28,7 @@ csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = none csharp_new_line_before_open_brace = none
csharp_new_line_between_query_expression_clauses = true csharp_new_line_between_query_expression_clauses = true
csharp_prefer_braces = false csharp_prefer_braces = true
csharp_prefer_qualified_reference = true:error csharp_prefer_qualified_reference = true:error
csharp_prefer_simple_default_expression = true:warning csharp_prefer_simple_default_expression = true:warning
csharp_prefer_simple_using_statement = true:warning csharp_prefer_simple_using_statement = true:warning

2
.vscode/launch.json vendored
View File

@ -8,7 +8,7 @@
"name": ".NET Core Launch (console)", "name": ".NET Core Launch (console)",
"type": "coreclr", "type": "coreclr",
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "Build",
"program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net9.0/ImmichToSlideshow.dll", "program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net9.0/ImmichToSlideshow.dll",
"args": [ "args": [
"s", "s",

195
.vscode/settings.json vendored
View File

@ -1,100 +1,107 @@
{ {
"[markdown]": { "files.associations": {
"editor.wordWrap": "off" "*.ffs_gui": "xml",
"*.hurl": "http",
"*.org": "ini",
"*.net": "ini",
"default": "ini"
},
"[markdown]": {
"editor.wordWrap": "off"
},
"files.exclude": {
"**/.git": false,
"**/node_modules": true
},
"files.watcherExclude": {
"**/node_modules": true
},
"cSpell.words": [
"accessibilities",
"ackages",
"Acks",
"aspnet",
"ASPNETCORE",
"binlog",
"buildhelp",
"cachefile",
"CAXXXX",
"checkin",
"codegen",
"coveragexml",
"csdef",
"dbmdl",
"dbproj",
"DENITED",
"Digi",
"dlldata",
"docstates",
"ebug",
"elease",
"eleases",
"esult",
"Fractors",
"gitea",
"Immich",
"Infineon",
"Installshield",
"iobj",
"ipch",
"ipdb",
"jmconfig",
"mfractor",
"Npgsql",
"Nsight",
"ntvs",
"NUNIT",
"nupkg",
"nvuser",
"opendb",
"opensdf",
"paket",
"Paket",
"pidb",
"psess",
"PTVS",
"publishproj",
"publishsettings",
"pycache",
"rptproj",
"rsuser",
"schemaview",
"Silverlight",
"svclog",
"Telerik's",
"Thumbhash",
"ublish",
"uild",
"userosscache",
"userprefs",
"vspscc",
"vspx",
"vssscc",
"wwwroot",
"xpress"
],
"rest-client.environmentVariables": {
"$shared": {
"productId": "asdfasdf",
"reviewId": "asdfasdf"
}, },
"files.exclude": { "dev": {
"**/.git": false, "ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"**/node_modules": true "host": "https://localhost:5003",
"token": "ey..dev",
}, },
"files.watcherExclude": { "affirm": {
"**/node_modules": true "ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://immich-to-slideshow.affirm.duckdns.org/",
"token": "ey..affirm"
}, },
"cSpell.words": [ "phares": {
"accessibilities", "ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"ackages", "host": "https://immich-to-slideshow.phares.duckdns.org/",
"Acks", "token": "ey..phares"
"aspnet",
"ASPNETCORE",
"binlog",
"buildhelp",
"cachefile",
"CAXXXX",
"checkin",
"codegen",
"coveragexml",
"csdef",
"dbmdl",
"dbproj",
"DENITED",
"Digi",
"dlldata",
"docstates",
"ebug",
"elease",
"eleases",
"esult",
"Fractors",
"gitea",
"Immich",
"Infineon",
"Installshield",
"iobj",
"ipch",
"ipdb",
"jmconfig",
"mfractor",
"Npgsql",
"Nsight",
"ntvs",
"NUNIT",
"nupkg",
"nvuser",
"opendb",
"opensdf",
"paket",
"Paket",
"pidb",
"psess",
"PTVS",
"publishproj",
"publishsettings",
"pycache",
"rptproj",
"rsuser",
"schemaview",
"Silverlight",
"svclog",
"Telerik's",
"Thumbhash",
"ublish",
"uild",
"userosscache",
"userprefs",
"vspscc",
"vspx",
"vssscc",
"wwwroot",
"xpress"
],
"rest-client.environmentVariables": {
"$shared": {
"productId": "asdfasdf",
"reviewId": "asdfasdf"
},
"dev": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://localhost:5003",
"token": "ey..dev",
},
"affirm": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://immich-to-slideshow.affirm.duckdns.org/",
"token": "ey..affirm"
},
"phares": {
"ownerId": "5f0b1052-466d-44de-a554-226d7256850d",
"host": "https://immich-to-slideshow.phares.duckdns.org/",
"token": "ey..phares"
}
} }
}
} }

24
.vscode/tasks.json vendored
View File

@ -43,7 +43,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "Format-Whitespaces", "label": "Format Whitespaces",
"command": "dotnet", "command": "dotnet",
"type": "process", "type": "process",
"args": [ "args": [
@ -53,7 +53,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "build", "label": "Build",
"command": "dotnet", "command": "dotnet",
"type": "process", "type": "process",
"args": [ "args": [
@ -65,7 +65,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "publish", "label": "Publish",
"command": "dotnet", "command": "dotnet",
"type": "process", "type": "process",
"args": [ "args": [
@ -77,7 +77,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "watch", "label": "Watch",
"command": "dotnet", "command": "dotnet",
"type": "process", "type": "process",
"args": [ "args": [
@ -89,7 +89,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-login", "label": "Podman Login",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
@ -99,7 +99,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-compose-up-build", "label": "Podman Compose Up Build",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
@ -110,7 +110,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-build", "label": "Podman Build",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
@ -122,7 +122,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-image-list", "label": "Podman Image List",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
@ -132,7 +132,7 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-run", "label": "Podman Run",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
@ -146,18 +146,18 @@
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-tag", "label": "Podman Tag",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [
"tag", "tag",
"asdf", "3f9eac99b7cf0710c5d762322ce4ded3f57fc008ee8310757760bb78ad8e029f",
"gitea.phares.duckdns.org:443/phares3757/immich-to-slideshow:latest" "gitea.phares.duckdns.org:443/phares3757/immich-to-slideshow:latest"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{ {
"label": "podman-push", "label": "Podman Push",
"command": "podman", "command": "podman",
"type": "process", "type": "process",
"args": [ "args": [

View File

@ -1,46 +0,0 @@
@host = http://0.0.0.0:5001
GET {{host}}/api/v1/assets/columns/
Accept: application/json
###
GET {{host}}/api/v1/assets/owner-ids/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/random-paths/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/save-random-paths/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/sync-immich/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/set-archive-immich/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/set-digi-kam-4-archive-immich/
Accept: application/json
###
GET {{host}}/api/v1/assets/{{ownerId}}/archived-tag/
Accept: application/json
###

View File

@ -0,0 +1,80 @@
GET http://127.0.0.1:5001/api/v1/assets/columns/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/owner-ids/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/random-paths/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/save-random-paths/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/sync-immich/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/set-archive-immich/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/set-digi-kam-4-archive-immich/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###
GET http://127.0.0.1:5001/api/v1/assets/5f0b1052-466d-44de-a554-226d7256850d/archived-tag/
Accept: application/json
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
###

View File

@ -25,15 +25,15 @@ public class AssetsController(AssetService assetService) : ControllerBase {
[HttpGet("{ownerId:guid}/random-paths")] [HttpGet("{ownerId:guid}/random-paths")]
public IActionResult GetRandomPaths(Guid ownerId) => public IActionResult GetRandomPaths(Guid ownerId) =>
Ok(_AssetService.GetRandomPaths(ownerId)); Ok(_AssetService.GetRandomPaths(ownerId, monthDay: null));
[HttpGet("{ownerId:guid}/archived-tag")] [HttpGet("{ownerId:guid}/archived-tag")]
public IActionResult GetArchivedTag(Guid ownerId) => public IActionResult GetArchivedTag(Guid ownerId) =>
Content(_AssetService.GetArchivedTag(ownerId) ?? string.Empty, _ContentType); Content(_AssetService.GetArchivedTag(ownerId) ?? string.Empty, _ContentType);
[HttpGet("{ownerId:guid}/save-random-paths")] [HttpGet("{ownerId:guid}/save-random-paths")]
public IActionResult SaveRandomPaths(Guid ownerId) => public IActionResult SaveRandomPaths(Guid ownerId, string? month_day) =>
Content(_AssetService.SaveRandomPaths(ownerId) ?? string.Empty, _ContentType); Content(_AssetService.SaveRandomPaths(ownerId, monthDay: month_day) ?? string.Empty, _ContentType);
[HttpGet("{ownerId:guid}/sync-immich")] [HttpGet("{ownerId:guid}/sync-immich")]
public IActionResult SyncImmich(Guid ownerId) => public IActionResult SyncImmich(Guid ownerId) =>

View File

@ -6,6 +6,7 @@ namespace ImmichToSlideshow.DependencyInjection;
public static class ServiceCollectionExtensions { public static class ServiceCollectionExtensions {
public static IServiceCollection AddServices(this IServiceCollection services, AppSettings appSettings) { public static IServiceCollection AddServices(this IServiceCollection services, AppSettings appSettings) {
_ = services.AddControllers();
_ = services.AddScoped<AssetService>(); _ = services.AddScoped<AssetService>();
_ = services.AddSingleton(_ => appSettings); _ = services.AddSingleton(_ => appSettings);
return services; return services;

View File

@ -11,28 +11,45 @@ public record AppSettings(string Company, Settings Settings, string URLs, string
} }
private static void Verify(AppSettings appSettings) { private static void Verify(AppSettings appSettings) {
if (appSettings?.Company is null) if (appSettings?.Company is null) {
throw new NullReferenceException(nameof(Company)); throw new NullReferenceException(nameof(Company));
if (appSettings?.URLs is null) }
if (appSettings?.URLs is null) {
throw new NullReferenceException(nameof(URLs)); throw new NullReferenceException(nameof(URLs));
if (appSettings?.WithOrigins is null) }
if (appSettings?.WithOrigins is null) {
throw new NullReferenceException(nameof(WithOrigins)); throw new NullReferenceException(nameof(WithOrigins));
if (appSettings?.Settings?.AddDays is null) }
if (appSettings?.Settings?.AddDays is null) {
throw new NullReferenceException(nameof(Settings.AddDays)); 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)); throw new NullReferenceException(nameof(Settings.ArchivedTag));
if (appSettings?.Settings?.ConnectionString is null) }
if (appSettings?.Settings?.ConnectionString is null) {
throw new NullReferenceException(nameof(Settings.ConnectionString)); throw new NullReferenceException(nameof(Settings.ConnectionString));
if (appSettings?.Settings?.DigiKam4 is null) }
if (appSettings?.Settings?.DigiKam4 is null) {
throw new NullReferenceException(nameof(Settings.DigiKam4)); throw new NullReferenceException(nameof(Settings.DigiKam4));
if (appSettings?.Settings?.FilterTags is null) }
if (appSettings?.Settings?.FilterTags is null) {
throw new NullReferenceException(nameof(Settings.FilterTags)); throw new NullReferenceException(nameof(Settings.FilterTags));
if (appSettings?.Settings?.ImmichUploadDirectory is null) }
if (appSettings?.Settings?.ImmichUploadDirectory is null) {
throw new NullReferenceException(nameof(Settings.ImmichUploadDirectory)); 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)); throw new NullReferenceException(nameof(Settings.RandomResultsDirectory));
if (appSettings?.Settings?.SyncDirectory is null) }
if (appSettings?.Settings?.SyncDirectory is null) {
throw new NullReferenceException(nameof(Settings.SyncDirectory)); throw new NullReferenceException(nameof(Settings.SyncDirectory));
}
} }
public static AppSettings Get(IConfigurationRoot configurationRoot) { 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) { if (company is null || settings is null || urls is null || withOrigins is null) {
List<string> paths = []; List<string> paths = [];
foreach (IConfigurationProvider configurationProvider in configurationRoot.Providers) { 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; continue;
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) }
if (jsonConfigurationProvider.Source.FileProvider is not Microsoft.Extensions.FileProviders.PhysicalFileProvider physicalFileProvider) {
continue; continue;
}
paths.Add(physicalFileProvider.Root); paths.Add(physicalFileProvider.Root);
} }
throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}"); throw new NotSupportedException($"Not found!{Environment.NewLine}{string.Join(Environment.NewLine, paths.Distinct())}");

View File

@ -5,12 +5,14 @@ namespace ImmichToSlideshow.Models;
public record Settings(int AddDays, public record Settings(int AddDays,
string ArchivedTag, string ArchivedTag,
string BirthdayFormat,
string ConnectionString, string ConnectionString,
DigiKam4? DigiKam4, DigiKam4? DigiKam4,
string[] FilterTags, string[] FilterTags,
string ImmichUploadDirectory, string ImmichUploadDirectory,
float LowestVersionHistory, float LowestVersionHistory,
string NotNinePath, string NotNinePath,
Dictionary<string, string> People,
string RandomResultsDirectory, string RandomResultsDirectory,
string SyncDirectory) { string SyncDirectory) {

View File

@ -10,7 +10,6 @@ public class Program {
WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args); WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args);
_ = webApplicationBuilder.Configuration.AddUserSecrets<Program>(); _ = webApplicationBuilder.Configuration.AddUserSecrets<Program>();
AppSettings appSettings = AppSettings.Get(webApplicationBuilder.Configuration); AppSettings appSettings = AppSettings.Get(webApplicationBuilder.Configuration);
_ = webApplicationBuilder.Services.AddControllers();
_ = webApplicationBuilder.Services.AddServices(appSettings); _ = webApplicationBuilder.Services.AddServices(appSettings);
WebApplication webApplication = webApplicationBuilder.Build(); WebApplication webApplication = webApplicationBuilder.Build();
ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>(); ILogger<Program>? logger = webApplication.Services.GetRequiredService<ILogger<Program>>();

View File

@ -69,8 +69,9 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
public string? GetAssets(Guid ownerId) { public string? GetAssets(Guid ownerId) {
string result; string result;
ReadOnlyCollection<string> people = Array.Empty<string>().AsReadOnly();
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)]; 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()); StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
result = stringBuilder.ToString(); result = stringBuilder.ToString();
if (result.Length == 1) { if (result.Length == 1) {
@ -79,13 +80,31 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
return result; return result;
} }
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId) { public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId, string? monthDay) {
string[]? results; string[]? results;
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)]; string commandText;
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
string json = stringBuilder.ToString();
Random random = new(); Random random = new();
List<string> people = [];
StringBuilder stringBuilder;
if (!string.IsNullOrEmpty(monthDay)) {
foreach (KeyValuePair<string, string> keyValuePair in _Settings.People) {
if (!keyValuePair.Key.Contains(monthDay)) {
continue;
}
people.Add($"People/{keyValuePair.Value.Trim('/')}");
}
}
try {
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags.AsReadOnly(), people.AsReadOnly());
stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
} catch (Exception) {
people.Clear();
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags.AsReadOnly(), people.AsReadOnly());
stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
}
string json = stringBuilder.ToString();
string ownerIdValue = ownerId.ToString(); string ownerIdValue = ownerId.ToString();
Asset[]? assets = JsonSerializer.Deserialize(json, AssetCollectionSourceGenerationContext.Default.AssetArray); Asset[]? assets = JsonSerializer.Deserialize(json, AssetCollectionSourceGenerationContext.Default.AssetArray);
results = assets is null ? null : (from l in assets orderby random.NextSingle() select l.Path.Split(ownerIdValue)[1]).ToArray(); results = assets is null ? null : (from l in assets orderby random.NextSingle() select l.Path.Split(ownerIdValue)[1]).ToArray();
@ -114,25 +133,35 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
return result; return result;
} }
public string? SaveRandomPaths(Guid ownerId) { public string? SaveRandomPaths(Guid ownerId, string? monthDay) {
string? results; string? results = null;
FileInfo fileInfo;
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
string tomorrow = dateTime.AddDays(1).ToString("MM-dd"); ReadOnlyCollection<string>? paths;
bool? check = monthDay is null ? null : monthDay == "00-00";
if (Directory.Exists(_Settings.RandomResultsDirectory)) { if (Directory.Exists(_Settings.RandomResultsDirectory)) {
_ = Directory.CreateDirectory(_Settings.RandomResultsDirectory); _ = Directory.CreateDirectory(_Settings.RandomResultsDirectory);
} }
FileInfo fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{tomorrow}.json")); for (int i = 0; i < 366; i++) {
if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_Settings.AddDays)) { if (check is null || check.Value) {
results = null; monthDay = i == 0 && check is not null && check.Value ? "02-29" : dateTime.AddDays(i).ToString("MM-dd");
} else { }
_Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName); fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{monthDay}.json"));
ReadOnlyCollection<string>? paths = GetRandomPaths(ownerId); if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_Settings.AddDays)) {
if (paths is null) {
results = null; results = null;
} else { } else {
_Logger.LogInformation("{count} path(s)", paths.Count.ToString()); _Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName);
results = JsonSerializer.Serialize(paths); paths = GetRandomPaths(ownerId, monthDay);
File.WriteAllText(fileInfo.FullName, results); if (paths is null) {
results = null;
} else {
_Logger.LogInformation("{count} path(s)", paths.Count.ToString());
results = JsonSerializer.Serialize(paths);
File.WriteAllText(fileInfo.FullName, results);
}
}
if (check is null || !check.Value) {
break;
} }
} }
return results; return results;

View File

@ -1,3 +1,5 @@
using System.Collections.ObjectModel;
namespace ImmichToSlideshow.Services; namespace ImmichToSlideshow.Services;
internal static class CommandText { internal static class CommandText {
@ -40,7 +42,7 @@ internal static class CommandText {
return string.Join(Environment.NewLine, results); return string.Join(Environment.NewLine, results);
} // cSpell:enable } // 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 = [ List<string> results = [
" SELECT json_agg(j) ", " SELECT json_agg(j) ",
" FROM ( ", " FROM ( ",
@ -79,7 +81,7 @@ internal static class CommandText {
} else { } else {
results.Add(" FROM public.asset a "); results.Add(" FROM public.asset a ");
} }
results.AddRange(" INNER "); results.Add(" INNER ");
if (lowestVersionHistory <= 1.129) { if (lowestVersionHistory <= 1.129) {
results.Add(" JOIN asset_files f "); results.Add(" JOIN asset_files f ");
} else { } else {
@ -107,7 +109,28 @@ internal static class CommandText {
results.AddRange([ results.AddRange([
" ON g.\"tagsId\" = t.\"id\" ", " ON g.\"tagsId\" = t.\"id\" ",
$" WHERE t.\"value\" in ('{string.Join("','", filterTags)}') ", $" 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.\"isExternal\" = true ",
" AND a.\"isOffline\" = false ", " AND a.\"isOffline\" = false ",
" AND a.\"ownerId\" = @ownerId ", " AND a.\"ownerId\" = @ownerId ",