mirror of
https://github.com/Sonarr/Sonarr
synced 2025-12-06 08:28:37 +01:00
Add additional v5 filesystem endpoints
This commit is contained in:
parent
1ca148a7a9
commit
2f119fefd1
1 changed files with 61 additions and 0 deletions
61
src/Sonarr.Api.V5/FileSystem/FileSystemController.cs
Normal file
61
src/Sonarr.Api.V5/FileSystem/FileSystemController.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using Sonarr.Http;
|
||||
|
||||
namespace Sonarr.Api.V5.FileSystem;
|
||||
|
||||
[V5ApiController]
|
||||
public class FileSystemController : Controller
|
||||
{
|
||||
private readonly IFileSystemLookupService _fileSystemLookupService;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IDiskScanService _diskScanService;
|
||||
|
||||
public FileSystemController(IFileSystemLookupService fileSystemLookupService,
|
||||
IDiskProvider diskProvider,
|
||||
IDiskScanService diskScanService)
|
||||
{
|
||||
_fileSystemLookupService = fileSystemLookupService;
|
||||
_diskProvider = diskProvider;
|
||||
_diskScanService = diskScanService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Produces("application/json")]
|
||||
public IActionResult GetContents(string path, bool includeFiles = false, bool allowFoldersWithoutTrailingSlashes = false)
|
||||
{
|
||||
return Ok(_fileSystemLookupService.LookupContents(path, includeFiles, allowFoldersWithoutTrailingSlashes));
|
||||
}
|
||||
|
||||
[HttpGet("type")]
|
||||
[Produces("application/json")]
|
||||
public object GetEntityType(string path)
|
||||
{
|
||||
if (_diskProvider.FileExists(path))
|
||||
{
|
||||
return new { type = "file" };
|
||||
}
|
||||
|
||||
// Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system
|
||||
return new { type = "folder" };
|
||||
}
|
||||
|
||||
[HttpGet("mediafiles")]
|
||||
[Produces("application/json")]
|
||||
public object GetMediaFiles(string path)
|
||||
{
|
||||
if (!_diskProvider.FolderExists(path))
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
return _diskScanService.GetVideoFiles(path).Select(f => new
|
||||
{
|
||||
Path = f,
|
||||
RelativePath = path.GetRelativePath(f),
|
||||
Name = Path.GetFileName(f)
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue