Radarr/src/Radarr.Api.V3/FileSystem/FileSystemController.cs

63 lines
2.0 KiB
C#
Raw Permalink Normal View History

using System;
2018-11-23 07:03:32 +00:00
using System.IO;
using System.Linq;
2021-10-21 20:04:19 +00:00
using Microsoft.AspNetCore.Mvc;
2018-11-23 07:03:32 +00:00
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaFiles;
2021-10-21 20:04:19 +00:00
using Radarr.Http;
2018-11-23 07:03:32 +00:00
namespace Radarr.Api.V3.FileSystem
2018-11-23 07:03:32 +00:00
{
2021-10-21 20:04:19 +00:00
[V3ApiController]
public class FileSystemController : Controller
2018-11-23 07:03:32 +00:00
{
private readonly IFileSystemLookupService _fileSystemLookupService;
private readonly IDiskProvider _diskProvider;
private readonly IDiskScanService _diskScanService;
2021-10-21 20:04:19 +00:00
public FileSystemController(IFileSystemLookupService fileSystemLookupService,
2018-11-23 07:03:32 +00:00
IDiskProvider diskProvider,
IDiskScanService diskScanService)
{
_fileSystemLookupService = fileSystemLookupService;
_diskProvider = diskProvider;
_diskScanService = diskScanService;
}
2021-10-21 20:04:19 +00:00
[HttpGet]
public IActionResult GetContents(string path, bool includeFiles = false, bool allowFoldersWithoutTrailingSlashes = false)
2018-11-23 07:03:32 +00:00
{
2021-10-21 20:04:19 +00:00
return Ok(_fileSystemLookupService.LookupContents(path, includeFiles, allowFoldersWithoutTrailingSlashes));
2018-11-23 07:03:32 +00:00
}
2021-10-21 20:04:19 +00:00
[HttpGet("type")]
public object GetEntityType(string path)
2018-11-23 07:03:32 +00:00
{
if (_diskProvider.FileExists(path))
{
2019-08-28 21:43:55 +00:00
return new { type = "file" };
2018-11-23 07:03:32 +00:00
}
2022-11-20 18:27:45 +00:00
// Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system
2019-08-28 21:43:55 +00:00
return new { type = "folder" };
2018-11-23 07:03:32 +00:00
}
2021-10-21 20:04:19 +00:00
[HttpGet("mediafiles")]
public object GetMediaFiles(string path)
2018-11-23 07:03:32 +00:00
{
if (!_diskProvider.FolderExists(path))
{
return Array.Empty<string>();
2018-11-23 07:03:32 +00:00
}
2019-12-22 22:08:53 +00:00
return _diskScanService.GetVideoFiles(path).Select(f => new
{
2018-11-23 07:03:32 +00:00
Path = f,
RelativePath = path.GetRelativePath(f),
Name = Path.GetFileName(f)
2019-08-28 21:43:55 +00:00
});
2018-11-23 07:03:32 +00:00
}
}
}