- Security: PBKDF2-SHA512 (210,000 iterations) hashes, opaque bearer tokens stored as SHA-256 with sliding expiry and revocation, HttpOnly/Secure/ SameSite=Strict admin cookie with a session-bound CSRF token, sign-in rate limit and lockout, role/permission metadata on every endpoint, audit log, first-run administrator bootstrap. - Sequences with keyset paging, ETags and settings_version conflicts; sync manifest; frames, proxies, thumbnails and exports streamed with Range. - Chunked resumable uploads with hash short-circuit, quota and disk checks, staging on the archive volume, SHA-256 verification and IArchiveIngest. - Job engine host, jobs API, render nodes with heartbeat timeout and reassignment, WebSocket events, LAN discovery beacon, upload cleanup. - Windows service host over advapi32 (--service, --install-service, --uninstall-service); fails fast without the archive module services. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
91 lines
3.9 KiB
C#
91 lines
3.9 KiB
C#
using System.Text;
|
|
using System.Text.Json;
|
|
using Titano.Core.Model;
|
|
using Titano.Protocol;
|
|
|
|
namespace Titano.Server.Api;
|
|
|
|
/// <summary>Domain entities → API v1 contracts.</summary>
|
|
public static class Dto
|
|
{
|
|
public static UserDto User(User u) => new(
|
|
u.Id, u.Username, u.DisplayName, Role(u.Role), (long)u.Permissions, u.QuotaBytes, u.UsedBytes, u.Disabled, u.MustChangePassword,
|
|
u.Created, u.LastLogin);
|
|
|
|
public static string Role(UserRole role) => role.ToString().ToLowerInvariant();
|
|
|
|
public static SequenceDto Sequence(Sequence s) => new(
|
|
s.Id, s.Title, s.DisplayTitle, s.Folder, s.CameraMake, s.CameraModel, s.Lens, s.FirstCapture, s.LastCapture, s.FrameCount,
|
|
s.MedianInterval, s.TotalBytes, (long)s.Status, s.RenderedCount, s.HeroFrameId, s.Tags, s.Rating, s.Notes, s.SettingsVersion,
|
|
s.FramesVersion, s.WarningCount, s.OwnerUserId, s.UpdatedAt);
|
|
|
|
public static FrameDto Frame(Frame f) => new(
|
|
f.Id, f.SequenceId, f.Index, f.FileName, f.Size, f.Sha256, f.CapturedAt, f.UtcOffsetMinutes, f.ExposureTime, f.FNumber, f.Iso,
|
|
f.FocalLength, f.Orientation, f.Width, f.Height, f.Format.ToString().ToLowerInvariant(), (long)f.Flags);
|
|
|
|
public static RenderDto Render(Render r) => new(r.Id, r.PresetName, r.Codec, r.Width, r.Height, r.Fps, r.DurationSeconds, r.Bytes, r.Created, r.ProducedBy);
|
|
|
|
public static JobDto Job(Job j) => new(
|
|
j.Id, JobWire.Kind(j.Kind), j.TargetIds, j.TargetLabel, JobWire.State(j.State), JobWire.Priority(j.Priority), j.ProgressDone,
|
|
j.ProgressTotal, j.ItemsPerSecond, j.Eta?.TotalSeconds, j.LogTail, j.NodeId, j.Attempts, j.Error, j.Created, j.Started, j.Finished);
|
|
|
|
public static AuditEntryDto Audit(AuditEntry a) => new(a.Id, a.At, a.UserId, a.Username, a.Action, a.TargetKind, a.TargetId, a.Details, a.RemoteAddress);
|
|
|
|
public static RenderNodeDto Node(RenderNode node, string username) =>
|
|
new(node.Id, node.ClientName, username, Capabilities(node)?.Encoders ?? [], node.LastHeartbeat, node.State);
|
|
|
|
/// <summary>What a node announced at registration (stored as its capabilities JSON).</summary>
|
|
public static RegisterNodeRequest? Capabilities(RenderNode node)
|
|
{
|
|
if (node.CapabilitiesJson is null) return null;
|
|
try
|
|
{
|
|
return JsonSerializer.Deserialize(node.CapabilitiesJson, ProtocolJson.Default.RegisterNodeRequest);
|
|
}
|
|
catch (JsonException)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>Wire names of job kinds, states and priorities: kebab-case (<c>deep-analyse</c>) and lower-case (<c>running</c>).</summary>
|
|
public static class JobWire
|
|
{
|
|
public static string Kind(JobKind kind)
|
|
{
|
|
var name = kind.ToString();
|
|
var sb = new StringBuilder(name.Length + 4);
|
|
for (var i = 0; i < name.Length; i++)
|
|
{
|
|
if (i > 0 && char.IsUpper(name[i])) sb.Append('-');
|
|
sb.Append(char.ToLowerInvariant(name[i]));
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static bool TryParseKind(string? text, out JobKind kind) => TryParse(text, Kind, out kind);
|
|
|
|
public static string State(JobState state) => state.ToString().ToLowerInvariant();
|
|
|
|
public static bool TryParseState(string? text, out JobState state) => TryParse(text, State, out state);
|
|
|
|
public static string Priority(JobPriority priority) => priority.ToString().ToLowerInvariant();
|
|
|
|
public static bool TryParsePriority(string? text, out JobPriority priority) => TryParse(text, Priority, out priority);
|
|
|
|
private static bool TryParse<T>(string? text, Func<T, string> name, out T value) where T : struct, Enum
|
|
{
|
|
foreach (var candidate in Enum.GetValues<T>())
|
|
{
|
|
if (string.Equals(name(candidate), text, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
value = candidate;
|
|
return true;
|
|
}
|
|
}
|
|
value = default;
|
|
return false;
|
|
}
|
|
}
|