Adds multiple media urls for content
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Hutopy.Application.Users.Commands;
|
||||
/// </summary>
|
||||
public class UploadBannerPictureCommand : IRequest<IResult>
|
||||
{
|
||||
public required Stream BannerPicture { get; init; }
|
||||
public required MemoryStream BannerPicture { get; init; }
|
||||
public string BannerPictureUrl { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,12 @@ public class UploadBannerPictureCommandHandler(IHttpContextAccessor contextAcces
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.BannerPicture}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.BannerPicture, contentType);
|
||||
var url = await azureBlobStorageService.UploadFileAsync(
|
||||
ContainerNames.Users,
|
||||
blobName,
|
||||
request.BannerPicture,
|
||||
contentType,
|
||||
cancellationToken);
|
||||
|
||||
await identityService.UpdateCurrentUserBannerPictureUrlAsync(url);
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace Hutopy.Application.Users.Commands;
|
||||
/// </summary>
|
||||
public class UploadProfilePictureCommand : IRequest<IResult>
|
||||
{
|
||||
public required Stream ProfilePicture { get; init; }
|
||||
public required MemoryStream ProfilePicture { get; init; }
|
||||
public string ProfilePictureUrl { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public class UploadProfilePictureCommandHandler(IHttpContextAccessor contextAccessor, IIdentityService identityService, IAzureBlobStorageService azureBlobStorageService) : IRequestHandler<UploadProfilePictureCommand, IResult>
|
||||
{
|
||||
public async Task<IResult> Handle(UploadProfilePictureCommand request, CancellationToken cancellationToken)
|
||||
public async Task<IResult> Handle(UploadProfilePictureCommand request, CancellationToken ct)
|
||||
{
|
||||
// If an url to the picture is provided, use it right away and don't upload anything.
|
||||
if (!string.IsNullOrEmpty(request.ProfilePictureUrl))
|
||||
@@ -32,7 +32,12 @@ public class UploadProfilePictureCommandHandler(IHttpContextAccessor contextAcce
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.ProfilePicture, contentType);
|
||||
var url = await azureBlobStorageService.UploadFileAsync(
|
||||
ContainerNames.Users,
|
||||
blobName,
|
||||
request.ProfilePicture,
|
||||
contentType,
|
||||
ct);
|
||||
|
||||
await identityService.UpdateCurrentUserProfilePictureUrlAsync(url);
|
||||
|
||||
|
||||
@@ -10,14 +10,17 @@ namespace Hutopy.Application.Users.Commands;
|
||||
/// </summary>
|
||||
public class UploadWebsiteIconCommand : IRequest<IResult>
|
||||
{
|
||||
public required Stream WebsiteIcon { get; init; }
|
||||
|
||||
public required MemoryStream WebsiteIcon { get; init; }
|
||||
|
||||
public string WebsitePictureUrl { get; init; } = string.Empty;
|
||||
}
|
||||
|
||||
public class UploadWebsiteIconCommandHandler(IHttpContextAccessor contextAccessor, IIdentityService identityService, IAzureBlobStorageService azureBlobStorageService) : IRequestHandler<UploadWebsiteIconCommand, IResult>
|
||||
public class UploadWebsiteIconCommandHandler(
|
||||
IHttpContextAccessor contextAccessor,
|
||||
IIdentityService identityService,
|
||||
IAzureBlobStorageService azureBlobStorageService) : IRequestHandler<UploadWebsiteIconCommand, IResult>
|
||||
{
|
||||
public async Task<IResult> Handle(UploadWebsiteIconCommand request, CancellationToken cancellationToken)
|
||||
public async Task<IResult> Handle(UploadWebsiteIconCommand request, CancellationToken ct)
|
||||
{
|
||||
// If an url to the picture is provided, use it right away and don't upload anything.
|
||||
if (!string.IsNullOrEmpty(request.WebsitePictureUrl))
|
||||
@@ -25,19 +28,23 @@ public class UploadWebsiteIconCommandHandler(IHttpContextAccessor contextAccesso
|
||||
await identityService.UpdateCurrentUserWebsiteIconUrlAsync(request.WebsitePictureUrl);
|
||||
return Results.Ok(request.WebsitePictureUrl);
|
||||
}
|
||||
|
||||
|
||||
var contentType = contextAccessor.EnsureContentType();
|
||||
|
||||
|
||||
var identityUser = await identityService.GetCurrentUserAsync();
|
||||
var currentUserId = new Guid(identityUser?.Id ?? "").ToString();
|
||||
|
||||
|
||||
var blobName = $"{currentUserId}/{SubDirectoryNames.Profile}/{CommonFileNames.WebsiteIcon}";
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(ContainerNames.Users, blobName, request.WebsiteIcon, contentType);
|
||||
|
||||
var url = await azureBlobStorageService.UploadFileAsync(
|
||||
ContainerNames.Users,
|
||||
blobName,
|
||||
request.WebsiteIcon,
|
||||
contentType,
|
||||
ct);
|
||||
|
||||
await identityService.UpdateCurrentUserWebsiteIconUrlAsync(url);
|
||||
|
||||
|
||||
return Results.Ok(request.WebsitePictureUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user