Adds ChangeBanner for Creators
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
public interface IAzureBlobStorageService
|
||||
public interface IBlobStorage
|
||||
{
|
||||
Task<string> UploadFileAsync(string containerName, string blobName, Stream stream, string contentType,
|
||||
CancellationToken ct = default);
|
||||
@@ -1,6 +1,5 @@
|
||||
using Hutopy.Application.AzureBlobStorage.Constants;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Utils;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hutopy.Application.Users.Commands;
|
||||
@@ -16,19 +15,17 @@ public class UploadProfilePictureCommand : IRequest<IResult>
|
||||
public class UploadProfilePictureCommandHandler(
|
||||
IHttpContextAccessor contextAccessor,
|
||||
IIdentityService identityService,
|
||||
IAzureBlobStorageService azureBlobStorageService) : IRequestHandler<UploadProfilePictureCommand, IResult>
|
||||
IBlobStorage blobStorage) : IRequestHandler<UploadProfilePictureCommand, IResult>
|
||||
{
|
||||
public async Task<IResult> Handle(UploadProfilePictureCommand request, CancellationToken ct)
|
||||
{
|
||||
var contentType = contextAccessor.EnsureContentType();
|
||||
|
||||
var identityUser = await identityService.GetCurrentUserAsync();
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(
|
||||
var url = await blobStorage.UploadFileAsync(
|
||||
ContainerNames.Users,
|
||||
$"{identityUser.Id}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}",
|
||||
request.File.OpenReadStream(),
|
||||
contentType,
|
||||
request.File.ContentType,
|
||||
ct);
|
||||
|
||||
await identityService.UpdateCurrentUserPortraitUrlAsync(url);
|
||||
|
||||
@@ -7,7 +7,7 @@ public record GetCurrentUserProfilePictureQuery : IRequest<Stream>;
|
||||
|
||||
public class GetCurrentUserProfilePictureQueryHandler(
|
||||
IIdentityService identityService,
|
||||
IAzureBlobStorageService azureBlobStorageService
|
||||
IBlobStorage blobStorage
|
||||
)
|
||||
: IRequestHandler<GetCurrentUserProfilePictureQuery, Stream>
|
||||
{
|
||||
@@ -15,7 +15,7 @@ public class GetCurrentUserProfilePictureQueryHandler(
|
||||
{
|
||||
var identityUser = await identityService.GetCurrentUserAsync();
|
||||
|
||||
return await azureBlobStorageService.DownloadFileAsync(
|
||||
return await blobStorage.DownloadFileAsync(
|
||||
ContainerNames.Users,
|
||||
$"{identityUser.Id.ToString()}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}",
|
||||
cancellationToken);
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Hutopy.Application.Utils;
|
||||
|
||||
public static class HttpContextAccessorExtensions
|
||||
{
|
||||
public static HttpContext EnsureHttpContext(this IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
if (httpContextAccessor.HttpContext == null)
|
||||
{
|
||||
throw new InvalidOperationException("HttpContext is null.");
|
||||
}
|
||||
|
||||
return httpContextAccessor.HttpContext;
|
||||
}
|
||||
|
||||
public static string EnsureContentType(this IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
var httpContext = EnsureHttpContext(httpContextAccessor);
|
||||
var contentType = httpContext.Request.ContentType;
|
||||
|
||||
if (string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
throw new InvalidOperationException("Content-Type header is missing.");
|
||||
}
|
||||
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user