Files
immich-to-slideshow/src/ImmichToSlideshow/Services/CommandText.cs
mikep@034E8FF1ED4D1F6 c4d42d79a0 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
2025-07-27 16:03:47 -07:00

177 lines
6.5 KiB
C#

namespace ImmichToSlideshow.Services;
internal static class CommandText {
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(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(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(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 ");
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(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
}