39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
using Hutopy.Infrastructure.BlobStorage.Contracts;
|
|
using Hutopy.Modules.Identity.Data;
|
|
using Hutopy.Modules.Identity.Models;
|
|
|
|
namespace Hutopy.Modules.Identity.Handlers;
|
|
|
|
[PublicAPI]
|
|
public class GetCurrentUserPortraitHandler(
|
|
IdentityService identityService,
|
|
IBlobStorage blobStorage
|
|
)
|
|
: EndpointWithoutRequest<Stream>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/users/portrait");
|
|
Options(o => o.WithTags("Users"));
|
|
}
|
|
|
|
public override async Task HandleAsync(
|
|
CancellationToken cancellationToken)
|
|
{
|
|
UserModel? identityUser = await identityService.GetCurrentUserAsync();
|
|
|
|
if (identityUser is null)
|
|
{
|
|
await SendNotFoundAsync(cancellationToken);
|
|
return;
|
|
}
|
|
|
|
MemoryStream stream = await blobStorage.DownloadFileAsync(
|
|
ContainerNames.Users,
|
|
$"{identityUser.Id.ToString()}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}",
|
|
cancellationToken);
|
|
|
|
await SendOkAsync(stream, cancellationToken);
|
|
}
|
|
}
|