fix(projects): empty sequences, push size, version paging, delete rights, settings PATCH, change events

- An unplaced sequence (no photos) lists no projects and refuses to create one
  with sequence_empty, instead of writing sidecars at the archive root.
- A push accepts a full-size version; a 413 is reported as too_large.
- Version pages are capped in bytes and say when more follow; the summary form
  leaves settings out; server homes page on.
- Deleting by its maker needs the same account, not just the same username.
- A settings PATCH writes project.json under the sequence lease, so Main's
  later birth no longer wipes it.
- Reconcile, read-only catch-up and a Main flip publish projectChanged.
- Server homes read the frames stamp and check a version is really stored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 12:31:52 +01:00
1 parent ed7452e739
commit 4f652c4025
16 files changed
+356 -53

No files matched your search

+1
View File
@@ -64,6 +64,7 @@
<data name="Editor.Copy.Restored" xml:space="preserve"><value>Project restored</value></data>
<data name="Editor.Copy.Same" xml:space="preserve"><value>Nothing to restore</value></data>
<data name="Editor.Copy.Undo" xml:space="preserve"><value>Undo</value></data>
<data name="Editor.Error.Empty" xml:space="preserve"><value>This sequence has no photos yet.</value><comment>long</comment></data>
<data name="Editor.Error.FramesArriving" xml:space="preserve"><value>Photos are being added to this sequence; wait a moment and try again.</value><comment>long</comment></data>
<data name="Editor.Error.FramesChanged" xml:space="preserve"><value>The frames of this sequence changed on the server; get its proxies again.</value><comment>long</comment></data>
<data name="Editor.Error.Missing" xml:space="preserve"><value>This sequence is no longer in the archive.</value><comment>long</comment></data>
+1
View File
@@ -106,6 +106,7 @@
<data name="Server.Error.ScheduleSystem" xml:space="preserve"><value>A system schedule cannot be deleted; turn it off instead.</value><comment>long</comment></data>
<data name="Server.Error.Self" xml:space="preserve"><value>You cannot do this to your own account.</value><comment>long</comment></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>A job is working on this sequence or its archive; try again when it is free.</value><comment>long</comment></data>
<data name="Server.Error.SequenceEmpty" xml:space="preserve"><value>This sequence has no photos yet; its projects start with its first photo.</value><comment>long</comment></data>
<data name="Server.Error.SequenceInLibrary" xml:space="preserve"><value>That sequence is in the library already.</value><comment>long</comment></data>
<data name="Server.Error.SessionExpired" xml:space="preserve"><value>The session expired; sign in again.</value><comment>long</comment></data>
<data name="Server.Error.SettingLocked" xml:space="preserve"><value>An environment variable sets this; change it there.</value><comment>long</comment></data>
+1
View File
@@ -63,6 +63,7 @@
<data name="Editor.Copy.Restored" xml:space="preserve"><value>Progetto ripristinato</value></data>
<data name="Editor.Copy.Same" xml:space="preserve"><value>Niente da ripristinare</value></data>
<data name="Editor.Copy.Undo" xml:space="preserve"><value>Annulla</value></data>
<data name="Editor.Error.Empty" xml:space="preserve"><value>Questa sequenza non ha ancora foto.</value></data>
<data name="Editor.Error.FramesArriving" xml:space="preserve"><value>Si stanno aggiungendo foto a questa sequenza; attendi un momento e riprova.</value></data>
<data name="Editor.Error.FramesChanged" xml:space="preserve"><value>I fotogrammi di questa sequenza sono cambiati sul server; scarica di nuovo i proxy.</value></data>
<data name="Editor.Error.Missing" xml:space="preserve"><value>Questa sequenza non è più nell’archivio.</value></data>
+1
View File
@@ -104,6 +104,7 @@
<data name="Server.Error.ScheduleSystem" xml:space="preserve"><value>Una pianificazione di sistema non si può eliminare; disattivala.</value><comment>long</comment></data>
<data name="Server.Error.Self" xml:space="preserve"><value>Non puoi farlo sul tuo account.</value></data>
<data name="Server.Error.SequenceBusy" xml:space="preserve"><value>Un'attività sta lavorando su questa sequenza o sul suo archivio; riprova quando è libera.</value></data>
<data name="Server.Error.SequenceEmpty" xml:space="preserve"><value>Questa sequenza non ha ancora foto; i suoi progetti iniziano con la prima foto.</value></data>
<data name="Server.Error.SequenceInLibrary" xml:space="preserve"><value>Quella sequenza è già nella libreria.</value></data>
<data name="Server.Error.SessionExpired" xml:space="preserve"><value>La sessione è scaduta; accedi di nuovo.</value></data>
<data name="Server.Error.SettingLocked" xml:space="preserve"><value>È impostato da una variabile d'ambiente; modificala lì.</value></data>
@@ -791,6 +791,10 @@ public sealed class SequenceViewModel : SectionViewModel
{
throw new InvalidOperationException(Loc.L("Editor.Error.Missing"), ex);
}
catch (ProjectException ex) when (ex.Reason == ProjectError.SequenceEmpty)
{
throw new InvalidOperationException(Loc.L("Editor.Error.Empty"), ex);
}
catch (HomeUnavailableException ex)
{
// Said of the server, not of this PC's library.
+2 -1
View File
@@ -418,7 +418,8 @@ public sealed class WorkspaceHost
var listed = await reached.ListAsync(cancellationToken).ConfigureAwait(false);
project = projectId is { } id
? listed.FirstOrDefault(p => p.Id == id) ?? throw new ProjectException(ProjectError.NotFound, $"The home has no project {id}.")
: listed.First(p => p.IsMain);
// A server's sequence with no photo yet has no projects at all.
: listed.FirstOrDefault(p => p.IsMain) ?? throw new ProjectException(ProjectError.SequenceEmpty, $"Sequence {sequenceId} has no projects yet.");
}
// A copy here this Chronos cannot read (damaged, or a newer Chronos's): nothing is checked out or copied over it.
if (Store.Find(project.Id) is { } here && await EntryOrUnreadableAsync(here, cancellationToken).ConfigureAwait(false) is { IsReadable: false } unreadable)
+13 -1
View File
@@ -355,14 +355,26 @@ public sealed class ArchiveIndexer
{
if (await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) is not { } row
|| !Directory.Exists(paths.Sequence(row.Folder).ProjectsDirectory)) return;
ProjectChangeSet? changed = null;
try
{
await using (await _writer.LockAsync(paths, sequenceId, cancellationToken).ConfigureAwait(false))
{
var folder = await SequenceWriter.FolderAsync(_db, paths, row, cancellationToken).ConfigureAwait(false);
if (!SequenceFolders.Holds(folder, sequenceId) || !Directory.Exists(folder.ProjectsDirectory)) return;
await _projects.ReconcileAsync(folder, sequenceId, cancellationToken).ConfigureAwait(false);
// Projects and versions another program wrote, taken in here, are told as a project call's are: the next call
// finds them in the index already and has nothing to tell.
var before = await ProjectService.WatchedAsync(_db, _writer.Options, sequenceId, cancellationToken).ConfigureAwait(false);
try
{
await _projects.ReconcileAsync(folder, sequenceId, cancellationToken).ConfigureAwait(false);
}
finally
{
if (before is not null) changed = await ProjectService.ChangesAsync(_db, sequenceId, before, settingsChanged: false).ConfigureAwait(false);
}
}
if (changed is not null) await ProjectService.TellAsync(_writer.Options, changed).ConfigureAwait(false);
}
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
{
@@ -3,6 +3,7 @@ using Chronos.Core.Archiving;
using Chronos.Core.Conversion;
using Chronos.Core.Diagnostics;
using Chronos.Core.Import;
using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Core.Naming;
@@ -348,6 +349,65 @@ public sealed class ArchiveService : IJobHandlerProvider
return await write(await _db.Sequences.GetAsync(sequence.Id, cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
}
/// <summary>
/// Settings a caller writes into the index (<paramref name="edit"/>: the server's <c>PATCH</c>, with its version checks)
/// written into the sequence's <c>project.json</c> too, under its lease, as every other writer of the settings does: so
/// the file never holds settings older than the index's, which the projects would take for the sequence's own when they
/// meet Main (<see cref="ProjectService"/>). <paramref name="settingsJson"/> goes to the file first; when the index then
/// does not take it (a conflict, the sequence gone) or the edit fails, the file is put back as it was. A sequence with no
/// folder yet is edited in the index alone: its first photo writes the file from the index.
/// </summary>
/// <param name="wait">How long the sequence's lease is waited for.</param>
/// <exception cref="ArgumentException">The sequence or its archive is not in the index.</exception>
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only: nothing is written.</exception>
/// <exception cref="LeaseUnavailableException">Another writer held the sequence for longer than <paramref name="wait"/>: nothing is written.</exception>
/// <exception cref="SequenceFolderMovedException">The sequence's folder does not hold it now: nothing is written.</exception>
/// <exception cref="IOException">The file cannot be written: nothing is written.</exception>
public async Task<SequenceEditResult> EditSettingsAsync(Guid sequenceId, string settingsJson, Func<CancellationToken, Task<SequenceEditResult>> edit, TimeSpan wait,
CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(settingsJson);
ArgumentNullException.ThrowIfNull(edit);
var (archive, sequence) = await LoadSequenceAsync(sequenceId, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(sequence.Folder)) return await edit(cancellationToken).ConfigureAwait(false);
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
await using (await _writer.LockAsync(paths, sequenceId, wait, cancellationToken).ConfigureAwait(false))
{
var row = await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) ?? throw Unknown(sequenceId);
var folder = paths.Sequence(row.Folder);
if (string.IsNullOrEmpty(row.Folder) || !SequenceFolders.Holds(folder, sequenceId)) throw new SequenceFolderMovedException();
var previous = File.Exists(folder.ProjectPath) ? AtomicFile.ReadAllText(folder.ProjectPath) : null;
Directory.CreateDirectory(folder.MetaDirectory);
AtomicFile.WriteAllText(folder.ProjectPath, settingsJson);
SequenceEditResult result;
try
{
result = await edit(cancellationToken).ConfigureAwait(false);
}
catch
{
PutBack(folder, previous);
throw;
}
if (result.Outcome != SequenceEditOutcome.Updated) PutBack(folder, previous);
return result;
}
static void PutBack(SequencePaths folder, string? previous)
{
try
{
if (previous is not null) AtomicFile.WriteAllText(folder.ProjectPath, previous);
else File.Delete(folder.ProjectPath);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Warning("archive", $"The project.json of {folder.RelativeFolder} could not be put back after an edit the index did not take", ex);
}
}
}
public Task<IReadOnlyList<DuplicateGroup>> FindDuplicatesAsync(Guid archiveId, CancellationToken cancellationToken = default) =>
Maintenance.FindDuplicatesAsync(archiveId, cancellationToken);
+10 -1
View File
@@ -176,8 +176,17 @@ public sealed class ArchiveProjectHome(ChronosDatabase db, ProjectService projec
/// hashed and a checksum of those hashes (a Verify hashes them, or finds other bytes, without another frames version)
/// and how many removals it keeps (a conversion's links).
/// </summary>
public async Task<string?> FramesStampAsync(CancellationToken cancellationToken)
public async Task<string?> FramesStampAsync(CancellationToken cancellationToken) =>
await StampOfAsync(db, sequenceId, cancellationToken).ConfigureAwait(false);
/// <summary>
/// The stamp of a sequence's frames as an index holds them (<see cref="FramesStampAsync"/>): what a server answers for
/// its sequences too (<c>GET …/projects/frames/stamp</c>).
/// </summary>
/// <exception cref="ProjectException">The sequence is not in the index.</exception>
public static async Task<string> StampOfAsync(ChronosDatabase db, Guid sequenceId, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(db);
var row = await db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false)
?? throw new ProjectException(ProjectError.SequenceNotFound, $"Sequence {sequenceId} is not in the index.");
var (hashed, checksum, removals) = await db.Frames.CountNamedAsync(sequenceId, cancellationToken).ConfigureAwait(false);
+54 -13
View File
@@ -27,6 +27,12 @@ public enum ProjectError
/// <summary>The Main project cannot be deleted: it holds the sequence's own settings.</summary>
MainCannotBeDeleted,
/// <summary>
/// The sequence has no folder in its archive yet (made before its first photo, as a server's new sequence is): it keeps
/// no projects until its first photo places it.
/// </summary>
SequenceEmpty,
}
/// <summary>A project operation was refused; nothing was written.</summary>
@@ -406,6 +412,7 @@ public sealed class ProjectService
ArgumentNullException.ThrowIfNull(version);
if (await _db.Projects.GetAsync(projectId, cancellationToken).ConfigureAwait(false) is not { DeletedAt: null } project) return false;
var (paths, row) = await LocateAsync(project.SequenceId, cancellationToken).ConfigureAwait(false);
if (Unplaced(row)) return false;
if (Availability(paths) == ArchiveAvailability.Offline) throw new ArchiveOfflineException(paths.Root, ArchiveAvailability.Offline);
var folder = paths.Sequence(row.Folder);
if (!SequenceFolders.Holds(folder, project.SequenceId)) throw new SequenceFolderMovedException();
@@ -446,6 +453,8 @@ public sealed class ProjectService
/// </summary>
private async Task ReadAsync(Guid sequenceId, CancellationToken cancellationToken)
{
// A sequence with no folder yet keeps no projects: nothing to catch up, and nothing may be written (its folder would be the archive's root).
if (Unplaced(await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) ?? throw SequenceMissing(sequenceId))) return;
try
{
try
@@ -479,6 +488,8 @@ public sealed class ProjectService
{
var (paths, row) = await LocateAsync(sequenceId, cancellationToken).ConfigureAwait(false);
var folder = paths.Sequence(row.Folder);
// What the sidecars bring into the index, and a Main made in it, are told as any other call's changes.
var before = await WatchedAsync(sequenceId, cancellationToken).ConfigureAwait(false);
try
{
if (!SequenceFolders.Holds(folder, sequenceId))
@@ -494,6 +505,11 @@ public sealed class ProjectService
{
Log.Info("projects", $"The projects of sequence {sequenceId} are read from the index: {ex.Message}");
}
finally
{
if (before is not null && await ChangesAsync(sequenceId, before, settingsChanged: false).ConfigureAwait(false) is { } changed)
await TellAsync(changed).ConfigureAwait(false);
}
}
/// <summary>
@@ -507,7 +523,10 @@ public sealed class ProjectService
private async Task<T> UnderLeaseAsync<T>(Guid sequenceId, Func<LeaseContext, CancellationToken, Task<T>> work, CancellationToken cancellationToken,
TimeSpan? wait = null)
{
var (paths, _) = await LocateAsync(sequenceId, cancellationToken).ConfigureAwait(false);
var (paths, located) = await LocateAsync(sequenceId, cancellationToken).ConfigureAwait(false);
// Before the lease: the archive's root is no sequence's folder, so nothing of this sequence's projects is read from it or written into it.
if (Unplaced(located))
throw new ProjectException(ProjectError.SequenceEmpty, $"Sequence {sequenceId} has no folder yet: it keeps no projects before its first photo.");
var availability = Availability(paths);
if (availability != ArchiveAvailability.Online) throw new ArchiveOfflineException(paths.Root, availability);
ProjectChangeSet? changed = null;
@@ -517,7 +536,7 @@ public sealed class ProjectService
{
var row = await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) ?? throw SequenceMissing(sequenceId);
var folder = paths.Sequence(row.Folder);
if (!SequenceFolders.Holds(folder, sequenceId)) throw new SequenceFolderMovedException();
if (Unplaced(row) || !SequenceFolders.Holds(folder, sequenceId)) throw new SequenceFolderMovedException();
// Taken before the reconcile: the versions another program wrote into the sidecars are told too.
var before = await WatchedAsync(sequenceId, cancellationToken).ConfigureAwait(false);
LeaseContext? context = null;
@@ -542,21 +561,36 @@ public sealed class ProjectService
}
/// <summary>The sequence's projects as the index has them now (deleted ones too), when someone is to be told what changes; else null.</summary>
private async Task<Dictionary<Guid, SequenceProject>?> WatchedAsync(Guid sequenceId, CancellationToken cancellationToken) =>
_writer.Options.ProjectsChanged is null
? null
: (await _db.Projects.ListBySequenceAsync(sequenceId, includeDeleted: true, cancellationToken).ConfigureAwait(false)).ToDictionary(p => p.Id);
private Task<Dictionary<Guid, SequenceProject>?> WatchedAsync(Guid sequenceId, CancellationToken cancellationToken) =>
WatchedAsync(_db, _writer.Options, sequenceId, cancellationToken);
private Task<ProjectChangeSet?> ChangesAsync(Guid sequenceId, Dictionary<Guid, SequenceProject> before, bool settingsChanged) =>
ChangesAsync(_db, sequenceId, before, settingsChanged);
private Task TellAsync(ProjectChangeSet changed) => TellAsync(_writer.Options, changed);
/// <summary>
/// What changed in the sequence's projects since <paramref name="before"/> (a project new or back, deleted, renamed, or
/// with a new head); null when nothing did. Never throws: it runs after the work, whatever became of it.
/// The sequence's projects as the index has them now (deleted ones too), when someone is to be told what changes
/// (<see cref="ArchiveServiceOptions.ProjectsChanged"/>); else null. Shared with the scans that take the sidecars back
/// outside a project call (<see cref="ArchiveIndexer"/>).
/// </summary>
private async Task<ProjectChangeSet?> ChangesAsync(Guid sequenceId, Dictionary<Guid, SequenceProject> before, bool settingsChanged)
internal static async Task<Dictionary<Guid, SequenceProject>?> WatchedAsync(ChronosDatabase db, ArchiveServiceOptions options, Guid sequenceId,
CancellationToken cancellationToken) =>
options.ProjectsChanged is null
? null
: (await db.Projects.ListBySequenceAsync(sequenceId, includeDeleted: true, cancellationToken).ConfigureAwait(false)).ToDictionary(p => p.Id);
/// <summary>
/// What changed in the sequence's projects since <paramref name="before"/> (a project new or back, deleted, renamed or
/// made Main or no longer Main, or with a new head); null when nothing did. Never throws: it runs after the work,
/// whatever became of it.
/// </summary>
internal static async Task<ProjectChangeSet?> ChangesAsync(ChronosDatabase db, Guid sequenceId, Dictionary<Guid, SequenceProject> before, bool settingsChanged)
{
IReadOnlyList<SequenceProject> after;
try
{
after = await _db.Projects.ListBySequenceAsync(sequenceId, includeDeleted: true, CancellationToken.None).ConfigureAwait(false);
after = await db.Projects.ListBySequenceAsync(sequenceId, includeDeleted: true, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex) when (ex is DatabaseException or IOException or InvalidOperationException)
{
@@ -572,7 +606,8 @@ public sealed class ProjectService
else if (!live && wasLive) changes.Add(Change(project, Protocol.ProjectChanges.Deleted));
else if (live)
{
if (project.Name != was!.Name) changes.Add(Change(project, Protocol.ProjectChanges.Renamed));
// Main passed to another project (the sidecars name another one Main): told as a rename, which lists read again for.
if (project.Name != was!.Name || project.IsMain != was.IsMain) changes.Add(Change(project, Protocol.ProjectChanges.Renamed));
if (project.HeadVersionId != was.HeadVersionId) changes.Add(Change(project, Protocol.ProjectChanges.Pushed));
}
}
@@ -582,11 +617,11 @@ public sealed class ProjectService
}
/// <summary>Tells the host what a call changed; a failure is logged, never passed on.</summary>
private async Task TellAsync(ProjectChangeSet changed)
internal static async Task TellAsync(ArchiveServiceOptions options, ProjectChangeSet changed)
{
try
{
await _writer.Options.ProjectsChanged!(changed, CancellationToken.None).ConfigureAwait(false);
await options.ProjectsChanged!(changed, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -1322,6 +1357,12 @@ public sealed class ProjectService
? project
: throw new ProjectException(ProjectError.NotFound, $"Project {projectId} was deleted.");
/// <summary>
/// Whether the sequence has no folder in its archive yet (a server's sequence made before its first photo): its folder
/// would read as the archive's root, which every such sequence shares and which is no sequence's.
/// </summary>
private static bool Unplaced(Sequence row) => string.IsNullOrEmpty(row.Folder);
private static ProjectException SequenceMissing(Guid sequenceId) => new(ProjectError.SequenceNotFound, $"Sequence {sequenceId} is not in the index.");
/// <summary>The sequence as read under its lease (the mirror moves its settings version), its folder, and what its projects' reconcile met.</summary>
+49 -10
View File
@@ -92,19 +92,57 @@ public sealed class ServerProjectHome : IProjectHome
? ProjectWire.ToVersion(version)
: null, cancellationToken);
/// <remarks>
/// The server ends a page early when its versions' settings are large (<see cref="ProjectVersionPageDto.More"/>): the
/// pages are read on until <paramref name="limit"/> versions came or no more follow, so a short answer always means the end.
/// </remarks>
public Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken) =>
Reach<IReadOnlyList<ProjectVersion>>(async () =>
[
.. (await Client.ListProjectVersionsAsync(SequenceId, projectId, after: Math.Max(0, afterNumber), limit: Page(limit), ct: cancellationToken)
.ConfigureAwait(false)).Items.Select(ProjectWire.ToVersion),
], cancellationToken);
Reach(() => PagesAsync(Page(limit), last => Client.ListProjectVersionsAsync(SequenceId, projectId, after: Math.Max(0, last?.Number ?? afterNumber),
limit: Page(limit), ct: cancellationToken)), cancellationToken);
/// <remarks>Read on past a page the server ended early, as <see cref="VersionsAfterAsync"/> is.</remarks>
public Task<IReadOnlyList<ProjectVersion>> HistoryAsync(Guid projectId, int? beforeNumber, int limit, CancellationToken cancellationToken) =>
Reach<IReadOnlyList<ProjectVersion>>(async () =>
[
.. (await Client.ListProjectVersionsAsync(SequenceId, projectId, before: beforeNumber is { } before ? Math.Max(0, before) : null, limit: Page(limit),
ct: cancellationToken).ConfigureAwait(false)).Items.Select(ProjectWire.ToVersion),
], cancellationToken);
Reach(() => PagesAsync(Page(limit), last => Client.ListProjectVersionsAsync(SequenceId, projectId,
before: last is not null ? last.Number : beforeNumber is { } before ? Math.Max(0, before) : null, limit: Page(limit), ct: cancellationToken)),
cancellationToken);
/// <summary>Up to <paramref name="limit"/> versions, page after page (each read after the last version of the one before) while more follow.</summary>
private static async Task<IReadOnlyList<ProjectVersion>> PagesAsync(int limit, Func<ProjectVersion?, Task<ProjectVersionPageDto>> read)
{
var versions = new List<ProjectVersion>();
while (true)
{
var page = await read(versions.Count > 0 ? versions[^1] : null).ConfigureAwait(false);
versions.AddRange(page.Items.Take(limit - versions.Count).Select(ProjectWire.ToVersion));
if (!page.More || page.Items.Count == 0 || versions.Count >= limit) return versions;
}
}
/// <summary>
/// Read back from the version's file on the server (<c>?stored=true</c>: <see cref="ProjectService.StoredAsync"/> there),
/// never from its index's row: false when the file is missing or damaged, or the project was deleted.
/// </summary>
public Task<bool> HoldsAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(version);
return Reach(async () =>
{
if (!ProjectContent.Verifies(version.SettingsJson, version.ContentHash)) return false;
try
{
return await Client.GetStoredProjectVersionAsync(SequenceId, projectId, version.Id, cancellationToken).ConfigureAwait(false) is { } held
&& held.ProjectId == projectId && string.Equals(held.ContentHash, version.ContentHash, StringComparison.OrdinalIgnoreCase);
}
catch (ChronosApiException ex) when (ex is { Status: HttpStatusCode.NotFound, Error.Details: "project" })
{
return false;
}
}, cancellationToken);
}
/// <summary>The server's stamp of the frames (<c>GET …/projects/frames/stamp</c>): the frames are downloaded again only when it moved.</summary>
public Task<string?> FramesStampAsync(CancellationToken cancellationToken) =>
Reach<string?>(async () => (await Client.GetProjectFramesStampAsync(SequenceId, cancellationToken).ConfigureAwait(false)).Stamp, cancellationToken);
/// <remarks>The server numbers the version (head + 1) and records the account that pushed it as its author.</remarks>
public Task<PushResult> PushAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken)
@@ -174,6 +212,7 @@ public sealed class ServerProjectHome : IProjectHome
(HttpStatusCode.BadRequest, ProjectErrors.InvalidName, _) => new ProjectException(ProjectError.InvalidName, ex.Message),
(HttpStatusCode.Conflict, ProjectErrors.NameTaken, _) => new ProjectException(ProjectError.NameTaken, ex.Message),
(HttpStatusCode.Conflict, ProjectErrors.MainCannotBeDeleted, _) => new ProjectException(ProjectError.MainCannotBeDeleted, ex.Message),
(HttpStatusCode.Conflict, ProjectErrors.SequenceEmpty, _) => new ProjectException(ProjectError.SequenceEmpty, ex.Message),
_ => null,
};
+32 -7
View File
@@ -507,7 +507,9 @@ public sealed class ChronosClient : IDisposable
/// <summary>
/// One page of a project's versions: newest first, numbered below <paramref name="before"/> (from the head when null),
/// or, with <paramref name="after"/>, oldest first numbered above it (what a workspace pulls). <paramref name="limit"/>:
/// 1–200 (the server's default, 50 newest first and 100 oldest first, when null).
/// 1–200 (the server's default, 50 newest first and 100 oldest first, when null). A page may hold fewer versions than
/// asked for while more follow (<see cref="ProjectVersionPageDto.More"/>): the server also ends one before its settings
/// pass a few MiB (<c>?summary=true</c> leaves the settings out, for a list of the versions).
/// </summary>
public Task<ProjectVersionPageDto> ListProjectVersionsAsync(Guid sequenceId, Guid projectId, int? before = null, int? after = null, int? limit = null,
CancellationToken ct = default) =>
@@ -515,12 +517,22 @@ public sealed class ChronosClient : IDisposable
ProtocolJson.Default.ProjectVersionPageDto, ct);
/// <summary>A version of the project by id; null when the server has no such version of it.</summary>
public async Task<ProjectVersionDto?> GetProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default)
public Task<ProjectVersionDto?> GetProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default) =>
VersionOrNullAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}", ct);
/// <summary>
/// A version of the project the server holds durably, read back from its file now with its content hash: what a workspace
/// asks before it drops its own copy. Null when the file is missing or damaged, or the server has no such version; a
/// deleted project is a 404 <c>project</c> <see cref="ChronosApiException"/>.
/// </summary>
public Task<ProjectVersionDto?> GetStoredProjectVersionAsync(Guid sequenceId, Guid projectId, Guid versionId, CancellationToken ct = default) =>
VersionOrNullAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}?stored=true", ct);
private async Task<ProjectVersionDto?> VersionOrNullAsync(string path, CancellationToken ct)
{
try
{
return await GetAsync($"api/v1/sequences/{sequenceId}/projects/{projectId}/versions/{versionId}", ProtocolJson.Default.ProjectVersionDto, ct)
.ConfigureAwait(false);
return await GetAsync(path, ProtocolJson.Default.ProjectVersionDto, ct).ConfigureAwait(false);
}
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.NotFound && ex.Error.Details == "version")
{
@@ -532,8 +544,8 @@ public sealed class ChronosClient : IDisposable
/// Pushes <paramref name="version"/>, made in a workspace from the project's head (<see cref="ProjectVersionDto.ParentId"/>):
/// the server stores it as the new head, numbered head + 1 (201, <c>stored</c>), or answers it again for a repeated push
/// (200, <c>already_stored</c>), or refuses it, storing nothing: 409 <c>diverged</c> with the head, 422
/// <c>hash_mismatch</c>, <c>newer_format</c>, <c>too_large</c> or <c>invalid</c>. These come back as <see cref="ProjectPushResultDto"/>
/// without throwing; any other failure (the sequence or project gone, no permission, the archive offline or the sequence
/// <c>hash_mismatch</c>, <c>newer_format</c>, <c>too_large</c> or <c>invalid</c>; a body larger than the server (or a proxy before
/// it) takes, 413, is <c>too_large</c> too. These come back as <see cref="ProjectPushResultDto"/> without throwing; any other failure (the sequence or project gone, no permission, the archive offline or the sequence
/// busy: 503) throws <see cref="ChronosApiException"/>. Safe to repeat: the version's id makes a second push a no-op.
/// </summary>
public async Task<ProjectPushResultDto> PushProjectVersionAsync(Guid sequenceId, Guid projectId, ProjectVersionDto version, CancellationToken ct = default)
@@ -556,6 +568,8 @@ public sealed class ChronosClient : IDisposable
// Not a push answer (a proxy's page): the status says what failed.
}
}
if (response.StatusCode == HttpStatusCode.RequestEntityTooLarge)
return new ProjectPushResultDto(ProjectPushOutcomes.TooLarge, null, null, ProjectErrors.TooLarge, response.ReasonPhrase);
await EnsureSuccessAsync(response, ct).ConfigureAwait(false);
throw new ChronosApiException(response.StatusCode, new ApiError("http_" + (int)response.StatusCode, response.ReasonPhrase ?? "error"));
}
@@ -564,16 +578,27 @@ public sealed class ChronosClient : IDisposable
public Task<ProjectFramesDto> GetProjectFramesAsync(Guid sequenceId, CancellationToken ct = default) =>
GetAsync($"api/v1/sequences/{sequenceId}/projects/frames", ProtocolJson.Default.ProjectFramesDto, ct);
/// <summary>A cheap stamp of what <see cref="GetProjectFramesAsync"/> answers: the frames are read again only when it moved.</summary>
public Task<ProjectFramesStampDto> GetProjectFramesStampAsync(Guid sequenceId, CancellationToken ct = default) =>
GetAsync($"api/v1/sequences/{sequenceId}/projects/frames/stamp", ProtocolJson.Default.ProjectFramesStampDto, ct);
// ---------------- Events ----------------
/// <summary>Server events over WebSocket until cancelled; reconnect is the caller's policy.</summary>
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken ct = default)
public IAsyncEnumerable<ServerEvent> EventsAsync(CancellationToken ct = default) => EventsAsync(null, ct);
/// <summary>
/// Server events over WebSocket until cancelled, calling <paramref name="connected"/> once the socket is open (before its
/// first event): from then on no event the server sends is missed.
/// </summary>
public async IAsyncEnumerable<ServerEvent> EventsAsync(Action? connected, [EnumeratorCancellation] CancellationToken ct = default)
{
using var socket = new ClientWebSocket();
socket.Options.RemoteCertificateValidationCallback = _pinning.Validate;
if (_token is not null) socket.Options.SetRequestHeader("Authorization", "Bearer " + _token);
var ws = new UriBuilder(new Uri(BaseAddress, "api/v1/events")) { Scheme = BaseAddress.Scheme == "https" ? "wss" : "ws" }.Uri;
await socket.ConnectAsync(ws, ct).ConfigureAwait(false);
connected?.Invoke();
var buffer = new byte[64 * 1024];
using var message = new MemoryStream();
while (socket.State == WebSocketState.Open && !ct.IsCancellationRequested)
+13
View File
@@ -87,6 +87,13 @@ public sealed record ProjectPushResultDto(string Outcome, ProjectVersionDto? Ver
/// </summary>
public sealed record ProjectFramesDto(Guid SequenceId, int FramesVersion, IReadOnlyList<FrameDto> Frames, IReadOnlyList<RemovedPhotoDto>? Aliases = null);
/// <summary>
/// <c>GET /api/v1/sequences/{sid}/projects/frames/stamp</c>: a cheap stamp of what <c>…/projects/frames</c> answers, another
/// value whenever the frames, how their photos are named (a hash learnt) or the encodings conversions joined may have
/// changed, so a workspace reads the frames again only then.
/// </summary>
public sealed record ProjectFramesStampDto(Guid SequenceId, string Stamp);
/// <summary>What became of a pushed version (<see cref="ProjectPushResultDto.Outcome"/>).</summary>
public static class ProjectPushOutcomes
{
@@ -154,4 +161,10 @@ public static class ProjectErrors
/// <summary>409: the Main project holds the sequence's own settings and is never deleted.</summary>
public const string MainCannotBeDeleted = "main_cannot_be_deleted";
/// <summary>409: the sequence has no photo yet (no folder in the archive), so it keeps no projects; its list is empty.</summary>
public const string SequenceEmpty = "sequence_empty";
/// <summary>413 from a push: the body is larger than the server takes; read as the outcome <see cref="ProjectPushOutcomes.TooLarge"/>.</summary>
public const string TooLarge = "too_large";
}
+1
View File
@@ -99,4 +99,5 @@ namespace Chronos.Protocol;
[JsonSerializable(typeof(ProjectVersionPageDto))]
[JsonSerializable(typeof(ProjectPushResultDto))]
[JsonSerializable(typeof(ProjectFramesDto))]
[JsonSerializable(typeof(ProjectFramesStampDto))]
public sealed partial class ProtocolJson : JsonSerializerContext;
+70 -18
View File
@@ -25,13 +25,21 @@ public static class ProjectEndpoints
{
/// <summary>
/// The body a push may take: a version's portable settings name each exclusion and camera keyframe by photo (about 150
/// bytes each), so the project of a large sequence outgrows the 1 MiB of other JSON bodies.
/// bytes each), so the project of a large sequence outgrows the 1 MiB of other JSON bodies. Any version this PC's archive
/// or a workspace stores (a file up to <see cref="ProjectSidecars.MaxVersionBytes"/>; the body, with its settings as one
/// JSON string, is no larger) fits, with room for the rest of the version: a server and a PC's archive take the same.
/// </summary>
public const long PushBodyLimit = 16L * 1024 * 1024;
public const long PushBodyLimit = ProjectSidecars.MaxVersionBytes + (1L << 20);
/// <summary>Versions one page may hold.</summary>
public const int MaxPage = 200;
/// <summary>
/// The settings one page of versions carries at most (in characters): a page stops before the version that would pass it
/// (one version always goes) and says more follow, so an answer stays a few MiB however large a sequence's versions are.
/// </summary>
internal const long PageSettingsChars = 4L << 20;
private const int MaxNote = 2000;
private const int MaxClientName = 200;
@@ -41,6 +49,7 @@ public static class ProjectEndpoints
projects.MapGet("", ListAsync);
projects.MapPost("", CreateAsync).Requires(Permissions.Edit);
projects.MapGet("/frames", FramesAsync);
projects.MapGet("/frames/stamp", FramesStampAsync);
projects.MapGet("/{pid:guid}", GetAsync);
projects.MapPatch("/{pid:guid}", RenameAsync).Requires(Permissions.Edit);
projects.MapDelete("/{pid:guid}", DeleteAsync).Requires(Permissions.Delete);
@@ -53,15 +62,16 @@ public static class ProjectEndpoints
/// <summary>
/// The sequence's live projects, Main first, each with its head's kind, author, client and time. A sequence without a Main
/// project gets it now, from its settings; while that cannot be done (the archive offline, the sequence busy, its folder
/// elsewhere) the answer is 503 with the reason's code.
/// elsewhere) the answer is 503 with the reason's code. A sequence with no photo yet (no folder in the archive) has none:
/// the list is empty, and nothing is written.
/// </summary>
private static async Task<IResult> ListAsync(HttpContext context, Guid sid, ChronosDatabase db, [FromServices] ArchiveService? archives) =>
await RunAsync(context, "project", async ct =>
{
if (await db.Sequences.GetAsync(sid, ct) is null) return ApiErrors.NotFound(context, "sequence");
if (await db.Sequences.GetAsync(sid, ct) is not { } sequence) return ApiErrors.NotFound(context, "sequence");
var projects = LibraryEndpoints.Engine(archives, db).Projects;
var list = await projects.ListAsync(sid, ct);
if (!list.Any(p => p.IsMain))
if (!list.Any(p => p.IsMain) && !string.IsNullOrEmpty(sequence.Folder))
{
await projects.MainAsync(sid, ct);
list = await projects.ListAsync(sid, ct);
@@ -73,8 +83,8 @@ public static class ProjectEndpoints
/// <summary>
/// A new project (201): its first version, kind <c>imported</c>, copies <c>fromVersionId</c> (a version of any project of the
/// sequence; 404 <c>not_found</c> <c>version</c> otherwise) or Main's head. 400 <c>invalid_name</c>, 409 <c>name_taken</c>.
/// Audited <c>project_created</c>.
/// sequence; 404 <c>not_found</c> <c>version</c> otherwise) or Main's head. 400 <c>invalid_name</c>, 409 <c>name_taken</c>,
/// <c>sequence_empty</c> (no photo yet). Audited <c>project_created</c>.
/// </summary>
private static async Task<IResult> CreateAsync(HttpContext context, Caller caller, Guid sid, CreateProjectRequest request, ChronosDatabase db,
[FromServices] ArchiveService? archives, AuditLog audit, IHostApplicationLifetime lifetime) =>
@@ -136,7 +146,7 @@ public static class ProjectEndpoints
var project = known.Project!;
if (project.DeletedAt is not null) return ApiErrors.NotFound(context, "project");
if (project.IsMain) return ApiErrors.Conflict(context, ProjectErrors.MainCannotBeDeleted);
if (!caller.IsAdmin && known.Sequence!.OwnerUserId != caller.Id && project.CreatedBy != caller.User.Username) return ApiErrors.Forbidden(context);
if (!caller.IsAdmin && known.Sequence!.OwnerUserId != caller.Id && !MadeBy(project, caller.User)) return ApiErrors.Forbidden(context);
await projects.DeleteAsync(pid, lifetime.ApplicationStopping);
await audit.WriteAsync(caller, context, "project_deleted", "project", pid.ToString(), $"{sid} · {project.Name}");
return Results.NoContent();
@@ -159,9 +169,11 @@ public static class ProjectEndpoints
/// <summary>
/// One page of the project's versions: newest first, numbered below <paramref name="before"/> (from the head when absent),
/// or with <paramref name="after"/> oldest first, numbered above it. <paramref name="limit"/> 1–<see cref="MaxPage"/> (50 newest
/// first, 100 oldest first). 400 <c>bad_request</c> (<c>after</c> with <c>before</c>, a number below 0).
/// first, 100 oldest first); a page also ends before its settings pass <see cref="PageSettingsChars"/>, with <c>more</c>.
/// <paramref name="summary"/>: the versions without their settings (<c>settingsJson</c> empty), what a list of them shows.
/// 400 <c>bad_request</c> (<c>after</c> with <c>before</c>, a number below 0).
/// </summary>
private static async Task<IResult> VersionsAsync(HttpContext context, Guid sid, Guid pid, int? before, int? after, int? limit, ChronosDatabase db,
private static async Task<IResult> VersionsAsync(HttpContext context, Guid sid, Guid pid, int? before, int? after, int? limit, bool? summary, ChronosDatabase db,
[FromServices] ArchiveService? archives)
{
if (before is not null && after is not null) return ApiErrors.BadRequest(context, "bad_request", "after");
@@ -178,26 +190,41 @@ public static class ProjectEndpoints
: await projects.HistoryAsync(pid, before, take + 1, ct);
// The head as the page was read: the call above caught the project up first.
var head = (await projects.GetAsync(pid, ct))?.HeadNumber ?? known.Project!.HeadNumber;
return Results.Json(new ProjectVersionPageDto([.. page.Take(take).Select(ProjectWire.ToDto)], head, page.Count > take),
ProtocolJson.Default.ProjectVersionPageDto);
var items = new List<ProjectVersionDto>(Math.Min(take, page.Count));
var chars = 0L;
foreach (var version in page.Take(take))
{
if (summary != true && items.Count > 0 && chars + version.SettingsJson.Length > PageSettingsChars) break;
chars += version.SettingsJson.Length;
var dto = ProjectWire.ToDto(version);
items.Add(summary == true ? dto with { SettingsJson = string.Empty } : dto);
}
return Results.Json(new ProjectVersionPageDto(items, head, page.Count > items.Count), ProtocolJson.Default.ProjectVersionPageDto);
});
}
/// <summary>A version of the project by id; one the index does not know yet is looked for in the sequence's sidecars first.</summary>
private static async Task<IResult> VersionAsync(HttpContext context, Guid sid, Guid pid, Guid vid, ChronosDatabase db, [FromServices] ArchiveService? archives) =>
/// <summary>
/// A version of the project by id; one the index does not know yet is looked for in the sequence's sidecars first. With
/// <paramref name="stored"/>, only a version the archive holds durably (<see cref="ProjectService.StoredAsync"/>: its
/// file read back now, with that content hash) of a live project: what a workspace asks before it drops its own copy;
/// 404 <c>project</c> for a deleted project, <c>version</c> for a file missing or damaged.
/// </summary>
private static async Task<IResult> VersionAsync(HttpContext context, Guid sid, Guid pid, Guid vid, bool? stored, ChronosDatabase db,
[FromServices] ArchiveService? archives) =>
await RunAsync(context, "version", async ct =>
{
var projects = LibraryEndpoints.Engine(archives, db).Projects;
var known = await KnownAsync(context, db, projects, sid, pid, ct);
if (known.Refused is { } refused) return refused;
if (stored == true && known.Project!.DeletedAt is not null) return ApiErrors.NotFound(context, "project");
if (await projects.GetVersionAsync(vid, ct) is not { } version)
{
await projects.ListAsync(sid, ct);
version = await projects.GetVersionAsync(vid, ct);
}
return version is not null && version.ProjectId == pid
? Results.Json(ProjectWire.ToDto(version), ProtocolJson.Default.ProjectVersionDto)
: ApiErrors.NotFound(context, "version");
if (version is null || version.ProjectId != pid || (stored == true && !await projects.StoredAsync(pid, version, ct)))
return ApiErrors.NotFound(context, "version");
return Results.Json(ProjectWire.ToDto(version), ProtocolJson.Default.ProjectVersionDto);
});
/// <summary>
@@ -271,6 +298,30 @@ public static class ProjectEndpoints
ProtocolJson.Default.ProjectFramesDto);
}
/// <summary>
/// A cheap stamp of what <see cref="FramesAsync"/> answers (<see cref="ArchiveProjectHome.StampOfAsync"/>: the frames
/// version, the photos hashed and their checksum, the removals): a workspace reads the frames again only when it moved.
/// </summary>
private static async Task<IResult> FramesStampAsync(HttpContext context, Guid sid, ChronosDatabase db)
{
try
{
return Results.Json(new ProjectFramesStampDto(sid, await ArchiveProjectHome.StampOfAsync(db, sid, context.RequestAborted)),
ProtocolJson.Default.ProjectFramesStampDto);
}
catch (ProjectException)
{
return ApiErrors.NotFound(context, "sequence");
}
}
/// <summary>
/// Whether <paramref name="user"/> made <paramref name="project"/>: the name it records, by an account that existed when
/// the project was made. An account made since under the name of a deleted one is not its maker.
/// </summary>
internal static bool MadeBy(SequenceProject project, User user) =>
project.CreatedBy is { } maker && string.Equals(maker, user.Username, StringComparison.Ordinal) && user.Created <= project.CreatedAt;
/// <summary>Every frame of a sequence in index order, read a page at a time.</summary>
internal static async Task<List<Frame>> AllFramesAsync(ChronosRepositories db, Guid sequenceId, CancellationToken cancellationToken)
{
@@ -308,7 +359,7 @@ public static class ProjectEndpoints
/// <summary>
/// Runs a project call with its refusals answered by their codes: 404 <c>not_found</c> (<c>sequence</c>, or
/// <paramref name="notFound"/> for a project or version the engine does not know), 400 <c>invalid_name</c>, 409
/// <c>name_taken</c>, <c>main_cannot_be_deleted</c>; 503 <c>archive_offline</c> (offline or read-only), <c>sequence_busy</c>
/// <c>name_taken</c>, <c>main_cannot_be_deleted</c>, <c>sequence_empty</c>; 503 <c>archive_offline</c> (offline or read-only), <c>sequence_busy</c>
/// (another writer held it past the lease wait), <c>folder_moved</c> (its folder is not where the index has it),
/// <c>projects_unreadable</c> (a project record or version this Chronos cannot read now: nothing was written); 413
/// <c>too_large</c> for a version file over 64 MiB; 409 <c>folder_in_use</c> when a project's file cannot be written.
@@ -327,6 +378,7 @@ public static class ProjectEndpoints
ProjectError.InvalidName => ApiErrors.BadRequest(context, ProjectErrors.InvalidName),
ProjectError.NameTaken => ApiErrors.Conflict(context, ProjectErrors.NameTaken),
ProjectError.MainCannotBeDeleted => ApiErrors.Conflict(context, ProjectErrors.MainCannotBeDeleted),
ProjectError.SequenceEmpty => ApiErrors.Conflict(context, ProjectErrors.SequenceEmpty),
_ => ApiErrors.NotFound(context, notFound),
};
}
+44 -2
View File
@@ -25,6 +25,9 @@ public static class SequenceEndpoints
{
private const int MaxTitle = 200;
private const int MaxNotes = 2000;
/// <summary>How long a settings edit waits for the sequence's lease (another writer filing photos or analysing it) before it answers 503 <c>sequence_busy</c>.</summary>
private static readonly TimeSpan SettingsLeaseWait = TimeSpan.FromSeconds(20);
/// <summary>Tags a sequence may carry.</summary>
internal const int MaxTags = 50;
@@ -128,8 +131,15 @@ public static class SequenceEndpoints
return Results.Json(Dto.Sequence(sequence), ProtocolJson.Default.SequenceDto);
}
/// <summary>
/// Edits a sequence's title, tags, rating, notes and settings in the index (the settings version as an optional check). New
/// settings also go to the sequence's <c>project.json</c>, under its lease (<see cref="ArchiveService.EditSettingsAsync"/>),
/// as the archive's other writers of the settings do, so the projects never take an older file for the sequence's
/// settings (owner review 2, R8): 503 <c>archive_offline</c>, <c>sequence_busy</c> or <c>folder_moved</c>, and 409
/// <c>folder_in_use</c>, when that cannot be done now, with nothing changed.
/// </summary>
private static async Task<IResult> UpdateAsync(HttpContext context, Caller caller, Guid id, UpdateSequenceRequest request, ChronosDatabase db,
AuditLog audit, EventHub events, ProjectCatchUp projects)
AuditLog audit, EventHub events, ProjectCatchUp projects, [FromServices] ArchiveService? archives)
{
if (request.Title is { Length: > MaxTitle }) return ApiErrors.BadRequest(context, "bad_request", "title");
if (request.Notes is { Length: > MaxNotes }) return ApiErrors.BadRequest(context, "bad_request", "notes");
@@ -150,7 +160,39 @@ public static class SequenceEndpoints
HeroFrameId = request.HeroFrameId
?? (request.SettingsJson is { } settings ? await SettingsHeroAsync(db, id, settings, context.RequestAborted) : null),
};
var result = await db.Sequences.EditAsync(id, edit, expected, request.ExpectedFramesVersion, context.RequestAborted);
SequenceEditResult result;
if (request.SettingsJson is { } written && archives is not null)
{
try
{
result = await archives.EditSettingsAsync(id, written, ct => db.Sequences.EditAsync(id, edit, expected, request.ExpectedFramesVersion, ct),
SettingsLeaseWait, context.RequestAborted);
}
catch (ArgumentException)
{
return ApiErrors.NotFound(context, "sequence");
}
catch (Chronos.Core.Archiving.ArchiveOfflineException)
{
return ApiErrors.Result(context, StatusCodes.Status503ServiceUnavailable, "archive_offline");
}
catch (Chronos.Core.Archiving.LeaseUnavailableException)
{
return ApiErrors.Result(context, StatusCodes.Status503ServiceUnavailable, "sequence_busy");
}
catch (SequenceFolderMovedException)
{
return ApiErrors.Result(context, StatusCodes.Status503ServiceUnavailable, "folder_moved");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return ApiErrors.Conflict(context, "folder_in_use");
}
}
else
{
result = await db.Sequences.EditAsync(id, edit, expected, request.ExpectedFramesVersion, context.RequestAborted);
}
switch (result.Outcome)
{
case SequenceEditOutcome.NotFound: