A Reorganize with a file template failed its job at the step of a sequence
a camera was still uploading into, and its retry gave the rest up. Photos
changed since the plan now never refuse a step: that sequence keeps its file
names (FilesKept), its folder and title change as planned, the other steps go
on and the job ends with ReorganizeKept. The fingerprint, the job's
confirmation and the check under the leases pin file renames by their digest
instead of the frames version, so photos filed under the names the plan gives
them no longer make a dry run or a queued job stale.
- A step whose folder or files a template names after {title} checks the
title as a retitle does (RenameStep.NamedByTitle): no name comes from a
title edited since the plan.
- Recovery sends a photo that already took its new name back together with a
companion whose new name was taken, so the two never end up apart.
- ArchiveService.OpenAsync logs a NewerFormatException from resuming a plan
and keeps its journal, so a server still boots.
- Once a step's folder moved, every index row of the step follows it even
when a sidecar cannot be read or written; the step then fails for a retry.
- Job log lines and errors give the real reason for files kept busy (in use
or a new name taken) and for a sidecar of a newer format (new Newer
outcome; strings en and it).
- A plan an archive open completes tells sequenceChanged; the docs that
promised more than that are corrected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f8554b8af0828ab9b0ff128e694abacdd53e6fd7)
60 lines
2.9 KiB
C#
60 lines
2.9 KiB
C#
using System.Net;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
using System.Security.Cryptography;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests;
|
|
|
|
/// <summary>Raw-HTTP upload helpers (the protocol client is exercised separately).</summary>
|
|
internal static class Uploads
|
|
{
|
|
public static byte[] Photo(int size, int seed)
|
|
{
|
|
var bytes = new byte[size];
|
|
new Random(seed).NextBytes(bytes);
|
|
return bytes;
|
|
}
|
|
|
|
public static string Sha(byte[] data) => Convert.ToHexStringLower(SHA256.HashData(data));
|
|
|
|
/// <param name="capturedAt">The capture time the client sends; null: 2026-09-28 18:02:11.</param>
|
|
public static async Task<StartUploadResponse> StartAsync(HttpClient client, byte[] data, string fileName = "IMG_0001.CR3", Guid? sequenceId = null,
|
|
string? sessionKey = null, HttpStatusCode expected = HttpStatusCode.Created, DateTime? capturedAt = null)
|
|
{
|
|
using var response = await client.PostAsJsonAsync("/api/v1/uploads",
|
|
new StartUploadRequest(sequenceId, fileName, data.Length, Sha(data), capturedAt ?? new DateTime(2026, 9, 28, 18, 2, 11), sessionKey),
|
|
ProtocolJson.Default.StartUploadRequest);
|
|
await response.ExpectAsync(expected);
|
|
return await response.ReadAsync(ProtocolJson.Default.StartUploadResponse);
|
|
}
|
|
|
|
public static async Task<HttpResponseMessage> PutChunkAsync(HttpClient client, Guid uploadId, int index, ReadOnlyMemory<byte> data)
|
|
{
|
|
var content = new ByteArrayContent(data.ToArray());
|
|
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
|
return await client.PutAsync($"/api/v1/uploads/{uploadId}/chunks/{index}", content);
|
|
}
|
|
|
|
public static ReadOnlyMemory<byte> Chunk(byte[] data, int chunkSize, int index) =>
|
|
data.AsMemory(index * chunkSize, Math.Min(chunkSize, data.Length - index * chunkSize));
|
|
|
|
/// <summary>Start, every chunk, complete; returns the committed frame.</summary>
|
|
public static async Task<CompleteUploadResponse> UploadAsync(HttpClient client, byte[] data, string fileName = "IMG_0001.CR3", Guid? sequenceId = null,
|
|
string? sessionKey = null, DateTime? capturedAt = null)
|
|
{
|
|
var start = await StartAsync(client, data, fileName, sequenceId, sessionKey, capturedAt: capturedAt);
|
|
var id = Assert.NotNull(start.UploadId);
|
|
var chunks = (data.Length + start.ChunkSize - 1) / start.ChunkSize;
|
|
for (var i = 0; i < chunks; i++)
|
|
{
|
|
using var put = await PutChunkAsync(client, id, i, Chunk(data, start.ChunkSize, i));
|
|
await put.ExpectAsync(HttpStatusCode.OK);
|
|
}
|
|
using var complete = await client.PostAsync($"/api/v1/uploads/{id}/complete", null);
|
|
await complete.ExpectAsync(HttpStatusCode.OK);
|
|
return await complete.ReadAsync(ProtocolJson.Default.CompleteUploadResponse);
|
|
}
|
|
}
|