You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.3 KiB
99 lines
3.3 KiB
7 years ago
|
using System.Collections.Generic;
|
||
7 years ago
|
using System.Linq;
|
||
3 years ago
|
using Lidarr.Http;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
7 years ago
|
using NzbDrone.Common.Extensions;
|
||
7 years ago
|
using NzbDrone.Core.Messaging.Commands;
|
||
7 years ago
|
using NzbDrone.Core.Music;
|
||
7 years ago
|
using NzbDrone.Core.Music.Commands;
|
||
7 years ago
|
|
||
7 years ago
|
namespace Lidarr.Api.V1.Artist
|
||
7 years ago
|
{
|
||
3 years ago
|
[V1ApiController("artist/editor")]
|
||
|
public class ArtistEditorController : Controller
|
||
7 years ago
|
{
|
||
|
private readonly IArtistService _artistService;
|
||
7 years ago
|
private readonly IManageCommandQueue _commandQueueManager;
|
||
7 years ago
|
|
||
3 years ago
|
public ArtistEditorController(IArtistService artistService, IManageCommandQueue commandQueueManager)
|
||
7 years ago
|
{
|
||
|
_artistService = artistService;
|
||
7 years ago
|
_commandQueueManager = commandQueueManager;
|
||
7 years ago
|
}
|
||
|
|
||
3 years ago
|
[HttpPut]
|
||
|
public IActionResult SaveAll([FromBody] ArtistEditorResource resource)
|
||
7 years ago
|
{
|
||
|
var artistToUpdate = _artistService.GetArtists(resource.ArtistIds);
|
||
7 years ago
|
var artistToMove = new List<BulkMoveArtist>();
|
||
7 years ago
|
|
||
|
foreach (var artist in artistToUpdate)
|
||
|
{
|
||
|
if (resource.Monitored.HasValue)
|
||
|
{
|
||
|
artist.Monitored = resource.Monitored.Value;
|
||
|
}
|
||
|
|
||
|
if (resource.QualityProfileId.HasValue)
|
||
|
{
|
||
6 years ago
|
artist.QualityProfileId = resource.QualityProfileId.Value;
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
if (resource.MetadataProfileId.HasValue)
|
||
|
{
|
||
|
artist.MetadataProfileId = resource.MetadataProfileId.Value;
|
||
|
}
|
||
|
|
||
7 years ago
|
if (resource.RootFolderPath.IsNotNullOrWhiteSpace())
|
||
|
{
|
||
|
artist.RootFolderPath = resource.RootFolderPath;
|
||
7 years ago
|
artistToMove.Add(new BulkMoveArtist
|
||
|
{
|
||
|
ArtistId = artist.Id,
|
||
|
SourcePath = artist.Path
|
||
|
});
|
||
7 years ago
|
}
|
||
|
|
||
|
if (resource.Tags != null)
|
||
|
{
|
||
|
var newTags = resource.Tags;
|
||
|
var applyTags = resource.ApplyTags;
|
||
|
|
||
|
switch (applyTags)
|
||
|
{
|
||
|
case ApplyTags.Add:
|
||
|
newTags.ForEach(t => artist.Tags.Add(t));
|
||
|
break;
|
||
|
case ApplyTags.Remove:
|
||
|
newTags.ForEach(t => artist.Tags.Remove(t));
|
||
|
break;
|
||
|
case ApplyTags.Replace:
|
||
|
artist.Tags = new HashSet<int>(newTags);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
if (artistToMove.Any())
|
||
7 years ago
|
{
|
||
|
_commandQueueManager.Push(new BulkMoveArtistCommand
|
||
|
{
|
||
|
DestinationRootFolder = resource.RootFolderPath,
|
||
5 years ago
|
Artist = artistToMove,
|
||
|
MoveFiles = resource.MoveFiles
|
||
7 years ago
|
});
|
||
|
}
|
||
|
|
||
3 years ago
|
return Accepted(_artistService.UpdateArtists(artistToUpdate, !resource.MoveFiles).ToResource());
|
||
7 years ago
|
}
|
||
|
|
||
3 years ago
|
[HttpDelete]
|
||
|
public object DeleteArtist([FromBody] ArtistEditorResource resource)
|
||
7 years ago
|
{
|
||
4 years ago
|
_artistService.DeleteArtists(resource.ArtistIds, resource.DeleteFiles);
|
||
7 years ago
|
|
||
5 years ago
|
return new object();
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|