feat: integration cloudfile
This commit is contained in:
@@ -1,16 +1,36 @@
|
||||
using System.Text;
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using mws.backend.dotnet.application.Common;
|
||||
using mws.backend.dotnet.domain.Documents;
|
||||
|
||||
namespace mws.backend.dotnet.application.Documents;
|
||||
|
||||
public record GetDocumentQuery(Guid UserId, Guid DocumentId) : IRequest<DocumentDto>;
|
||||
|
||||
public class GetDocumentHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<GetDocumentQuery, DocumentDto>
|
||||
public class GetDocumentHandler(IUnitOfWork uow, IMapper mapper, IDocumentContentStore contentStore)
|
||||
: IRequestHandler<GetDocumentQuery, DocumentDto>
|
||||
{
|
||||
public async Task<DocumentDto> Handle(GetDocumentQuery query, CancellationToken ct)
|
||||
{
|
||||
var doc = await DocumentAccess.GetDocumentForUserAsync(uow, query.UserId, query.DocumentId, ct);
|
||||
return mapper.Map<DocumentDto>(doc);
|
||||
var dto = mapper.Map<DocumentDto>(doc);
|
||||
|
||||
if (doc.Type == DocumentType.Document)
|
||||
{
|
||||
await using var stream = await contentStore.DownloadAsync(doc.ProjectId, doc.Id, ct);
|
||||
if (stream != Stream.Null)
|
||||
{
|
||||
using var reader = new StreamReader(stream, Encoding.UTF8);
|
||||
var content = await reader.ReadToEndAsync(ct);
|
||||
dto.Content = string.IsNullOrEmpty(content) ? null : content;
|
||||
}
|
||||
else
|
||||
{
|
||||
dto.Content = null;
|
||||
}
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user