2018-11-23 07:03:32 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using FluentValidation;
|
2021-10-21 20:04:19 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-11-23 07:03:32 +00:00
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
|
|
|
using NzbDrone.Core.Validation.Paths;
|
|
|
|
using Radarr.Http;
|
2021-10-21 20:04:19 +00:00
|
|
|
using Radarr.Http.REST;
|
|
|
|
using Radarr.Http.REST.Attributes;
|
2018-11-23 07:03:32 +00:00
|
|
|
|
2019-12-03 01:36:18 +00:00
|
|
|
namespace Radarr.Api.V3.RemotePathMappings
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
2021-10-21 20:04:19 +00:00
|
|
|
[V3ApiController]
|
|
|
|
public class RemotePathMappingController : RestController<RemotePathMappingResource>
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
private readonly IRemotePathMappingService _remotePathMappingService;
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
public RemotePathMappingController(IRemotePathMappingService remotePathMappingService,
|
2018-11-23 07:03:32 +00:00
|
|
|
PathExistsValidator pathExistsValidator,
|
|
|
|
MappedNetworkDriveValidator mappedNetworkDriveValidator)
|
|
|
|
{
|
|
|
|
_remotePathMappingService = remotePathMappingService;
|
|
|
|
|
|
|
|
SharedValidator.RuleFor(c => c.Host)
|
|
|
|
.NotEmpty();
|
|
|
|
|
|
|
|
// We cannot use IsValidPath here, because it's a remote path, possibly other OS.
|
|
|
|
SharedValidator.RuleFor(c => c.RemotePath)
|
|
|
|
.NotEmpty();
|
|
|
|
|
|
|
|
SharedValidator.RuleFor(c => c.LocalPath)
|
2023-04-01 13:03:53 +00:00
|
|
|
.Cascade(CascadeMode.Stop)
|
|
|
|
.IsValidPath()
|
2018-11-23 07:03:32 +00:00
|
|
|
.SetValidator(mappedNetworkDriveValidator)
|
|
|
|
.SetValidator(pathExistsValidator);
|
|
|
|
}
|
|
|
|
|
2021-10-24 20:35:22 +00:00
|
|
|
protected override RemotePathMappingResource GetResourceById(int id)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
return _remotePathMappingService.Get(id).ToResource();
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
[RestPostById]
|
2024-04-28 22:19:25 +00:00
|
|
|
[Consumes("application/json")]
|
|
|
|
public ActionResult<RemotePathMappingResource> CreateMapping([FromBody] RemotePathMappingResource resource)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
var model = resource.ToModel();
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
return Created(_remotePathMappingService.Add(model).Id);
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
[HttpGet]
|
|
|
|
public List<RemotePathMappingResource> GetMappings()
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
return _remotePathMappingService.All().ToResource();
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
[RestDeleteById]
|
|
|
|
public void DeleteMapping(int id)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
_remotePathMappingService.Remove(id);
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
[RestPutById]
|
2024-04-28 22:19:25 +00:00
|
|
|
public ActionResult<RemotePathMappingResource> UpdateMapping([FromBody] RemotePathMappingResource resource)
|
2018-11-23 07:03:32 +00:00
|
|
|
{
|
|
|
|
var mapping = resource.ToModel();
|
|
|
|
|
2021-10-21 20:04:19 +00:00
|
|
|
return Accepted(_remotePathMappingService.Update(mapping));
|
2018-11-23 07:03:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|