Добавить панель обработки изображений

This commit is contained in:
Никита
2026-11-10 11:04:44 +03:00
parent ea17657202
commit 0e0efe5614
6 changed files with 126 additions and 2 deletions
@@ -29,6 +29,30 @@ public static class AttachmentEndpoints
if(file is null) return ApiError(ctx,404,"not_found","Вложение не найдено");
return Results.Ok(file.Value.Dto);
});
app.MapGet("/api/v1/attachments/{attachment_id}/processing",async(string attachment_id,HttpContext ctx,
SessionService sessions,AppDatabase db,Npgsql.NpgsqlDataSource source)=> {
var(actor,_)=await sessions.AuthenticateAsync(ctx); if(actor is null) return Unauthorized(ctx);
if(!Guid.TryParse(attachment_id,out var id)) return ApiError(ctx,400,"invalid_request","Некорректный ID");
if(await db.FindAttachmentAsync(id,actor.Id) is null) return ApiError(ctx,404,"not_found","Вложение не найдено");
await using var cmd=source.CreateCommand("""
SELECT j.state,j.attempts,j.error_code,j.created_at,j.completed_at,
e.event,e.attempt,e.created_at
FROM attachment_jobs j LEFT JOIN attachment_job_events e ON e.job_id=j.id
WHERE j.attachment_id=@id ORDER BY e.id
""");
cmd.Parameters.AddWithValue("id",id);
await using var reader=await cmd.ExecuteReaderAsync(ctx.RequestAborted);
string? state=null,error=null;int attempts=0;DateTime? created=null,completed=null;
var events=new List<object>();
while(await reader.ReadAsync(ctx.RequestAborted)) {
state=reader.GetString(0);attempts=reader.GetInt32(1);
error=reader.IsDBNull(2)?null:reader.GetString(2);
created=reader.GetDateTime(3);completed=reader.IsDBNull(4)?null:reader.GetDateTime(4);
if(!reader.IsDBNull(5)) events.Add(new {name=reader.GetString(5),attempt=reader.GetInt32(6),at=reader.GetDateTime(7)});
}
ctx.Response.Headers.CacheControl="no-store";
return Results.Ok(new {state,attempts,error_code=error,created_at=created,completed_at=completed,events});
});
app.MapGet("/api/v1/attachments/{attachment_id}/content",async(string attachment_id,HttpContext ctx,
SessionService sessions,AppDatabase db,S3Storage storage)=> {
var(actor,_)=await sessions.AuthenticateAsync(ctx); if(actor is null) return Unauthorized(ctx);