From c8325aafca1aa447030d18118ebc44bad654fa24 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sat, 23 Nov 2024 11:53:11 -0700 Subject: [PATCH] Ready to test pulling random assets --- .vscode/launch.json | 2 +- .vscode/settings.json | 69 ++++++- .vscode/tasks.json | 11 ++ Dockerfile | 4 +- global.json | 2 +- requests/ImmichToSlideshow.http | 17 +- requests/google.http | 1 - .../Controllers/AssetsController.cs | 91 ++------- .../ServiceCollectionExtensions.cs | 4 +- .../ImmichToSlideshow.csproj | 2 +- src/ImmichToSlideshow/Models/Immich/Asset.cs | 55 +++--- src/ImmichToSlideshow/Program.cs | 35 ++-- .../WebApplicationExtensions.cs | 6 +- .../Services/AssetService.cs | 186 +++++++++++------- .../appsettings.Development.json | 8 - src/ImmichToSlideshow/appsettings.json | 9 - 16 files changed, 270 insertions(+), 232 deletions(-) delete mode 100644 requests/google.http delete mode 100644 src/ImmichToSlideshow/appsettings.Development.json delete mode 100644 src/ImmichToSlideshow/appsettings.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 4dc57b4..4cf6e7f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net8.0/ImmichToSlideshow.dll", + "program": "${workspaceFolder}/src/ImmichToSlideshow/bin/Debug/net9.0/ImmichToSlideshow.dll", "args": [ "s", "test" diff --git a/.vscode/settings.json b/.vscode/settings.json index 0261a1d..b0f4d33 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,15 +11,69 @@ }, "cSpell.words": [ "accessibilities", + "ackages", "Acks", "aspnet", "ASPNETCORE", + "binlog", + "buildhelp", + "cachefile", "CAXXXX", + "checkin", + "codegen", + "coveragexml", + "csdef", + "dbmdl", + "dbproj", "DENITED", + "dlldata", + "docstates", + "ebug", + "elease", + "eleases", + "esult", + "Fractors", + "gitea", "Immich", "Infineon", + "Installshield", + "iobj", + "ipch", + "ipdb", + "jmconfig", + "mfractor", "Npgsql", - "Thumbhash" + "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": { @@ -27,8 +81,19 @@ "reviewId": "asdfasdf" }, "dev": { + "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", "host": "http://localhost:5003", - "token": "ey..dev" + "token": "ey..dev", + }, + "affirm": { + "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", + "host": "https://products.affirm.duckdns.org/", + "token": "ey..affirm" + }, + "phares": { + "ownerId": "5f0b1052-466d-44de-a554-226d7256850d", + "host": "https://products.phares.duckdns.org/", + "token": "ey..phares" } } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1aee41c..4052324 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -104,6 +104,17 @@ "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" + }, + { + "label": "docker compose up --build", + "command": "docker", + "type": "process", + "args": [ + "compose", + "up", + "--build" + ], + "problemMatcher": "$msCompile" } ] } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a4162c6..975ad84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build Stage -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build WORKDIR /src @@ -17,7 +17,7 @@ FROM build AS publish RUN dotnet publish 'ImmichToSlideshow.csproj' -c Release -o /app/publish # Stage 3: Run Stage -FROM mcr.microsoft.com/dotnet/aspnet:8.0 +FROM mcr.microsoft.com/dotnet/aspnet:9.0 ENV ASPNETCORE_HTTP_PORTS=5001 EXPOSE 5001 WORKDIR /app diff --git a/global.json b/global.json index 744a6ea..3d8048a 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "rollForward": "latestMinor", - "version": "8.0.100" + "version": "9.0.100" } } \ No newline at end of file diff --git a/requests/ImmichToSlideshow.http b/requests/ImmichToSlideshow.http index 41f60ee..5d86e9a 100644 --- a/requests/ImmichToSlideshow.http +++ b/requests/ImmichToSlideshow.http @@ -1,6 +1,17 @@ -@immich_to_slideshow_HostAddress = http://localhost:5243 - -GET {{immich_to_slideshow_HostAddress}}/weatherforecast/ +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 \ No newline at end of file diff --git a/requests/google.http b/requests/google.http deleted file mode 100644 index 67c33ca..0000000 --- a/requests/google.http +++ /dev/null @@ -1 +0,0 @@ -GET www.google.com \ No newline at end of file diff --git a/src/ImmichToSlideshow/Controllers/AssetsController.cs b/src/ImmichToSlideshow/Controllers/AssetsController.cs index 4ee2a9e..6305699 100644 --- a/src/ImmichToSlideshow/Controllers/AssetsController.cs +++ b/src/ImmichToSlideshow/Controllers/AssetsController.cs @@ -1,93 +1,30 @@ -using ImmichToSlideshow.Models.Immich; using ImmichToSlideshow.Services; using Microsoft.AspNetCore.Mvc; -using System.Collections.ObjectModel; namespace ImmichToSlideshow.Controllers; [ApiController] -[Route("[controller]")] +[Route("api/v1/[controller]")] public class AssetsController(AssetService assetService) : ControllerBase { + private readonly string _ContentType = "application/json"; private readonly AssetService _AssetService = assetService; - [HttpGet()] - public IActionResult Get() - { - ReadOnlyCollection assets = _AssetService.Get(); - AssetResponse?[] assetResponses = AssetResponse.FromDomain(assets); - return Ok(assetResponses); - } + [HttpGet("columns")] + public IActionResult GetColumns() => + Content(_AssetService.GetColumns(), _ContentType); - [HttpPost] - public IActionResult Create(CreateAssetRequest request) - { - // mapping to internal representation - Asset asset = request.ToDomain(); + [HttpGet("owner-ids")] + public IActionResult GetOwnerIds() => + Content(_AssetService.GetOwnerIds(), _ContentType); - // invoke the use case - _AssetService.Create(asset); + [HttpGet("{ownerId:guid}")] + public IActionResult Get(Guid ownerId) => + Content(_AssetService.GetAssets(ownerId), _ContentType); - // mapping to external representation - AssetResponse assetResponse = AssetResponse.FromDomain(asset); - - // return 201 created response - return CreatedAtAction( - actionName: nameof(Get), - routeValues: new { AssetId = asset.Id }, - value: assetResponse); - } - - [HttpGet("{assetId:guid}")] - public IActionResult Get(Guid assetId) - { - //get the asset - Asset? asset = _AssetService.Get(assetId); - - // mapping to external representation - AssetResponse? assetResponse = AssetResponse.FromDomain(asset); - - // return 200 ok response - return assetResponse is null - ? Problem(statusCode: StatusCodes.Status404NotFound, detail: $"Asset not found {assetId}") - : Ok(assetResponse); - } - - public record CreateAssetRequest(string Id, - string DeviceAssetId, - string OwnerId, - string OriginalFileName, - string Path) - { - - public Asset ToDomain() => - Asset.Get(id: Id, - deviceAssetId: DeviceAssetId, - ownerId: OwnerId, - originalFileName: OriginalFileName, - path: Path); - - } - - public record AssetResponse(string Id, - string DeviceAssetId, - string OwnerId, - string OriginalFileName, - string Path) - { - - public static AssetResponse? FromDomain(Asset? asset) => - asset is null ? null : new AssetResponse( - Id: asset.Id, - DeviceAssetId: asset.DeviceAssetId, - OwnerId: asset.OwnerId, - OriginalFileName: asset.OriginalFileName, - Path: asset.Path); - - public static AssetResponse?[] FromDomain(IEnumerable assets) => - assets.Select(FromDomain).ToArray(); - - } + [HttpGet("{ownerId:guid}/random-paths")] + public IActionResult GetRandomPaths(Guid ownerId) => + Ok(_AssetService.GetRandomPaths(ownerId)); } \ No newline at end of file diff --git a/src/ImmichToSlideshow/DependencyInjection/ServiceCollectionExtensions.cs b/src/ImmichToSlideshow/DependencyInjection/ServiceCollectionExtensions.cs index 398591e..72c73f4 100644 --- a/src/ImmichToSlideshow/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/ImmichToSlideshow/DependencyInjection/ServiceCollectionExtensions.cs @@ -1,3 +1,4 @@ +using ImmichToSlideshow.Models; using ImmichToSlideshow.Services; namespace ImmichToSlideshow.DependencyInjection; @@ -5,9 +6,10 @@ namespace ImmichToSlideshow.DependencyInjection; public static class ServiceCollectionExtensions { - public static IServiceCollection AddServices(this IServiceCollection services) + public static IServiceCollection AddServices(this IServiceCollection services, AppSettings appSettings) { _ = services.AddScoped(); + _ = services.AddSingleton(_ => appSettings); return services; } diff --git a/src/ImmichToSlideshow/ImmichToSlideshow.csproj b/src/ImmichToSlideshow/ImmichToSlideshow.csproj index 7131c50..235e41e 100644 --- a/src/ImmichToSlideshow/ImmichToSlideshow.csproj +++ b/src/ImmichToSlideshow/ImmichToSlideshow.csproj @@ -2,7 +2,7 @@ enable enable - net8.0 + net9.0 win-x64;linux-x64 cc24ad7a-1d95-4c47-a3ea-0d8475ab06da diff --git a/src/ImmichToSlideshow/Models/Immich/Asset.cs b/src/ImmichToSlideshow/Models/Immich/Asset.cs index be80571..3118023 100644 --- a/src/ImmichToSlideshow/Models/Immich/Asset.cs +++ b/src/ImmichToSlideshow/Models/Immich/Asset.cs @@ -5,32 +5,32 @@ namespace ImmichToSlideshow.Models.Immich; public record Asset([property: JsonPropertyName("id")] string Id, [property: JsonPropertyName("deviceAssetId")] string DeviceAssetId, - [property: JsonPropertyName("ownerId")] string OwnerId, - [property: JsonPropertyName("deviceId")] string DeviceId, - [property: JsonPropertyName("type")] string Type, + // [property: JsonPropertyName("ownerId")] string OwnerId, + // [property: JsonPropertyName("deviceId")] string DeviceId, + // [property: JsonPropertyName("type")] string Type, [property: JsonPropertyName("originalPath")] string OriginalPath, - [property: JsonPropertyName("fileCreatedAt")] DateTime FileCreatedAt, - [property: JsonPropertyName("fileModifiedAt")] DateTime FileModifiedAt, - [property: JsonPropertyName("isFavorite")] bool IsFavorite, - [property: JsonPropertyName("duration")] string Duration, - [property: JsonPropertyName("encodedVideoPath")] string EncodedVideoPath, - [property: JsonPropertyName("checksum")] string Checksum, - [property: JsonPropertyName("isVisible")] bool IsVisible, - [property: JsonPropertyName("livePhotoVideoId")] object LivePhotoVideoId, - [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt, - [property: JsonPropertyName("createdAt")] DateTime CreatedAt, - [property: JsonPropertyName("isArchived")] bool IsArchived, + // [property: JsonPropertyName("fileCreatedAt")] DateTime FileCreatedAt, + // [property: JsonPropertyName("fileModifiedAt")] DateTime FileModifiedAt, + // [property: JsonPropertyName("isFavorite")] bool IsFavorite, + // [property: JsonPropertyName("duration")] string? Duration, + // [property: JsonPropertyName("encodedVideoPath")] string EncodedVideoPath, + // [property: JsonPropertyName("checksum")] string Checksum, + // [property: JsonPropertyName("isVisible")] bool IsVisible, + // [property: JsonPropertyName("livePhotoVideoId")] object? LivePhotoVideoId, + // [property: JsonPropertyName("updatedAt")] DateTime UpdatedAt, + // [property: JsonPropertyName("createdAt")] DateTime CreatedAt, + // [property: JsonPropertyName("isArchived")] bool IsArchived, [property: JsonPropertyName("originalFileName")] string OriginalFileName, - [property: JsonPropertyName("sidecarPath")] object SidecarPath, - [property: JsonPropertyName("thumbhash")] string Thumbhash, - [property: JsonPropertyName("isOffline")] bool IsOffline, - [property: JsonPropertyName("libraryId")] string LibraryId, - [property: JsonPropertyName("isExternal")] bool IsExternal, - [property: JsonPropertyName("deletedAt")] object DeletedAt, - [property: JsonPropertyName("localDateTime")] DateTime LocalDateTime, - [property: JsonPropertyName("stackId")] object StackId, - [property: JsonPropertyName("duplicateId")] string DuplicateId, - [property: JsonPropertyName("status")] string Status, + // [property: JsonPropertyName("sidecarPath")] object? SidecarPath, + // [property: JsonPropertyName("thumbhash")] string Thumbhash, + // [property: JsonPropertyName("isOffline")] bool IsOffline, + // [property: JsonPropertyName("libraryId")] string LibraryId, + // [property: JsonPropertyName("isExternal")] bool IsExternal, + // [property: JsonPropertyName("deletedAt")] object? DeletedAt, + // [property: JsonPropertyName("localDateTime")] DateTime LocalDateTime, + // [property: JsonPropertyName("stackId")]? object? StackId, + [property: JsonPropertyName("duplicateId")] string? DuplicateId, + // [property: JsonPropertyName("status")] string Status, [property: JsonPropertyName("path")] string Path) { @@ -40,13 +40,6 @@ public record Asset([property: JsonPropertyName("id")] string Id, return result; } - public static Asset Get(string id, - string deviceAssetId, - string ownerId, - string originalFileName, - string path) => - throw new Exception(); - } [JsonSourceGenerationOptions(WriteIndented = true)] diff --git a/src/ImmichToSlideshow/Program.cs b/src/ImmichToSlideshow/Program.cs index 943f94d..39cc3ad 100644 --- a/src/ImmichToSlideshow/Program.cs +++ b/src/ImmichToSlideshow/Program.cs @@ -2,21 +2,22 @@ using ImmichToSlideshow.DependencyInjection; using ImmichToSlideshow.Models; using ImmichToSlideshow.RequestPipeline; -WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args); +namespace ImmichToSlideshow; + +public class Program { - // configure services (DI) - _ = webApplicationBuilder.Services.AddServices(); - _ = webApplicationBuilder.Services.AddControllers(); - _ = webApplicationBuilder.Configuration.AddUserSecrets(); - AppSettings appSettings = ImmichToSlideshow.Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); - _ = webApplicationBuilder.Services.AddSingleton(_ => appSettings); -} -WebApplication webApplication = webApplicationBuilder.Build(); -{ - // configure request pipeline - _ = webApplication.MapControllers(); - _ = webApplication.InitializeDatabase(); -} -ILogger? logger = webApplication.Services.GetRequiredService>(); -logger.LogInformation("Starting Web Application"); -webApplication.Run(); + + public static void Main(string[] args) + { + WebApplicationBuilder webApplicationBuilder = WebApplication.CreateBuilder(args); + _ = webApplicationBuilder.Configuration.AddUserSecrets(); + AppSettings appSettings = Models.Binder.AppSettings.Get(webApplicationBuilder.Configuration); + _ = webApplicationBuilder.Services.AddControllers(); + _ = webApplicationBuilder.Services.AddServices(appSettings); + WebApplication webApplication = webApplicationBuilder.Build(); + _ = webApplication.MapControllers(); + _ = webApplication.InitializeDatabase(); + webApplication.Run(); + } + +} \ No newline at end of file diff --git a/src/ImmichToSlideshow/RequestPipeline/WebApplicationExtensions.cs b/src/ImmichToSlideshow/RequestPipeline/WebApplicationExtensions.cs index c7e5f7c..0a16b35 100644 --- a/src/ImmichToSlideshow/RequestPipeline/WebApplicationExtensions.cs +++ b/src/ImmichToSlideshow/RequestPipeline/WebApplicationExtensions.cs @@ -3,10 +3,12 @@ namespace ImmichToSlideshow.RequestPipeline; public static class WebApplicationExtensions { - public static WebApplication InitializeDatabase(this WebApplication application) + public static WebApplication InitializeDatabase(this WebApplication webApplication) { + ILogger? logger = webApplication.Services.GetRequiredService>(); + logger.LogInformation("Starting Web Application"); // DBInitializer.Initialize(application.Configuration[DbConstants.DefaultConnectionStringPath]!); - return application; + return webApplication; } } \ No newline at end of file diff --git a/src/ImmichToSlideshow/Services/AssetService.cs b/src/ImmichToSlideshow/Services/AssetService.cs index 278a5ac..1679ee3 100644 --- a/src/ImmichToSlideshow/Services/AssetService.cs +++ b/src/ImmichToSlideshow/Services/AssetService.cs @@ -1,5 +1,5 @@ -using ImmichToSlideshow.Models.Immich; using ImmichToSlideshow.Models; +using ImmichToSlideshow.Models.Immich; using Npgsql; using System.Collections.ObjectModel; using System.Data; @@ -8,17 +8,12 @@ using System.Text.Json; namespace ImmichToSlideshow.Services; -public class AssetService +public class AssetService(AppSettings appSettings) { - private readonly AppSettings _AppSettings; + private readonly AppSettings _AppSettings = appSettings; - public AssetService(AppSettings appSettings) => - _AppSettings = appSettings; - - private static readonly List _AssetsRepository = []; - - private static string GetCommandText() + private static string GetColumnsCommandText() { // cSpell:disable List results = new(); // results.Add(" SELECT COALESCE(SUM(checksum_failures), 0) "); @@ -27,97 +22,136 @@ public class AssetService // results.Add(" FROM information_schema.tables t "); // results.Add(" WHERE table_schema='public' "); // results.Add(" AND table_type='BASE TABLE' "); - // results.Add(" SELECT json_agg(c) "); - // results.Add(" FROM information_schema.columns c "); + results.Add(" SELECT json_agg(c) "); + results.Add(" FROM information_schema.columns c "); // results.Add(" WHERE table_name ='assets' "); // results.Add(" WHERE table_name ='libraries' "); - // results.Add(" WHERE table_name ='asset_files' "); + results.Add(" WHERE table_name ='asset_files' "); + return string.Join(Environment.NewLine, results); + } // cSpell:enable + + private static string GetOwnerIdActiveImageCommandText() + { // cSpell:disable + List results = new(); results.Add(" SELECT json_agg(j) "); results.Add(" FROM ( "); - results.Add(" SELECT a.* "); - results.Add(" , f.\"path\" "); + results.Add(" SELECT a.\"ownerId\" "); results.Add(" FROM assets a "); - // results.Add(" FROM asset_files f "); - results.Add(" INNER "); - results.Add(" JOIN asset_files f "); - results.Add(" ON a.\"id\" = f.\"assetId\" "); - results.Add(" AND f.\"type\" = 'preview' "); results.Add(" WHERE a.\"status\" = 'active' "); - // results.Add(" WHERE f.\"assetId\" = '4c1933ce-f5b3-4348-bcc3-978f99823d70' "); - results.Add(" AND a.\"isExternal\" = true "); - results.Add(" AND a.\"isOffline\" = false "); - results.Add(" AND a.\"isVisible\" = true "); - // results.Add(" AND a.\"id\" = '4c1933ce-f5b3-4348-bcc3-978f99823d70' "); - // results.Add(" AND a.\"originalFileName\""); - // results.Add(" LIKE '%still%' "); - // results.Add(" AND a.\"originalFileName\" = '979270910999.jpg' "); + results.Add(" AND a.\"type\" = 'IMAGE' "); + results.Add(" GROUP"); + results.Add(" BY a.\"ownerId\" "); results.Add(" ) j "); return string.Join(Environment.NewLine, results); } // cSpell:enable - private static int? ExecuteNonQuery(string connectionString, string commandText) - { - int? result; - if (string.IsNullOrEmpty(connectionString)) - result = null; - else - { - using NpgsqlConnection npgsqlConnection = new(connectionString); - npgsqlConnection.Open(); - using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection); - result = npgsqlCommand.ExecuteNonQuery(); - } - return result; - } + private static string GetAssetActiveImagePreviewNotDuplicateCommandText() + { // cSpell:disable + List results = new(); + results.Add(" SELECT json_agg(j) "); + results.Add(" FROM ( "); + results.Add(" SELECT a.\"id\" "); + results.Add(" , a.\"deviceAssetId\" "); + // results.Add(" , a.\"ownerId\" "); + // results.Add(" , a.\"deviceId\" "); + // results.Add(" , a.\"type\" "); + results.Add(" , a.\"originalPath\" "); + // results.Add(" , a.\"fileCreatedAt\" "); + // results.Add(" , a.\"fileModifiedAt\" "); + // results.Add(" , a.\"isFavorite\" "); + // results.Add(" , a.\"duration\" "); + // results.Add(" , a.\"encodedVideoPath\" "); + // results.Add(" , a.\"checksum\" "); + // results.Add(" , a.\"isVisible\" "); + // results.Add(" , a.\"livePhotoVideoId\" "); + // results.Add(" , a.\"updatedAt\" "); + // results.Add(" , a.\"createdAt\" "); + // results.Add(" , a.\"isArchived\" "); + results.Add(" , a.\"originalFileName\" "); + // results.Add(" , a.\"sidecarPath\" "); + // results.Add(" , a.\"thumbhash\" "); + // results.Add(" , a.\"isOffline\" "); + // results.Add(" , a.\"libraryId\" "); + // results.Add(" , a.\"isExternal\" "); + // results.Add(" , a.\"deletedAt\" "); + // results.Add(" , a.\"localDateTime\" "); + // results.Add(" , a.\"stackId\" "); + results.Add(" , a.\"duplicateId\" "); + // results.Add(" , a.\"status\" "); + results.Add(" , f.\"path\" "); + results.Add(" FROM assets a "); + results.Add(" INNER "); + results.Add(" JOIN asset_files f "); + results.Add(" ON a.\"id\" = f.\"assetId\" "); + results.Add(" WHERE a.\"status\" = 'active' "); + results.Add(" AND a.\"type\" = 'IMAGE' "); + results.Add(" AND f.\"type\" = 'preview' "); + results.Add(" AND a.\"duplicateId\" is null "); + results.Add(" AND a.\"isExternal\" = true "); + results.Add(" AND a.\"isOffline\" = false "); + results.Add(" AND a.\"isVisible\" = true "); + results.Add(" AND a.\"ownerId\" = @ownerId "); + results.Add(" ) j "); + return string.Join(Environment.NewLine, results); + } // cSpell:enable - private static StringBuilder GetForJsonPath(string connectionString, string commandText) + private static StringBuilder GetForJsonPath(string connectionString, string commandText, NpgsqlParameter[] npgsqlParameters) { StringBuilder stringBuilder = new(); using NpgsqlConnection npgsqlConnection = new(connectionString); npgsqlConnection.Open(); using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection); + npgsqlCommand.Parameters.AddRange(npgsqlParameters); NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.SequentialAccess); while (npgsqlDataReader.Read()) _ = stringBuilder.Append(npgsqlDataReader.GetString(0)); return stringBuilder; } - public ReadOnlyCollection? Get() + public string? GetColumns() { - string commandText = GetCommandText(); - if (commandText.Length == 1) - { - int? result = ExecuteNonQuery(_AppSettings.ConnectionString, commandText); - if (result is null) - { } - } - StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText); - if (commandText.Length == 1) - File.WriteAllText(".vscode/jsonl/.jsonl", stringBuilder.ToString()); - string json = stringBuilder.ToString(); + string commandText = GetColumnsCommandText(); + NpgsqlParameter[] npgsqlParameters = []; + StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters); + string json = stringBuilder.ToString(); + if (json.Length == 1) + File.WriteAllText(".vscode/jsonl/.jsonl", json); + return json; + } + + public string? GetOwnerIds() + { + string commandText = GetOwnerIdActiveImageCommandText(); + NpgsqlParameter[] npgsqlParameters = []; + StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters); + string json = stringBuilder.ToString(); + if (json.Length == 1) + File.WriteAllText(".vscode/jsonl/.jsonl", json); + return json; + } + + public string? GetAssets(Guid ownerId) + { + string commandText = GetAssetActiveImagePreviewNotDuplicateCommandText(); + NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)]; + StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters); + string json = stringBuilder.ToString(); + if (json.Length == 1) + File.WriteAllText(".vscode/jsonl/assets.jsonl", json); + return json; + } + + public ReadOnlyCollection? GetRandomPaths(Guid ownerId) + { + string commandText = GetAssetActiveImagePreviewNotDuplicateCommandText(); + NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)]; + StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters); + string json = stringBuilder.ToString(); + Random random = new(); + string ownerIdValue = ownerId.ToString(); Asset[]? assets = JsonSerializer.Deserialize(json, AssetCollectionSourceGenerationContext.Default.AssetArray); - return assets?.AsReadOnly(); + string[]? paths = assets is null ? null : (from l in assets orderby random.NextSingle() select l.Path.Split(ownerIdValue)[1][1..]).ToArray(); + return paths?.AsReadOnly(); } - // 1. fetch user - // 1. fetch asset - // 1. check wether the user reached the - // 1. update the user - // 1. save the asset - public void Create(Asset asset) - { - // Guid userId, - if (asset is null) - throw new ArgumentNullException(nameof(asset)); - - // User user = _UsersRepository.Find(x => x.Id == userId) - // ?? throw new InvalidOperationException(); - - // user.AddAsset(asset); - _AssetsRepository.Add(asset); - } - - public Asset? Get(Guid assetId) => - _AssetsRepository.Find(l => l.Id == assetId.ToString()); - } \ No newline at end of file diff --git a/src/ImmichToSlideshow/appsettings.Development.json b/src/ImmichToSlideshow/appsettings.Development.json deleted file mode 100644 index 0c208ae..0000000 --- a/src/ImmichToSlideshow/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/src/ImmichToSlideshow/appsettings.json b/src/ImmichToSlideshow/appsettings.json deleted file mode 100644 index 10f68b8..0000000 --- a/src/ImmichToSlideshow/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -}