aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Controllers/EnvironmentController.cs
diff options
context:
space:
mode:
authorcrobibero <cody@robibe.ro>2020-06-04 07:59:11 -0600
committercrobibero <cody@robibe.ro>2020-06-04 07:59:11 -0600
commit22f56842bd6422a8f2789a2ce5a7d6f4caf563f2 (patch)
treee286c98a338d022168c8f416feaf81d86aaa581f /Jellyfin.Api/Controllers/EnvironmentController.cs
parent5f0c37d5745cbf2632d377905a0763f0254bca08 (diff)
Apply review suggestions
Diffstat (limited to 'Jellyfin.Api/Controllers/EnvironmentController.cs')
-rw-r--r--Jellyfin.Api/Controllers/EnvironmentController.cs31
1 files changed, 14 insertions, 17 deletions
diff --git a/Jellyfin.Api/Controllers/EnvironmentController.cs b/Jellyfin.Api/Controllers/EnvironmentController.cs
index 8d9d2642f..35cd89e0e 100644
--- a/Jellyfin.Api/Controllers/EnvironmentController.cs
+++ b/Jellyfin.Api/Controllers/EnvironmentController.cs
@@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
+using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers
{
@@ -21,17 +22,20 @@ namespace Jellyfin.Api.Controllers
public class EnvironmentController : BaseJellyfinApiController
{
private const char UncSeparator = '\\';
- private const string UncSeparatorString = "\\";
+ private const string UncStartPrefix = @"\\";
private readonly IFileSystem _fileSystem;
+ private readonly ILogger<EnvironmentController> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="EnvironmentController"/> class.
/// </summary>
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
- public EnvironmentController(IFileSystem fileSystem)
+ /// <param name="logger">Instance of the <see cref="ILogger{EnvironmentController}"/> interface.</param>
+ public EnvironmentController(IFileSystem fileSystem, ILogger<EnvironmentController> logger)
{
_fileSystem = fileSystem;
+ _logger = logger;
}
/// <summary>
@@ -46,27 +50,19 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
public IEnumerable<FileSystemEntryInfo> GetDirectoryContents(
[FromQuery, BindRequired] string path,
- [FromQuery] bool includeFiles,
- [FromQuery] bool includeDirectories)
+ [FromQuery] bool includeFiles = false,
+ [FromQuery] bool includeDirectories = false)
{
- const string networkPrefix = UncSeparatorString + UncSeparatorString;
- if (path.StartsWith(networkPrefix, StringComparison.OrdinalIgnoreCase)
+ if (path.StartsWith(UncStartPrefix, StringComparison.OrdinalIgnoreCase)
&& path.LastIndexOf(UncSeparator) == 1)
{
return Array.Empty<FileSystemEntryInfo>();
}
- var entries = _fileSystem.GetFileSystemEntries(path).OrderBy(i => i.FullName).Where(i =>
- {
- var isDirectory = i.IsDirectory;
-
- if (!includeFiles && !isDirectory)
- {
- return false;
- }
-
- return includeDirectories || !isDirectory;
- });
+ var entries =
+ _fileSystem.GetFileSystemEntries(path)
+ .Where(i => (i.IsDirectory && includeDirectories) || (!i.IsDirectory && includeFiles))
+ .OrderBy(i => i.FullName);
return entries.Select(f => new FileSystemEntryInfo
{
@@ -142,6 +138,7 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<IEnumerable<FileSystemEntryInfo>> GetNetworkShares()
{
+ _logger.LogWarning("Obsolete endpoint accessed: /Environment/NetworkShares");
return Array.Empty<FileSystemEntryInfo>();
}