Track manual snapshots and apply versioned camera config
Heimdall Gitea / Build and tests (pull_request) Failing after 1m34s
Heimdall Gitea / Publish versioned release (pull_request) Skipped

This commit is contained in:
Arnaud Dartois committed 2026-10-23 07:30:58 +02:00
1 parent f4a8f4a668
commit 8f00f69a5f
30 files changed
+645 -63

No files matched your search

@@ -133,7 +133,11 @@ public class EventsController : ControllerBase
var ev = await _db.CameraEvents.FirstOrDefaultAsync(e => e.Id == id, ct);
if (ev is null) return NotFound();
if (ev.SnapshotObjectKey is not null) return Ok(new { url = ev.SnapshotUrl });
if (ev.SnapshotObjectKey is not null)
{
await CompleteManualSnapshotRequestAsync(ev, ct);
return Ok(new { url = ev.SnapshotUrl });
}
var mediaType = Request.ContentType?.Split(';')[0].Trim();
if (!string.Equals(mediaType, "image/jpeg", StringComparison.OrdinalIgnoreCase))
@@ -164,6 +168,10 @@ public class EventsController : ControllerBase
try
{
ev.SetStoredSnapshot(key, location);
var manualRequest = ev.Type == EventType.ManualSnapshot
? await _db.ManualSnapshotRequests.FirstOrDefaultAsync(r => r.Id == ev.Id && r.CameraId == ev.CameraId, ct)
: null;
manualRequest?.Complete(DateTime.UtcNow);
await _db.SaveChangesWithRetryAsync(ct: ct);
}
catch
@@ -175,6 +183,16 @@ public class EventsController : ControllerBase
return Ok(new { url = ev.SnapshotUrl });
}
private async Task CompleteManualSnapshotRequestAsync(Heimdall.Domain.Entities.CameraEvent ev, CancellationToken ct)
{
if (ev.Type != EventType.ManualSnapshot) return;
var request = await _db.ManualSnapshotRequests
.FirstOrDefaultAsync(r => r.Id == ev.Id && r.CameraId == ev.CameraId, ct);
if (request is null || request.Status == ManualSnapshotStatus.Completed) return;
request.Complete(DateTime.UtcNow);
await _db.SaveChangesWithRetryAsync(ct: ct);
}
/// <summary>Stream a stored JPEG only to a user allowed to read its camera.</summary>
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.CameraRead)]
[HttpGet("{id:guid}/snapshot/content")]