CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job. - One naming rule (FrameNaming) for import, upload and Reorganize. - Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder. - Writers refuse a folder another program moved or gave to another sequence. - Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules. - Phase 3 docs and translations merged; strings in all 38 languages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
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);
|
|
}
|
|
}
|