Lidarr/src/Lidarr.Api.V1/FileSystem/FileSystemController.cs

59 lines
1.9 KiB
C#
Raw Normal View History

2017-09-04 02:20:56 +00:00
using System.Linq;
2021-08-04 20:42:40 +00:00
using Lidarr.Http;
using Microsoft.AspNetCore.Mvc;
2017-09-04 02:20:56 +00:00
using NzbDrone.Common.Disk;
using NzbDrone.Core.MediaFiles;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.FileSystem
2017-09-04 02:20:56 +00:00
{
2021-08-04 20:42:40 +00:00
[V1ApiController]
public class FileSystemController : Controller
2017-09-04 02:20:56 +00:00
{
private readonly IFileSystemLookupService _fileSystemLookupService;
private readonly IDiskProvider _diskProvider;
private readonly IDiskScanService _diskScanService;
2021-08-04 20:42:40 +00:00
public FileSystemController(IFileSystemLookupService fileSystemLookupService,
2017-09-04 02:20:56 +00:00
IDiskProvider diskProvider,
IDiskScanService diskScanService)
{
_fileSystemLookupService = fileSystemLookupService;
_diskProvider = diskProvider;
_diskScanService = diskScanService;
}
2021-08-04 20:42:40 +00:00
[HttpGet]
public IActionResult GetContents(string path, bool includeFiles = false, bool allowFoldersWithoutTrailingSlashes = false)
2017-09-04 02:20:56 +00:00
{
2021-08-04 20:42:40 +00:00
return Ok(_fileSystemLookupService.LookupContents(path, includeFiles, allowFoldersWithoutTrailingSlashes));
2017-09-04 02:20:56 +00:00
}
2021-08-04 20:42:40 +00:00
[HttpGet("type")]
public object GetEntityType(string path)
2017-09-04 02:20:56 +00:00
{
if (_diskProvider.FileExists(path))
{
2019-09-12 20:32:51 +00:00
return new { type = "file" };
2017-09-04 02:20:56 +00:00
}
// Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system
2019-09-12 20:32:51 +00:00
return new { type = "folder" };
2017-09-04 02:20:56 +00:00
}
2021-08-04 20:42:40 +00:00
[HttpGet("mediafiles")]
public object GetMediaFiles(string path)
2017-09-04 02:20:56 +00:00
{
if (!_diskProvider.FolderExists(path))
{
2019-09-12 20:32:51 +00:00
return new string[0];
2017-09-04 02:20:56 +00:00
}
return _diskScanService.GetAudioFiles(path).Select(f => new
{
Path = f.FullName,
Name = f.Name
2019-09-12 20:32:51 +00:00
});
2017-09-04 02:20:56 +00:00
}
}
}