hurl file over http file

AddControllers

Formatting
This commit is contained in:
2025-09-20 14:18:46 -07:00
parent 895dab9413
commit 8034f79753
13 changed files with 307 additions and 193 deletions

View File

@ -69,8 +69,9 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
public string? GetAssets(Guid ownerId) {
string result;
ReadOnlyCollection<string> people = Array.Empty<string>().AsReadOnly();
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());
result = stringBuilder.ToString();
if (result.Length == 1) {
@ -79,13 +80,31 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
return result;
}
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId) {
public ReadOnlyCollection<string>? GetRandomPaths(Guid ownerId, string? monthDay) {
string[]? results;
NpgsqlParameter[] npgsqlParameters = [new NpgsqlParameter(nameof(ownerId), ownerId)];
string commandText = CommandText.GetAssetActiveImagePreviewNotDuplicate(_Settings.LowestVersionHistory, _Settings.FilterTags);
StringBuilder stringBuilder = GetForJsonPath(_Settings.ConnectionString, commandText, npgsqlParameters.AsReadOnly());
string json = stringBuilder.ToString();
string commandText;
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();
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();
@ -114,25 +133,35 @@ public class AssetService(ILogger<Program> logger, AppSettings appSettings) {
return result;
}
public string? SaveRandomPaths(Guid ownerId) {
string? results;
public string? SaveRandomPaths(Guid ownerId, string? monthDay) {
string? results = null;
FileInfo fileInfo;
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)) {
_ = 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 {
_Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName);
ReadOnlyCollection<string>? paths = GetRandomPaths(ownerId);
if (paths is null) {
for (int i = 0; i < 366; i++) {
if (check is null || check.Value) {
monthDay = i == 0 && check is not null && check.Value ? "02-29" : dateTime.AddDays(i).ToString("MM-dd");
}
fileInfo = new(Path.Combine(_Settings.RandomResultsDirectory, $"{monthDay}.json"));
if (fileInfo.Exists && fileInfo.CreationTime > dateTime.AddDays(_Settings.AddDays)) {
results = null;
} else {
_Logger.LogInformation("{count} path(s)", paths.Count.ToString());
results = JsonSerializer.Serialize(paths);
File.WriteAllText(fileInfo.FullName, results);
_Logger.LogDebug("Writing <{FullName}>", fileInfo.FullName);
paths = GetRandomPaths(ownerId, monthDay);
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;