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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user