stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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}/chunks/{chunkIndex}
|
||||
/// </summary>
|
||||
private static async Task<IResult> GetSingleChunkAsync(
|
||||
string proofRoot,
|
||||
int chunkIndex,
|
||||
[FromServices] IEvidenceChunkRepository chunkRepository,
|
||||
ILogger<ProofsApiEndpoints> logger,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
logger.LogDebug("GET /v1/provcache/proofs/{ProofRoot}/chunks/{ChunkIndex}", proofRoot, chunkIndex);
|
||||
|
||||
try
|
||||
{
|
||||
var chunk = await chunkRepository.GetChunkAsync(proofRoot, chunkIndex, cancellationToken);
|
||||
if (chunk is null)
|
||||
{
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
return Results.Ok(new ProofChunkResponse
|
||||
{
|
||||
ChunkId = chunk.ChunkId,
|
||||
Index = chunk.ChunkIndex,
|
||||
Hash = chunk.ChunkHash,
|
||||
Size = chunk.BlobSize,
|
||||
ContentType = chunk.ContentType,
|
||||
Data = Convert.ToBase64String(chunk.Blob)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error getting chunk {ChunkIndex} for proof root {ProofRoot}", chunkIndex, proofRoot);
|
||||
return InternalError("Chunk retrieval failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user