Add track publication, album types, optional track pictures and batch upload URLs
Tracks
- Track.IsPublished (migration marks existing tracks as published). New
tracks are created unpublished.
- PUT /tracks/{id}/published and PUT /tracks/published change the flag;
publishing requires completed audio processing (the batch endpoint
reports skipped tracks).
- An unpublished track is only visible to its owner. A WherePublished /
VisibleTo filter is applied to search, genres, listening history, last
listened, likes, mixes, album and playlist contents and counts, recently
listened albums, public user tracks, track details and stream tickets.
- isPublished is part of the track responses, GET /tracks/users/{userId}
accepts a published filter and status-counts reports published and
unpublished totals.
- CreateTrackRequest.pictureIntentId is optional: without it the track
uses the album cover or the preset picture and no picture processing
runs. CreateTrackResourcesEvent carries nullable picture fields, so
queues must be drained before deploying.
- POST /tracks/upload-urls accepts an audios list and one optional picture
shared by all of them, and returns an intent per file. The upload intent
limits are raised so a batch fits.
Albums
- AlbumType (Album, EP, Single) on create, update and responses.
- CreateAlbumRequest.trackIds creates the album and links the tracks in a
single save.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using Musify.Domain.ValueObjects;
|
||||
|
||||
namespace Musify.Api.DataTransferObjects.Albums
|
||||
{
|
||||
public record CreateAlbumRequest(
|
||||
string Title,
|
||||
string? Description,
|
||||
int? ReleaseYear,
|
||||
Guid PictureIntentId);
|
||||
Guid PictureIntentId,
|
||||
AlbumType Type = AlbumType.Album,
|
||||
IReadOnlyList<Guid>? TrackIds = null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using Musify.Domain.ValueObjects;
|
||||
|
||||
namespace Musify.Api.DataTransferObjects.Albums
|
||||
{
|
||||
public record UpdateAlbumRequest(
|
||||
string Title,
|
||||
string? Description,
|
||||
int? ReleaseYear);
|
||||
int? ReleaseYear,
|
||||
AlbumType? Type = null);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Musify.Api.DataTransferObjects.Tracks
|
||||
{
|
||||
public record CreateTrackRequest(
|
||||
string Title,
|
||||
Guid PictureIntentId,
|
||||
Guid? PictureIntentId,
|
||||
Guid AudioIntentId,
|
||||
IReadOnlyCollection<Genre> Tags,
|
||||
bool IsExplicit = false);
|
||||
|
||||
+11
-5
@@ -1,10 +1,16 @@
|
||||
namespace Musify.Api.DataTransferObjects.Tracks
|
||||
{
|
||||
public record AudioUploadRequest(
|
||||
string FileType,
|
||||
string ContentType,
|
||||
long? ExpectedSizeBytes = null);
|
||||
|
||||
public record RequestTrackUploadUrlsRequest(
|
||||
string PictureFileType,
|
||||
string PictureContentType,
|
||||
string AudioFileType,
|
||||
string AudioContentType,
|
||||
string? PictureFileType = null,
|
||||
string? PictureContentType = null,
|
||||
string? AudioFileType = null,
|
||||
string? AudioContentType = null,
|
||||
long? ExpectedPictureSizeBytes = null,
|
||||
long? ExpectedAudioSizeBytes = null);
|
||||
long? ExpectedAudioSizeBytes = null,
|
||||
IReadOnlyList<AudioUploadRequest>? Audios = null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Musify.Api.DataTransferObjects.Tracks
|
||||
{
|
||||
public record SetTrackPublishedRequest(bool IsPublished);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace Musify.Api.DataTransferObjects.Tracks
|
||||
{
|
||||
public record SetTracksPublishedRequest(IReadOnlyList<Guid> TrackIds, bool IsPublished);
|
||||
}
|
||||
@@ -84,12 +84,13 @@ namespace Musify.Api.Endpoints
|
||||
|
||||
group.MapPost("/", CreateAlbum)
|
||||
.WithName("CreateAlbum")
|
||||
.WithSummary("Create a new album")
|
||||
.WithSummary("Create a new album, optionally with some of your tracks already in it")
|
||||
.AddEndpointFilter<ValidationFilter<CreateAlbumRequest>>()
|
||||
.RequireAuthorization()
|
||||
.Produces<AlbumApplicationResponse>(StatusCodes.Status201Created)
|
||||
.ProducesValidationProblem()
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.Produces(StatusCodes.Status403Forbidden)
|
||||
.Produces(StatusCodes.Status404NotFound);
|
||||
|
||||
group.MapPut("/{id:guid}", UpdateAlbum)
|
||||
@@ -245,7 +246,8 @@ namespace Musify.Api.Endpoints
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await mediator.Send(
|
||||
new CreateAlbumCommand(currentUser.RequiredId, request.Title, request.Description, request.ReleaseYear, request.PictureIntentId),
|
||||
new CreateAlbumCommand(
|
||||
currentUser.RequiredId, request.Title, request.Description, request.ReleaseYear, request.PictureIntentId, request.Type, request.TrackIds),
|
||||
cancellationToken);
|
||||
|
||||
return result.ToCreatedResult(album => $"/albums/{album.Id}");
|
||||
@@ -259,7 +261,7 @@ namespace Musify.Api.Endpoints
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await mediator.Send(
|
||||
new UpdateAlbumCommand(currentUser.RequiredId, id, request.Title, request.Description, request.ReleaseYear),
|
||||
new UpdateAlbumCommand(currentUser.RequiredId, id, request.Title, request.Description, request.ReleaseYear, request.Type),
|
||||
cancellationToken);
|
||||
|
||||
return result.ToHttpResult();
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Musify.Api.Endpoints
|
||||
group.MapGet("/users/{userId:long}", GetTracksByUserId)
|
||||
.AddEndpointFilter<ValidationFilter<PageQuery>>()
|
||||
.WithName("GetTracksByUserId")
|
||||
.WithSummary("Get paginated tracks for a user, optionally filtered by name and audio processing status. Each track lists the albums it belongs to")
|
||||
.WithSummary("Get paginated tracks for a user, optionally filtered by name, audio processing status and published state. Each track lists the albums it belongs to. Only the owner sees unpublished tracks")
|
||||
.Produces<PaginatedResponse<UserTrackApplicationResponse>>();
|
||||
|
||||
group.MapGet("/users/{userId:long}/status-counts", GetTrackStatusCounts)
|
||||
@@ -72,7 +72,7 @@ namespace Musify.Api.Endpoints
|
||||
|
||||
group.MapPost("/", CreateTrack)
|
||||
.WithName("CreateTrack")
|
||||
.WithSummary("Create a new track")
|
||||
.WithSummary("Create a new track, unpublished, from upload intents. The picture is optional")
|
||||
.AddEndpointFilter<ValidationFilter<CreateTrackRequest>>()
|
||||
.RequireAuthorization()
|
||||
.Produces<TrackApplicationResponse>(StatusCodes.Status201Created)
|
||||
@@ -101,9 +101,29 @@ namespace Musify.Api.Endpoints
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.Produces(StatusCodes.Status403Forbidden);
|
||||
|
||||
group.MapPut("/{id:guid}/published", SetTrackPublished)
|
||||
.WithName("SetTrackPublished")
|
||||
.WithSummary("Publish or unpublish one of your tracks. Only tracks with completed audio processing can be published")
|
||||
.RequireAuthorization()
|
||||
.Produces(StatusCodes.Status204NoContent)
|
||||
.ProducesValidationProblem()
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.Produces(StatusCodes.Status403Forbidden)
|
||||
.Produces(StatusCodes.Status404NotFound);
|
||||
|
||||
group.MapPut("/published", SetTracksPublished)
|
||||
.WithName("SetTracksPublished")
|
||||
.WithSummary("Publish or unpublish several of your tracks at once. Missing tracks and tracks that cannot be published yet are returned as skipped")
|
||||
.AddEndpointFilter<ValidationFilter<SetTracksPublishedRequest>>()
|
||||
.RequireAuthorization()
|
||||
.Produces<SetTracksPublishedResponse>()
|
||||
.ProducesValidationProblem()
|
||||
.Produces(StatusCodes.Status401Unauthorized)
|
||||
.Produces(StatusCodes.Status403Forbidden);
|
||||
|
||||
group.MapPost("/upload-urls", RequestTrackUploadUrls)
|
||||
.WithName("RequestTrackUploadUrls")
|
||||
.WithSummary("Request pre-signed URLs to upload track picture and audio")
|
||||
.WithSummary("Request pre-signed URLs to upload the audio of one or many tracks and an optional picture shared by all of them")
|
||||
.AddEndpointFilter<ValidationFilter<RequestTrackUploadUrlsRequest>>()
|
||||
.RequireAuthorization()
|
||||
.Produces<TrackUploadUrlsResponse>()
|
||||
@@ -128,10 +148,11 @@ namespace Musify.Api.Endpoints
|
||||
|
||||
private static async Task<IResult> GetTrackById(
|
||||
IMediator mediator,
|
||||
CurrentUser currentUser,
|
||||
Guid id,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await mediator.Send(new GetTrackByIdQuery(id), cancellationToken);
|
||||
var result = await mediator.Send(new GetTrackByIdQuery(id, currentUser.Id), cancellationToken);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
@@ -171,14 +192,39 @@ namespace Musify.Api.Endpoints
|
||||
|
||||
private static async Task<IResult> GetTracksByUserId(
|
||||
IMediator mediator,
|
||||
CurrentUser currentUser,
|
||||
long userId,
|
||||
string? name,
|
||||
[AsParameters] PageQuery page,
|
||||
CancellationToken cancellationToken,
|
||||
ProcessingStatus[]? status = null)
|
||||
ProcessingStatus[]? status = null,
|
||||
bool? published = null)
|
||||
{
|
||||
var result = await mediator.Send(
|
||||
new GetTracksByUserIdQuery(userId, name, page.PageNumber, page.PageSize, status),
|
||||
new GetTracksByUserIdQuery(userId, name, page.PageNumber, page.PageSize, status, currentUser.Id, published),
|
||||
cancellationToken);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> SetTrackPublished(
|
||||
IMediator mediator,
|
||||
CurrentUser currentUser,
|
||||
Guid id,
|
||||
SetTrackPublishedRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await mediator.Send(new SetTrackPublishedCommand(currentUser.RequiredId, id, request.IsPublished), cancellationToken);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
|
||||
private static async Task<IResult> SetTracksPublished(
|
||||
IMediator mediator,
|
||||
CurrentUser currentUser,
|
||||
SetTracksPublishedRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await mediator.Send(
|
||||
new SetTracksPublishedCommand(currentUser.RequiredId, request.TrackIds, request.IsPublished),
|
||||
cancellationToken);
|
||||
return result.ToHttpResult();
|
||||
}
|
||||
@@ -243,7 +289,8 @@ namespace Musify.Api.Endpoints
|
||||
request.AudioFileType,
|
||||
request.AudioContentType,
|
||||
request.ExpectedPictureSizeBytes,
|
||||
request.ExpectedAudioSizeBytes),
|
||||
request.ExpectedAudioSizeBytes,
|
||||
request.Audios?.Select(audio => new AudioUploadSpec(audio.FileType, audio.ContentType, audio.ExpectedSizeBytes)).ToList()),
|
||||
cancellationToken);
|
||||
|
||||
return result.ToHttpResult();
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace Musify.Api.Validators.Albums
|
||||
{
|
||||
public sealed class CreateAlbumRequestValidator : AbstractValidator<CreateAlbumRequest>
|
||||
{
|
||||
public const int MaxTracksOnCreate = 500;
|
||||
|
||||
public CreateAlbumRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Title)
|
||||
@@ -20,6 +22,18 @@ namespace Musify.Api.Validators.Albums
|
||||
|
||||
RuleFor(x => x.PictureIntentId)
|
||||
.NotEmpty();
|
||||
|
||||
RuleFor(x => x.Type)
|
||||
.IsInEnum();
|
||||
|
||||
RuleFor(x => x.TrackIds)
|
||||
.Must(ids => ids!.Count <= MaxTracksOnCreate)
|
||||
.WithMessage($"At most {MaxTracksOnCreate} tracks can be added at once.")
|
||||
.When(x => x.TrackIds != null);
|
||||
|
||||
RuleForEach(x => x.TrackIds)
|
||||
.NotEmpty()
|
||||
.When(x => x.TrackIds != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ namespace Musify.Api.Validators.Albums
|
||||
RuleFor(x => x.ReleaseYear)
|
||||
.InclusiveBetween(Limits.EarliestReleaseYear, Limits.LatestReleaseYear)
|
||||
.When(x => x.ReleaseYear.HasValue);
|
||||
|
||||
RuleFor(x => x.Type)
|
||||
.IsInEnum()
|
||||
.When(x => x.Type.HasValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace Musify.Api.Validators.Tracks
|
||||
.MaximumLength(Limits.TrackTitle);
|
||||
|
||||
RuleFor(x => x.PictureIntentId)
|
||||
.NotEmpty();
|
||||
.NotEqual(Guid.Empty)
|
||||
.When(x => x.PictureIntentId.HasValue);
|
||||
|
||||
RuleFor(x => x.AudioIntentId)
|
||||
.NotEmpty();
|
||||
|
||||
+40
-12
@@ -6,25 +6,53 @@ namespace Musify.Api.Validators.Tracks
|
||||
{
|
||||
public sealed class RequestTrackUploadUrlsRequestValidator : AbstractValidator<RequestTrackUploadUrlsRequest>
|
||||
{
|
||||
public const int MaxAudiosPerRequest = 20;
|
||||
|
||||
public RequestTrackUploadUrlsRequestValidator(UploadIntentConfiguration uploadConfiguration)
|
||||
{
|
||||
RuleFor(x => x.PictureFileType)
|
||||
.MustBeFileType(Uploads.PictureFileTypes);
|
||||
When(x => x.PictureFileType != null || x.PictureContentType != null, () =>
|
||||
{
|
||||
RuleFor(x => x.PictureFileType!)
|
||||
.MustBeFileType(Uploads.PictureFileTypes);
|
||||
|
||||
RuleFor(x => x.PictureContentType)
|
||||
.MustBeContentType(Uploads.PictureContentTypes);
|
||||
RuleFor(x => x.PictureContentType!)
|
||||
.MustBeContentType(Uploads.PictureContentTypes);
|
||||
|
||||
RuleFor(x => x.AudioFileType)
|
||||
.MustBeFileType(Uploads.AudioFileTypes);
|
||||
RuleFor(x => x.ExpectedPictureSizeBytes)
|
||||
.MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
});
|
||||
|
||||
RuleFor(x => x.AudioContentType)
|
||||
.MustBeContentType(Uploads.AudioContentTypes);
|
||||
When(x => x.Audios is { Count: > 0 }, () =>
|
||||
{
|
||||
RuleFor(x => x.AudioFileType)
|
||||
.Null()
|
||||
.WithMessage("Use either the audio fields or the audios list, not both.");
|
||||
|
||||
RuleFor(x => x.ExpectedPictureSizeBytes)
|
||||
.MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
RuleFor(x => x.AudioContentType)
|
||||
.Null()
|
||||
.WithMessage("Use either the audio fields or the audios list, not both.");
|
||||
|
||||
RuleFor(x => x.ExpectedAudioSizeBytes)
|
||||
.MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
RuleFor(x => x.Audios!)
|
||||
.Must(audios => audios.Count <= MaxAudiosPerRequest)
|
||||
.WithMessage($"At most {MaxAudiosPerRequest} audio files can be requested at once.");
|
||||
|
||||
RuleForEach(x => x.Audios!).ChildRules(audio =>
|
||||
{
|
||||
audio.RuleFor(a => a.FileType).MustBeFileType(Uploads.AudioFileTypes);
|
||||
audio.RuleFor(a => a.ContentType).MustBeContentType(Uploads.AudioContentTypes);
|
||||
audio.RuleFor(a => a.ExpectedSizeBytes).MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
});
|
||||
}).Otherwise(() =>
|
||||
{
|
||||
RuleFor(x => x.AudioFileType!)
|
||||
.MustBeFileType(Uploads.AudioFileTypes);
|
||||
|
||||
RuleFor(x => x.AudioContentType!)
|
||||
.MustBeContentType(Uploads.AudioContentTypes);
|
||||
|
||||
RuleFor(x => x.ExpectedAudioSizeBytes)
|
||||
.MustBeValidUploadSize(uploadConfiguration.MaxUploadBytes);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using FluentValidation;
|
||||
using Musify.Api.DataTransferObjects.Tracks;
|
||||
|
||||
namespace Musify.Api.Validators.Tracks
|
||||
{
|
||||
public sealed class SetTracksPublishedRequestValidator : AbstractValidator<SetTracksPublishedRequest>
|
||||
{
|
||||
public const int MaxTracksPerRequest = 100;
|
||||
|
||||
public SetTracksPublishedRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.TrackIds)
|
||||
.NotEmpty()
|
||||
.Must(ids => ids.Count <= MaxTracksPerRequest)
|
||||
.WithMessage($"At most {MaxTracksPerRequest} tracks can be updated at once.");
|
||||
|
||||
RuleForEach(x => x.TrackIds)
|
||||
.NotEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,8 +118,8 @@
|
||||
},
|
||||
"UploadIntent": {
|
||||
"UploadUrlExpiresInSeconds": 120,
|
||||
"MaxActiveUploadIntentsPerUser": 5,
|
||||
"MaxActiveUploadBytesPerUser": 209715200,
|
||||
"MaxActiveUploadIntentsPerUser": 50,
|
||||
"MaxActiveUploadBytesPerUser": 1073741824,
|
||||
"MaxUploadBytes": 104857600,
|
||||
"DefaultExpectedPictureSizeBytes": 10485760,
|
||||
"DefaultExpectedAudioSizeBytes": 104857600,
|
||||
|
||||
@@ -114,8 +114,8 @@
|
||||
},
|
||||
"UploadIntent": {
|
||||
"UploadUrlExpiresInSeconds": 120,
|
||||
"MaxActiveUploadIntentsPerUser": 5,
|
||||
"MaxActiveUploadBytesPerUser": 209715200,
|
||||
"MaxActiveUploadIntentsPerUser": 50,
|
||||
"MaxActiveUploadBytesPerUser": 1073741824,
|
||||
"MaxUploadBytes": 104857600,
|
||||
"DefaultExpectedPictureSizeBytes": 10485760,
|
||||
"DefaultExpectedAudioSizeBytes": 104857600,
|
||||
|
||||
Reference in New Issue
Block a user