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.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Ping.Application.Attachments.Responses
|
||||
{
|
||||
public record AttachmentUploadResponse(string UploadUrl, string Bucket, string Key, DateTime ExpiresAt);
|
||||
}
|
||||
Reference in New Issue
Block a user