Files
Ping/backend/Core/Ping.Application/Attachments/RequestAttachmentUploadUrl.cs
T
Admin 0623875dfa Add Ping backend
.NET 10 solution for Ping, a Discord style chat app: Domain, Application
and Infrastructure projects plus the Api host. SignalR for chat and
presence, LiveKit for call tokens, EF Core on Postgres, S3 compatible
storage for attachments, and OIDC auth shared with the Musify Zitadel
instance. Includes the Compose stack for local development.
2026-09-21 19:32:55 +02:00

28 lines
1.2 KiB
C#

using Mediator;
using Ping.Application.Attachments.Responses;
using Ping.Application.Configuration;
using Ping.Application.Contracts;
namespace Ping.Application.Attachments
{
public record RequestAttachmentUploadUrlCommand(long RequesterId, string FileName, string ContentType)
: ICommand<AttachmentUploadResponse>;
public class RequestAttachmentUploadUrlCommandHandler(IStorageService storageService, ApplicationStorageConfiguration storageConfiguration)
: ICommandHandler<RequestAttachmentUploadUrlCommand, AttachmentUploadResponse>
{
private static readonly TimeSpan UploadUrlExpiration = TimeSpan.FromMinutes(10);
public async ValueTask<AttachmentUploadResponse> Handle(RequestAttachmentUploadUrlCommand request, CancellationToken cancellationToken)
{
var key = $"attachments/{request.RequesterId}/{Guid.NewGuid()}/{request.FileName}";
var expiresAt = DateTime.UtcNow + UploadUrlExpiration;
var uploadUrl = await storageService.GetUploadUrlAsync(
storageConfiguration.Bucket, key, request.ContentType, UploadUrlExpiration, cancellationToken);
return new AttachmentUploadResponse(uploadUrl, storageConfiguration.Bucket, key, expiresAt);
}
}
}