mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Removes track path editing from the music track update flow
Stops Track.UpdateDetails and Artist.UpdateTrackInAlbum from assigning a path, so a track path can be set only when the track is created. Removes Path from UpdateTrackRequest, UpdateTrackCommand, UpdateTrackCommandValidator and UpdateMusicTrackRequest, and removes the path containment check and IPathService dependency from UpdateTrackCommandHandler. The path stays visible in TrackResponse, MusicTrackDto and the read-only field of the track page. Updates the endpoint summary, request and API docs, and the affected tests.
This commit is contained in:
1 parent
728a879bb8
commit
1aa427b1e2
29 files changed
+47
-243
No files matched your search
-1
@@ -158,7 +158,6 @@ public static class UpdateArtistCommandMapping
|
||||
Result<Updated> updateTrackResult = artist.UpdateTrackInAlbum(
|
||||
existingAlbum,
|
||||
existingTrack,
|
||||
domainTrack.Path,
|
||||
domainTrack.Metadata,
|
||||
domainTrack.Disambiguation,
|
||||
domainTrack.TrackNumber,
|
||||
|
||||
-1
@@ -111,7 +111,6 @@ public static class AudioMetadataDtoMapping
|
||||
return artist.UpdateTrackInAlbum(
|
||||
album,
|
||||
track,
|
||||
track.Path,
|
||||
metadataResult.Value,
|
||||
disambiguation,
|
||||
track.TrackNumber,
|
||||
|
||||
-1
@@ -85,7 +85,6 @@ public static class UpdateTrackCommandMapping
|
||||
Result<Updated> updateResult = artist.UpdateTrackInAlbum(
|
||||
album,
|
||||
track,
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
Optional<string>.FromNullable(metadata.Disambiguation),
|
||||
command.TrackNumber!.Value,
|
||||
|
||||
-1
@@ -26,7 +26,6 @@ public static class UpdateTrackRequestMapping
|
||||
artistId,
|
||||
albumId,
|
||||
trackId,
|
||||
request.Path,
|
||||
request.Metadata,
|
||||
request.TrackNumber,
|
||||
request.DiscNumber,
|
||||
|
||||
-2
@@ -19,7 +19,6 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
||||
/// <param name="ArtistId">The unique identifier of the artist this track belongs to, taken from the route.</param>
|
||||
/// <param name="AlbumId">The unique identifier of the album this track belongs to, taken from the route.</param>
|
||||
/// <param name="TrackId">The unique identifier of the track, taken from the route.</param>
|
||||
/// <param name="Path">The file system path of the track.</param>
|
||||
/// <param name="Metadata">The audio metadata of the track.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to, if applicable.</param>
|
||||
@@ -39,7 +38,6 @@ public record UpdateTrackCommand(
|
||||
string? ArtistId,
|
||||
string? AlbumId,
|
||||
string? TrackId,
|
||||
string? Path,
|
||||
MusicTrackMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
|
||||
+1
-21
@@ -26,7 +26,6 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIden
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
@@ -48,7 +47,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<UpdateTrackCommand> _validator;
|
||||
private readonly IPathService _pathService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateTrackCommandHandler"/> class.
|
||||
@@ -57,14 +55,12 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
/// <param name="pathService">Injected service for file system path related functionality.</param>
|
||||
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator, IPathService pathService)
|
||||
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
_pathService = pathService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,11 +123,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
if (getLibraryResult.Value is null)
|
||||
return Errors.Library.LibraryNotFound;
|
||||
|
||||
// A track is only readable if it is stored inside one of the content locations of its library, so a client can never edit an entry
|
||||
// that points the reading pipeline at an arbitrary file of the host.
|
||||
if (!AreTrackPathsWithinLibraryContentLocations(getLibraryResult.Value, command))
|
||||
return Errors.Music.TrackPathMustBeWithinLibraryContentLocations;
|
||||
|
||||
// Media contributors are referenced by Id and are never created implicitly by editing a track, so each one must already exist.
|
||||
Result<IReadOnlyList<MediaContributorEntity>> getContributorsResult = await GetExistingContributorsAsync(command, cancellationToken).ConfigureAwait(false);
|
||||
if (getContributorsResult.IsFailure)
|
||||
@@ -164,17 +155,6 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
return getPersistedTrackResult.Value.ToResponse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the track path referenced by <paramref name="command"/> is stored inside one of the content locations of <paramref name="library"/>.
|
||||
/// </summary>
|
||||
/// <param name="library">The media library that owns the track.</param>
|
||||
/// <param name="command">The command carrying the referenced track.</param>
|
||||
/// <returns><see langword="true"/> when the referenced track path is within a content location of the library; otherwise, <see langword="false"/>.</returns>
|
||||
private bool AreTrackPathsWithinLibraryContentLocations(LibraryEntity library, UpdateTrackCommand command)
|
||||
{
|
||||
return library.ContentLocations.Any(contentLocation => _pathService.IsPathWithin(command.Path!, contentLocation.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media contributors referenced by <paramref name="command"/>, requiring each referenced Id to already exist.
|
||||
/// </summary>
|
||||
|
||||
-6
@@ -57,12 +57,6 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(command => command.TrackId is not null && command.TrackId.Length > 0)
|
||||
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.Path)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.TrackPathCannotBeEmpty)
|
||||
.MaximumLength(2048)
|
||||
.WithError(Errors.Music.TrackPathMustBeMaximum2048CharactersLong);
|
||||
|
||||
// Validates the audio metadata of the track: title, lengths, release information, languages, genres and tags.
|
||||
RuleFor(command => command.Metadata)
|
||||
.NotNull()
|
||||
|
||||
-2
@@ -14,7 +14,6 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
|
||||
/// <summary>
|
||||
/// Represents a request to update an existing track.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file system path of the track. Required.</param>
|
||||
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
||||
@@ -30,7 +29,6 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
|
||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record UpdateTrackRequest(
|
||||
string? Path,
|
||||
MusicTrackMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
|
||||
+2
-4
@@ -638,11 +638,11 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <remarks>
|
||||
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is mutated through its owning artist,
|
||||
/// which is the consistency boundary. Book is itself an aggregate root, so its update flow reconstitutes it directly
|
||||
/// with its own Create method instead. This difference is intentional.
|
||||
/// with its own Create method instead. This difference is intentional. The file system path of the track is never updated
|
||||
/// here: a track path is set only when the track is created by the scanner.
|
||||
/// </remarks>
|
||||
/// <param name="album">The album the track belongs to.</param>
|
||||
/// <param name="track">The track to update.</param>
|
||||
/// <param name="path">The file system path of the track.</param>
|
||||
/// <param name="metadata">The audio metadata of the track.</param>
|
||||
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||
@@ -662,7 +662,6 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
public Result<Updated> UpdateTrackInAlbum(
|
||||
Album album,
|
||||
Track track,
|
||||
string path,
|
||||
AudioMetadata metadata,
|
||||
Optional<string> disambiguation,
|
||||
int trackNumber,
|
||||
@@ -686,7 +685,6 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
track.UpdateDetails(
|
||||
path,
|
||||
metadata,
|
||||
disambiguation,
|
||||
trackNumber,
|
||||
|
||||
+5
-4
@@ -343,9 +343,12 @@ public sealed class Track : Entity<TrackId>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
|
||||
/// Updates the details of the track, without touching the file system path, the moods, the ISRCs, the media contributors, and the ratings.
|
||||
/// </summary>
|
||||
/// <param name="path">The file system path of the track.</param>
|
||||
/// <remarks>
|
||||
/// The file system path is intentionally not editable here: it is set only when the track is created by the scanner, so that a client
|
||||
/// can never point an existing track at an arbitrary file of the host.
|
||||
/// </remarks>
|
||||
/// <param name="metadata">The audio metadata of the track.</param>
|
||||
/// <param name="disambiguation">The optional disambiguation comment of the track.</param>
|
||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||
@@ -359,7 +362,6 @@ public sealed class Track : Entity<TrackId>
|
||||
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
internal Result<Updated> UpdateDetails(
|
||||
string path,
|
||||
AudioMetadata metadata,
|
||||
Optional<string> disambiguation,
|
||||
int trackNumber,
|
||||
@@ -372,7 +374,6 @@ public sealed class Track : Entity<TrackId>
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||
Optional<MusicBrainzId> musicBrainzTrackId)
|
||||
{
|
||||
Path = path;
|
||||
Metadata = metadata;
|
||||
Disambiguation = disambiguation;
|
||||
TrackNumber = trackNumber;
|
||||
|
||||
+2
-7
@@ -31,7 +31,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
Description = "Updates the details of the track identified by the route, returning the full details of the updated track. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
|
||||
|
||||
ExampleRequest = new UpdateTrackRequest(
|
||||
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
Metadata: new MusicTrackMetadataDto(
|
||||
Title: "Bohemian Rhapsody",
|
||||
OriginalTitle: "Bohemian Rhapsody",
|
||||
@@ -124,7 +123,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
DiscNumber: 1
|
||||
);
|
||||
|
||||
RequestParam(r => r.Path, "The file system path of the track. Required.");
|
||||
RequestParam(r => r.Metadata, "The audio metadata of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.Title, "The title of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the track. Optional.");
|
||||
@@ -397,7 +395,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the new file system path already belongs to another track in the library, or because a unique constraint was violated.", "application/problem+json",
|
||||
Response(409, "The request failed because a unique constraint was violated.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
@@ -426,8 +424,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty",
|
||||
"TrackPathCannotBeEmpty",
|
||||
"TrackPathMustBeMaximum2048CharactersLong",
|
||||
"MetadataCannotBeNull",
|
||||
"TitleCannotBeEmpty",
|
||||
"TitleMustBeMaximum255CharactersLong",
|
||||
@@ -468,8 +464,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
"RatingValueMustBePositive",
|
||||
"RatingValueCannotBeGreaterThanMaxValue",
|
||||
"RatingMaxValueMustBePositive",
|
||||
"RatingVoteCountMustBePositive",
|
||||
"TrackPathMustBeWithinLibraryContentLocations"
|
||||
"RatingVoteCountMustBePositive"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
-2
@@ -14,7 +14,6 @@ namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibr
|
||||
/// <summary>
|
||||
/// Represents a request to update an existing track of an album of a music artist.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file system path of the track. Required.</param>
|
||||
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
||||
@@ -30,7 +29,6 @@ namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibr
|
||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||
[DebuggerDisplay("Title: {Metadata?.Title}")]
|
||||
public record UpdateMusicTrackRequest(
|
||||
string? Path,
|
||||
MusicTrackMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
|
||||
+4
-4
@@ -95,10 +95,10 @@
|
||||
<div class="book-details-form">
|
||||
<!-- General information. -->
|
||||
<h3 class="text-light-two">@_localizer["GeneralInformation"]</h3>
|
||||
<!-- Path. -->
|
||||
<!-- Path (read-only: a track path is set only by the scanner, it can never be edited). -->
|
||||
<div class="form-row">
|
||||
<div class="form-label"><label for="track-path">@_localizer["TrackPath"]</label>:</div>
|
||||
<div class="form-field"><input id="track-path" type="text" class="enlightenment-input" value="@(Model.Path ?? string.Empty)" /></div>
|
||||
<div class="form-label">@_localizer["TrackPath"]:</div>
|
||||
<div class="form-field"><span id="track-path" style="word-break: break-all;">@(Model.Path ?? string.Empty)</span></div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["TrackPathDescription"]</small>
|
||||
</div>
|
||||
<!-- Title. -->
|
||||
@@ -793,9 +793,9 @@
|
||||
}
|
||||
|
||||
// Builds the payload of the edited track, matching the update request of the API.
|
||||
// The file system path is not included: a track path is set only by the scanner and can never be edited.
|
||||
function buildPayload() {
|
||||
return {
|
||||
Path: readValue('track-path') || null,
|
||||
Metadata: {
|
||||
Title: readValue('track-title'),
|
||||
OriginalTitle: readValue('track-original-title') || null,
|
||||
|
||||
Reference in new issue
Block a user