Files
git.stella-ops.org/src/__Libraries/StellaOps.Provcache.Api/ProvcacheEndpointExtensions.GetProofManifest.cs

55 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace StellaOps.Provcache.Api;
public static partial class ProvcacheEndpointExtensions
{
/// <summary>
/// GET /v1/provcache/proofs/{proofRoot}/manifest
/// </summary>
private static async Task<IResult> GetProofManifestAsync(
string proofRoot,
[FromServices] IEvidenceChunkRepository chunkRepository,
ILogger<ProofsApiEndpoints> logger,
CancellationToken cancellationToken)
{
logger.LogDebug("GET /v1/provcache/proofs/{ProofRoot}/manifest", proofRoot);
try
{
var manifest = await chunkRepository.GetManifestAsync(proofRoot, cancellationToken);
if (manifest is null)
{
return Results.NotFound();
}
var chunkMetadata = manifest.Chunks
.OrderBy(c => c.Index)
.Select(c => new ChunkMetadataResponse
{
ChunkId = c.ChunkId,
Index = c.Index,
Hash = c.Hash,
Size = c.Size,
ContentType = c.ContentType
}).ToList();
return Results.Ok(new ProofManifestResponse
{
ProofRoot = proofRoot,
TotalChunks = manifest.TotalChunks,
TotalSize = manifest.TotalSize,
Chunks = chunkMetadata,
GeneratedAt = manifest.GeneratedAt
});
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting manifest for proof root {ProofRoot}", proofRoot);
return InternalError("Manifest retrieval failed");
}
}
}