Track manual snapshots and apply versioned camera config
This commit is contained in:
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")]
|
||||
|
||||
Reference in new issue
Block a user