set-archive-immich
This commit is contained in:
@ -89,6 +89,7 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
results.Add(" AND a.\"type\" = 'IMAGE' ");
|
||||
results.Add(" AND f.\"type\" = 'preview' ");
|
||||
results.Add(" AND a.\"duplicateId\" is null ");
|
||||
results.Add(" AND a.\"isArchived\" = false ");
|
||||
results.Add(" AND a.\"isExternal\" = true ");
|
||||
results.Add(" AND a.\"isOffline\" = false ");
|
||||
results.Add(" AND a.\"isVisible\" = true ");
|
||||
@ -97,6 +98,36 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
private static string SetAssetArchivedCommandText(string deviceAssetIds)
|
||||
{ // cSpell:disable
|
||||
List<string> results = new();
|
||||
results.Add(" UPDATE assets ");
|
||||
results.Add(" SET \"isArchived\" = true ");
|
||||
results.Add(" WHERE \"isArchived\" = false ");
|
||||
results.Add(" AND \"type\" = 'IMAGE' ");
|
||||
results.Add(" AND \"ownerId\" = @ownerId ");
|
||||
results.Add(" AND \"deviceAssetId\" in ( ");
|
||||
results.Add(deviceAssetIds);
|
||||
results.Add(" ) ");
|
||||
return string.Join(Environment.NewLine, results);
|
||||
} // cSpell:enable
|
||||
|
||||
private static int? ExecuteNonQuery(string connectionString, string commandText, NpgsqlParameter[] npgsqlParameters)
|
||||
{
|
||||
int? result;
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
using NpgsqlConnection npgsqlConnection = new(connectionString);
|
||||
npgsqlConnection.Open();
|
||||
using NpgsqlCommand npgsqlCommand = new(commandText, npgsqlConnection);
|
||||
npgsqlCommand.Parameters.AddRange(npgsqlParameters);
|
||||
result = npgsqlCommand.ExecuteNonQuery();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static StringBuilder GetForJsonPath(string connectionString, string commandText, NpgsqlParameter[] npgsqlParameters)
|
||||
{
|
||||
StringBuilder result = new();
|
||||
@ -221,4 +252,37 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings)
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<int> SetArchiveImmich(Guid ownerId)
|
||||
{
|
||||
List<int> results;
|
||||
string checkDirectory = Path.Combine(_AppSettings.CurrentResultsDirectory, "B)Metadata", _AppSettings.CurrentCommit, "[]");
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
string checkFile = Path.Combine(checkDirectory, "!9.json");
|
||||
if (!File.Exists(checkFile))
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
string json = File.ReadAllText(checkFile);
|
||||
Identifier[]? identifiers = JsonSerializer.Deserialize<Identifier[]>(json);
|
||||
if (identifiers is null || identifiers.Length == 0)
|
||||
results = null;
|
||||
else
|
||||
{
|
||||
string deviceAssetIds = $"'{string.Join($"',{Environment.NewLine}'", identifiers.Select(l => $"{l.PaddedId}{l.Extension}").ToArray())}'";
|
||||
string commandText = SetAssetArchivedCommandText(deviceAssetIds);
|
||||
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
|
||||
int? result = ExecuteNonQuery(_AppSettings.ConnectionString, commandText, npgsqlParameters);
|
||||
if (result is null)
|
||||
results = null;
|
||||
else
|
||||
results = [result.Value];
|
||||
}
|
||||
}
|
||||
}
|
||||
return results?.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user