DigiKam4 Archive
Change to only need the one json file and changed AppSettings to not need a binder file Editorconfig for no new line before open braces Nuget package bumps Database lowest-version-history
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using ImmichToSlideshow.Domain;
|
||||
using ImmichToSlideshow.Models;
|
||||
using ImmichToSlideshow.Models.Immich;
|
||||
using Npgsql;
|
||||
@ -8,21 +9,18 @@ using System.Text.Json;
|
||||
|
||||
namespace ImmichToSlideshow.Services;
|
||||
|
||||
public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
{
|
||||
public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
|
||||
|
||||
#pragma warning disable CS9124
|
||||
private readonly ILogger<Program> _Logger = logger;
|
||||
private readonly AppSettings _AppSettings = appSettings;
|
||||
private readonly Settings _Settings = appSettings.Settings;
|
||||
#pragma warning restore CS9124
|
||||
|
||||
private static int? ExecuteNonQuery(string connectionString, string commandText, ReadOnlyCollection<NpgsqlParameter> npgsqlParameters)
|
||||
{
|
||||
private static int? ExecuteNonQuery(string connectionString, string commandText, ReadOnlyCollection<NpgsqlParameter> npgsqlParameters) {
|
||||
int? result;
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
if (string.IsNullOrEmpty(connectionString)) {
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
using NpgsqlConnection npgsqlConnection = new(connectionString);
|
||||
npgsqlConnection.Open();
|
||||
using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection);
|
||||
@ -32,61 +30,60 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
return result;
|
||||
}
|
||||
|
||||
private static StringBuilder GetForJsonPath(string connectionString, string commandText, ReadOnlyCollection<NpgsqlParameter> npgsqlParameters)
|
||||
{
|
||||
private static StringBuilder GetForJsonPath(string connectionString, string commandText, ReadOnlyCollection<NpgsqlParameter> npgsqlParameters) {
|
||||
StringBuilder result = new();
|
||||
using NpgsqlConnection npgsqlConnection = new(connectionString);
|
||||
npgsqlConnection.Open();
|
||||
using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection);
|
||||
npgsqlCommand.Parameters.AddRange(npgsqlParameters.ToArray());
|
||||
NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.SequentialAccess);
|
||||
while (npgsqlDataReader.Read())
|
||||
while (npgsqlDataReader.Read()) {
|
||||
_ = result.Append(npgsqlDataReader.GetString(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string? GetColumns()
|
||||
{
|
||||
public string? GetColumns() {
|
||||
string result;
|
||||
NpgsqlParameter[] npgsqlParameters = [];
|
||||
string commandText = CommandText.GetColumns();
|
||||
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
result = stringBuilder.ToString();
|
||||
if (result.Length == 1)
|
||||
if (result.Length == 1) {
|
||||
File.WriteAllText(".vscode/jsonl/.jsonl", result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string? GetOwnerIds()
|
||||
{
|
||||
public string? GetOwnerIds() {
|
||||
string result;
|
||||
NpgsqlParameter[] npgsqlParameters = [];
|
||||
string commandText = CommandText.GetOwnerIdActiveImage();
|
||||
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string commandText = CommandText.GetOwnerIdActiveImage(_Settings.LowestVersionHistory);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
result = stringBuilder.ToString();
|
||||
if (result.Length == 1)
|
||||
if (result.Length == 1) {
|
||||
File.WriteAllText(".vscode/jsonl/.jsonl", result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string? GetAssets(Guid ownerId)
|
||||
{
|
||||
public string? GetAssets(Guid ownerId) {
|
||||
string result;
|
||||
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_AppSettings.FilterTags);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
result = stringBuilder.ToString();
|
||||
if (result.Length == 1)
|
||||
if (result.Length == 1) {
|
||||
File.WriteAllText(".vscode/jsonl/assets.jsonl", result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId)
|
||||
{
|
||||
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId) {
|
||||
string[]? results;
|
||||
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_AppSettings.FilterTags);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_AppSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
|
||||
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string json = stringBuilder.ToString();
|
||||
Random random = new();
|
||||
string ownerIdValue = ownerId.ToString();
|
||||
@ -95,49 +92,44 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
public Tag[]? GetArchivedTag(AppSettings appSettings, Guid ownerId)
|
||||
{
|
||||
Tag[] results;
|
||||
public Tag[]? GetArchivedTag(Settings settings, Guid ownerId) {
|
||||
Tag[]? results;
|
||||
Guid userId = ownerId;
|
||||
string value = appSettings.ArchivedTag;
|
||||
NpgsqlParameter[] npgsqlParameters =
|
||||
[
|
||||
string value = settings.ArchivedTag;
|
||||
NpgsqlParameter[] npgsqlParameters = [
|
||||
new NpgsqlParameter(nameof(value), value),
|
||||
new NpgsqlParameter(nameof(userId), userId),
|
||||
];
|
||||
string commandText = CommandText.GetArchivedTag();
|
||||
StringBuilder stringBuilder = GetForJsonPath(appSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string commandText = CommandText.GetArchivedTag(_Settings.LowestVersionHistory);
|
||||
StringBuilder stringBuilder = GetForJsonPath(settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
string json = stringBuilder.ToString();
|
||||
results = JsonSerializer.Deserialize(json, TagCollectionSourceGenerationContext.Default.TagArray);
|
||||
return results;
|
||||
}
|
||||
|
||||
public string? GetArchivedTag(Guid ownerId)
|
||||
{
|
||||
string result;
|
||||
Tag[]? tags = GetArchivedTag(_AppSettings, ownerId);
|
||||
public string? GetArchivedTag(Guid ownerId) {
|
||||
string? result;
|
||||
Tag[]? tags = GetArchivedTag(_Settings, ownerId);
|
||||
result = tags is null || tags.Length != 1 ? null : tags[0].Id;
|
||||
return result;
|
||||
}
|
||||
|
||||
public string? SaveRandomPaths(Guid ownerId)
|
||||
{
|
||||
public string? SaveRandomPaths(Guid ownerId) {
|
||||
string? results;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
string tomorrow = dateTime.AddDays(1).ToString("MM-dd");
|
||||
if (Directory.Exists(_AppSettings.RandomResultsDirectory))
|
||||
_ = Directory.CreateDirectory(_AppSettings.RandomResultsDirectory);
|
||||
FileInfo fileInfo = new(Path.Combine(_AppSettings.RandomResultsDirectory, $"{tomorrow}.json"));
|
||||
if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_AppSettings.AddDays))
|
||||
if (Directory.Exists(_Settings.RandomResultsDirectory)) {
|
||||
_ = Directory.CreateDirectory(_Settings.RandomResultsDirectory);
|
||||
}
|
||||
FileInfo fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{tomorrow}.json"));
|
||||
if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_Settings.AddDays)) {
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName);
|
||||
ReadOnlyCollection<string>? paths = GetRandomPaths(ownerId);
|
||||
if (paths is null)
|
||||
if (paths is null) {
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_Logger.LogInformation("{count} path(s)", paths.Count.ToString());
|
||||
results = JsonSerializer.Serialize(paths);
|
||||
File.WriteAllText(fileInfo.FullName, results);
|
||||
@ -148,32 +140,32 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
|
||||
private record Record(string Source, string Destination);
|
||||
|
||||
public ReadOnlyCollection<string> SyncImmich(Guid ownerId)
|
||||
{
|
||||
public ReadOnlyCollection<string> SyncImmich(Guid ownerId) {
|
||||
List<string> results = [];
|
||||
Record record;
|
||||
List<Record> records = [];
|
||||
if (Directory.Exists(_AppSettings.SyncDirectory))
|
||||
_ = Directory.CreateDirectory(_AppSettings.SyncDirectory);
|
||||
int syncLength = _AppSettings.SyncDirectory.Length;
|
||||
string[] syncFiles = Directory.GetFiles(_AppSettings.SyncDirectory, "*", SearchOption.AllDirectories);
|
||||
if (Directory.Exists(_Settings.SyncDirectory)) {
|
||||
_ = Directory.CreateDirectory(_Settings.SyncDirectory);
|
||||
}
|
||||
int syncLength = _Settings.SyncDirectory.Length;
|
||||
string[] syncFiles = Directory.GetFiles(_Settings.SyncDirectory, "*", SearchOption.AllDirectories);
|
||||
string[] syncCheck = syncFiles.Select(l => l[syncLength..]).ToArray();
|
||||
if (Directory.Exists(_AppSettings.ImmichUploadDirectory))
|
||||
_ = Directory.CreateDirectory(_AppSettings.ImmichUploadDirectory);
|
||||
int immichUploadLength = _AppSettings.ImmichUploadDirectory.Length;
|
||||
string[] immichUploadFiles = Directory.GetFiles(_AppSettings.ImmichUploadDirectory, "*", SearchOption.AllDirectories);
|
||||
if (Directory.Exists(_Settings.ImmichUploadDirectory)) {
|
||||
_ = Directory.CreateDirectory(_Settings.ImmichUploadDirectory);
|
||||
}
|
||||
int immichUploadLength = _Settings.ImmichUploadDirectory.Length;
|
||||
string[] immichUploadFiles = Directory.GetFiles(_Settings.ImmichUploadDirectory, "*", SearchOption.AllDirectories);
|
||||
string[] immichUploadCheck = immichUploadFiles.Select(l => l[immichUploadLength..]).ToArray();
|
||||
for (int i = 0; i < immichUploadFiles.Length; i++)
|
||||
{
|
||||
if (syncCheck.Contains(immichUploadCheck[i]))
|
||||
for (int i = 0; i < immichUploadFiles.Length; i++) {
|
||||
if (syncCheck.Contains(immichUploadCheck[i])) {
|
||||
continue;
|
||||
}
|
||||
results.Add(immichUploadCheck[i]);
|
||||
record = new(immichUploadFiles[i], string.Concat(_AppSettings.SyncDirectory, immichUploadCheck[i]));
|
||||
record = new(immichUploadFiles[i], string.Concat(_Settings.SyncDirectory, immichUploadCheck[i]));
|
||||
records.Add(record);
|
||||
}
|
||||
_Logger.LogInformation("{count} file(s)", results.Count.ToString());
|
||||
for (int i = 0; i < records.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < records.Count; i++) {
|
||||
record = records[i];
|
||||
_Logger.LogDebug("Copying <{source}>", record.Source);
|
||||
File.Copy(record.Source, record.Destination);
|
||||
@ -181,51 +173,73 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<int> SetArchiveImmich(Guid ownerId)
|
||||
{
|
||||
public ReadOnlyCollection<int>? SetArchiveImmich(Guid ownerId) {
|
||||
ReadOnlyCollection<int>? results;
|
||||
string checkDirectory = Path.Combine(_AppSettings.CurrentResultsDirectory, "B)Metadata", _AppSettings.CurrentCommit, "[]");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
if (!File.Exists(_Settings.NotNinePath)) {
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, "!9.json");
|
||||
if (!File.Exists(checkFile))
|
||||
} else {
|
||||
string json = File.ReadAllText(_Settings.NotNinePath);
|
||||
Identifier[]? identifiers = JsonSerializer.Deserialize<Identifier[]>(json);
|
||||
if (identifiers is null || identifiers.Length == 0) {
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
string json = File.ReadAllText(checkFile);
|
||||
Identifier[]? identifiers = JsonSerializer.Deserialize<Identifier[]>(json);
|
||||
if (identifiers is null || identifiers.Length == 0)
|
||||
} else {
|
||||
Tag[]? tags = GetArchivedTag(_Settings, ownerId);
|
||||
if (tags is null || tags.Length != 1) {
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
Tag[]? tags = GetArchivedTag(_AppSettings, ownerId);
|
||||
if (tags is null || tags.Length != 1)
|
||||
results = null;
|
||||
else
|
||||
results = SetArchiveImmich(logger, appSettings, ownerId, identifiers.AsReadOnly(), tags.AsReadOnly());
|
||||
} else {
|
||||
results = SetArchiveImmich(logger, _Settings, ownerId, identifiers.AsReadOnly(), tags.AsReadOnly());
|
||||
}
|
||||
}
|
||||
}
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int> SetArchiveImmich(ILogger<Program> logger, AppSettings appSettings, Guid ownerId, ReadOnlyCollection<Identifier> identifiers, ReadOnlyCollection<Tag> tags)
|
||||
{
|
||||
private static ReadOnlyCollection<int>? SetArchiveImmich(ILogger<Program> logger, Settings settings, Guid ownerId, string tagsId, string deviceAssetIds) {
|
||||
ReadOnlyCollection<int>? results;
|
||||
string tagsId = tags[0].Id;
|
||||
NpgsqlParameter[] npgsqlParameters =
|
||||
[
|
||||
NpgsqlParameter[] npgsqlParameters = [
|
||||
new NpgsqlParameter(nameof(tagsId), tagsId),
|
||||
new NpgsqlParameter(nameof(ownerId), ownerId),
|
||||
];
|
||||
string deviceAssetIds = Identifier.GetDeviceAssetIds(identifiers);
|
||||
string commandText = CommandText.SetAssetArchived(deviceAssetIds);
|
||||
string commandText = CommandText.SetAssetArchived(settings.LowestVersionHistory, deviceAssetIds);
|
||||
logger.LogDebug(commandText.Replace($"@{nameof(tagsId)}", $"'{tagsId}'").Replace($"@{nameof(ownerId)}", $"'{ownerId}'".ToString()));
|
||||
int? result = ExecuteNonQuery(appSettings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
int? result = ExecuteNonQuery(settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
|
||||
results = result is null ? null : new([result.Value]);
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int>? SetArchiveImmich(ILogger<Program> logger, Settings settings, Guid ownerId, ReadOnlyCollection<Identifier> identifiers, ReadOnlyCollection<Tag> tags) {
|
||||
ReadOnlyCollection<int>? results;
|
||||
string tagsId = tags[0].Id;
|
||||
string deviceAssetIds = Identifier.GetDeviceAssetIds(identifiers);
|
||||
results = SetArchiveImmich(logger, settings, ownerId, tagsId, deviceAssetIds);
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<int>? SetDigiKam4ArchiveImmich(Guid ownerId) {
|
||||
ReadOnlyCollection<int>? results;
|
||||
ReadOnlyCollection<ImageTag>? imageTags = ImageTag.Get(tag: _Settings.ArchivedTag,
|
||||
tagsPath: _Settings.DigiKam4?.Tags,
|
||||
imageTagsPath: _Settings.DigiKam4?.ImageTags,
|
||||
imagesPath: _Settings.DigiKam4?.Images);
|
||||
if (imageTags is null || imageTags.Count == 0) {
|
||||
results = null;
|
||||
} else {
|
||||
Tag[]? tags = GetArchivedTag(_Settings, ownerId);
|
||||
if (tags is null || tags.Length != 1) {
|
||||
results = null;
|
||||
} else {
|
||||
results = SetArchiveImmich(logger, _Settings, ownerId, imageTags, tags.AsReadOnly());
|
||||
}
|
||||
}
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<int>? SetArchiveImmich(ILogger<Program> logger, Settings settings, Guid ownerId, ReadOnlyCollection<ImageTag> imageTags, ReadOnlyCollection<Tag> tags) {
|
||||
ReadOnlyCollection<int>? results;
|
||||
string tagsId = tags[0].Id;
|
||||
string deviceAssetIds = Identifier.GetDeviceAssetIds(imageTags);
|
||||
results = SetArchiveImmich(logger, settings, ownerId, tagsId, deviceAssetIds);
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
@ -1,129 +1,176 @@
|
||||
namespace ImmichToSlideshow.Services;
|
||||
|
||||
internal static class CommandText
|
||||
{
|
||||
internal static class CommandText {
|
||||
|
||||
internal static string GetColumns()
|
||||
{ // cSpell:disable
|
||||
List<string> results = new();
|
||||
// results.Add(" SELECT COALESCE(SUM(checksum_failures), 0) ");
|
||||
// results.Add(" FROM pg_stat_database ");
|
||||
// results.Add(" SELECT json_agg(t) ");
|
||||
// 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(" WHERE table_name = 'assets' ");
|
||||
// results.Add(" WHERE table_name = 'libraries' ");
|
||||
results.Add(" WHERE table_name = 'asset_files' ");
|
||||
internal static string GetColumns() { // cSpell:disable
|
||||
List<string> results = [
|
||||
// " SELECT COALESCE(SUM(checksum_failures), 0) ",
|
||||
// " FROM pg_stat_database ",
|
||||
// " SELECT json_agg(t) ",
|
||||
// " FROM information_schema.tables t ",
|
||||
// " WHERE table_schema= 'public' ",
|
||||
// " AND table_type= 'BASE TABLE' ",
|
||||
" SELECT json_agg(c) ",
|
||||
" FROM information_schema.columns c ",
|
||||
// " WHERE table_name = 'assets' ",
|
||||
// " WHERE table_name = 'libraries' ",
|
||||
" WHERE table_name = 'asset_files'; "
|
||||
];
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
internal static string GetOwnerIdActiveImage()
|
||||
{ // cSpell:disable
|
||||
List<string> results = new();
|
||||
results.Add(" SELECT json_agg(j) ");
|
||||
results.Add(" FROM ( ");
|
||||
results.Add(" SELECT a.\"ownerId\" ");
|
||||
results.Add(" FROM assets a ");
|
||||
results.Add(" WHERE a.\"status\" = 'active' ");
|
||||
results.Add(" AND a.\"type\" = 'IMAGE' ");
|
||||
results.Add(" GROUP");
|
||||
results.Add(" BY a.\"ownerId\" ");
|
||||
results.Add(" ) j ");
|
||||
internal static string GetOwnerIdActiveImage(float lowestVersionHistory) { // cSpell:disable
|
||||
List<string> results = [
|
||||
" SELECT json_agg(j) ",
|
||||
" FROM ( ",
|
||||
" SELECT a.\"ownerId\" "
|
||||
];
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM assets a ");
|
||||
} else {
|
||||
results.Add(" FROM public.asset a ");
|
||||
}
|
||||
results.AddRange([
|
||||
" WHERE a.\"status\" = 'active' ",
|
||||
" AND a.\"type\" = 'IMAGE' ",
|
||||
" GROUP",
|
||||
" BY a.\"ownerId\" ",
|
||||
" ) j; "
|
||||
]);
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
internal static string GetAssetActiveImagePreviewNotDuplicate(string[] filterTags)
|
||||
{ // cSpell:disable
|
||||
List<string> 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.\"id\" not in ( ");
|
||||
results.Add(" SELECT \"assetsId\" ");
|
||||
results.Add(" FROM tag_asset g ");
|
||||
results.Add(" JOIN tags t ");
|
||||
results.Add(" ON g.\"tagsId\" = t.\"id\" ");
|
||||
results.Add($" WHERE t.\"value\" in ('{string.Join("','", filterTags)}') ");
|
||||
results.Add(" ) ");
|
||||
results.Add(" AND a.\"isExternal\" = true ");
|
||||
results.Add(" AND a.\"isOffline\" = false ");
|
||||
results.Add(" AND a.\"ownerId\" = @ownerId ");
|
||||
results.Add(" ) j ");
|
||||
internal static string GetAssetActiveImagePreviewNotDuplicate(float lowestVersionHistory, string[] filterTags) { // cSpell:disable
|
||||
List<string> results = [
|
||||
" SELECT json_agg(j) ",
|
||||
" FROM ( ",
|
||||
" SELECT a.\"id\" ",
|
||||
" , a.\"deviceAssetId\" ",
|
||||
// " , a.\"ownerId\" ",
|
||||
// " , a.\"deviceId\" ",
|
||||
// " , a.\"type\" ",
|
||||
" , a.\"originalPath\" ",
|
||||
// " , a.\"fileCreatedAt\" ",
|
||||
// " , a.\"fileModifiedAt\" ",
|
||||
// " , a.\"isFavorite\" ",
|
||||
// " , a.\"duration\" ",
|
||||
// " , a.\"encodedVideoPath\" ",
|
||||
// " , a.\"checksum\" ",
|
||||
// " , a.\"isVisible\" ",
|
||||
// " , a.\"livePhotoVideoId\" ",
|
||||
// " , a.\"updatedAt\" ",
|
||||
// " , a.\"createdAt\" ",
|
||||
// " , a.\"isArchived\" ",
|
||||
" , a.\"originalFileName\" ",
|
||||
// " , a.\"sidecarPath\" ",
|
||||
// " , a.\"thumbhash\" ",
|
||||
// " , a.\"isOffline\" ",
|
||||
// " , a.\"libraryId\" ",
|
||||
// " , a.\"isExternal\" ",
|
||||
// " , a.\"deletedAt\" ",
|
||||
// " , a.\"localDateTime\" ",
|
||||
// " , a.\"stackId\" ",
|
||||
" , a.\"duplicateId\" ",
|
||||
// " , a.\"status\" ",
|
||||
" , f.\"path\" "
|
||||
];
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM assets a ");
|
||||
} else {
|
||||
results.Add(" FROM public.asset a ");
|
||||
}
|
||||
results.AddRange(" INNER ");
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" JOIN asset_files f ");
|
||||
} else {
|
||||
results.Add(" JOIN public.asset_file f ");
|
||||
}
|
||||
results.AddRange([
|
||||
" ON a.\"id\" = f.\"assetId\" ",
|
||||
" WHERE a.\"status\" = 'active' ",
|
||||
" AND a.\"type\" = 'IMAGE' ",
|
||||
" AND f.\"type\" = 'preview' ",
|
||||
" AND a.\"duplicateId\" is null ",
|
||||
" AND a.\"id\" not 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("','", filterTags)}') ",
|
||||
" ) ",
|
||||
" AND a.\"isExternal\" = true ",
|
||||
" AND a.\"isOffline\" = false ",
|
||||
" AND a.\"ownerId\" = @ownerId ",
|
||||
" ) j; "
|
||||
]);
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
internal static string SetAssetArchived(string deviceAssetIds)
|
||||
{ // cSpell:disable
|
||||
List<string> results = new();
|
||||
results.Add(" INSERT INTO tag_asset ");
|
||||
results.Add(" (\"assetsId\", \"tagsId\") ");
|
||||
results.Add(" SELECT a.\"id\", @tagsId::uuid ");
|
||||
results.Add(" FROM assets a ");
|
||||
results.Add(" WHERE a.\"type\" = 'IMAGE' ");
|
||||
results.Add(" AND a.\"ownerId\" = @ownerId ");
|
||||
results.Add(" AND a.\"deviceAssetId\" in ( ");
|
||||
results.Add(deviceAssetIds);
|
||||
results.Add(" ) ");
|
||||
results.Add(" AND a.\"id\" not in ( ");
|
||||
results.Add(" SELECT \"id\" ");
|
||||
results.Add(" FROM assets b ");
|
||||
internal static string SetAssetArchived(float lowestVersionHistory, string deviceAssetIds) { // cSpell:disable
|
||||
List<string> results = [
|
||||
" INSERT INTO tag_asset ",
|
||||
" (\"assetsId\", \"tagsId\") ",
|
||||
" SELECT a.\"id\", @tagsId::uuid "
|
||||
];
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM assets a ");
|
||||
} else {
|
||||
results.Add(" FROM public.asset a ");
|
||||
}
|
||||
results.AddRange([
|
||||
" WHERE a.\"type\" = 'IMAGE' ",
|
||||
" AND a.\"ownerId\" = @ownerId ",
|
||||
" AND a.\"deviceAssetId\" in ( ",
|
||||
deviceAssetIds,
|
||||
" ) ",
|
||||
" AND a.\"id\" not in ( ",
|
||||
" SELECT \"id\" "
|
||||
]);
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM assets b ");
|
||||
} else {
|
||||
results.Add(" FROM public.asset b ");
|
||||
}
|
||||
results.Add(" INNER ");
|
||||
results.Add(" JOIN tag_asset t ");
|
||||
results.Add(" ON b.\"id\" = t.\"assetsId\" ");
|
||||
results.Add(" WHERE t.\"tagsId\" = @tagsId::uuid ");
|
||||
results.Add(" AND b.\"deviceAssetId\" in ( ");
|
||||
results.Add(deviceAssetIds);
|
||||
results.Add(" ) ");
|
||||
results.Add(" ) ");
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" JOIN tag_asset t ");
|
||||
} else {
|
||||
results.Add(" JOIN public.tag_asset t ");
|
||||
}
|
||||
results.AddRange([
|
||||
" ON b.\"id\" = t.\"assetsId\" ",
|
||||
" WHERE t.\"tagsId\" = @tagsId::uuid ",
|
||||
" AND b.\"deviceAssetId\" in ( ",
|
||||
deviceAssetIds,
|
||||
" ) ",
|
||||
" ); "
|
||||
]);
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
internal static string GetArchivedTag()
|
||||
{ // cSpell:disable
|
||||
List<string> results = new();
|
||||
results.Add(" SELECT json_agg(t) ");
|
||||
results.Add(" FROM tags t ");
|
||||
results.Add($" WHERE t.\"value\" = @value ");
|
||||
results.Add(" AND t.\"userId\" = @userId ");
|
||||
internal static string GetArchivedTag(float lowestVersionHistory) { // cSpell:disable
|
||||
List<string> results = [
|
||||
" SELECT json_agg(t) "
|
||||
];
|
||||
if (lowestVersionHistory <= 1.129) {
|
||||
results.Add(" FROM tags t ");
|
||||
} else {
|
||||
results.Add(" FROM public.tag t ");
|
||||
}
|
||||
results.AddRange([
|
||||
" WHERE t.\"value\" = @value ",
|
||||
" AND t.\"userId\" = @userId; "
|
||||
]);
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
|
Reference in New Issue
Block a user