diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 0eb92d5a7e..ef415ec57c 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -1,10 +1,10 @@ using MediaBrowser.Api.Playback; using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Session; using System; @@ -39,6 +39,7 @@ namespace MediaBrowser.Api private readonly IServerConfigurationManager _config; private readonly ISessionManager _sessionManager; + private readonly IFileSystem _fileSystem; public readonly SemaphoreSlim TranscodingStartLock = new SemaphoreSlim(1, 1); @@ -48,11 +49,12 @@ namespace MediaBrowser.Api /// The logger. /// The session manager. /// The configuration. - public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config) + public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config, IFileSystem fileSystem) { Logger = logger; _sessionManager = sessionManager; _config = config; + _fileSystem = fileSystem; Instance = this; } @@ -86,12 +88,12 @@ namespace MediaBrowser.Api /// private void DeleteEncodedMediaCache() { - var path = Path.Combine(_config.ApplicationPaths.TranscodingTempPath, EncodingContext.Streaming.ToString().ToLower()); + var path = _config.ApplicationPaths.TranscodingTempPath; foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) .ToList()) { - File.Delete(file); + _fileSystem.DeleteFile(file); } } @@ -462,7 +464,7 @@ namespace MediaBrowser.Api /// The output file path. private void DeleteProgressivePartialStreamFiles(string outputFilePath) { - File.Delete(outputFilePath); + _fileSystem.DeleteFile(outputFilePath); } /// @@ -479,13 +481,13 @@ namespace MediaBrowser.Api .ToList(); Exception e = null; - + foreach (var file in filesToDelete) { try { Logger.Info("Deleting HLS file {0}", file); - File.Delete(file); + _fileSystem.DeleteFile(file); } catch (DirectoryNotFoundException) { diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 297a131557..dff433c9dc 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -1,9 +1,12 @@ -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Dto; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; +using ServiceStack.Text.Controller; using ServiceStack.Web; using System; using System.Collections.Generic; @@ -21,7 +24,7 @@ namespace MediaBrowser.Api /// /// The logger. public ILogger Logger { get; set; } - + /// /// Gets or sets the HTTP result factory. /// @@ -35,6 +38,7 @@ namespace MediaBrowser.Api public IRequest Request { get; set; } public ISessionContext SessionContext { get; set; } + public IAuthorizationContext AuthorizationContext { get; set; } public string GetHeader(string name) { @@ -109,6 +113,37 @@ namespace MediaBrowser.Api private readonly char[] _dashReplaceChars = { '?', '/', '&' }; private const char SlugChar = '-'; + protected DtoOptions GetDtoOptions(object request) + { + var options = new DtoOptions(); + + options.DeviceId = AuthorizationContext.GetAuthorizationInfo(Request).DeviceId; + + var hasFields = request as IHasItemFields; + if (hasFields != null) + { + options.Fields = hasFields.GetItemFields().ToList(); + } + + var hasDtoOptions = request as IHasDtoOptions; + if (hasDtoOptions != null) + { + options.EnableImages = hasDtoOptions.EnableImages ?? true; + + if (hasDtoOptions.ImageTypeLimit.HasValue) + { + options.ImageTypeLimit = hasDtoOptions.ImageTypeLimit.Value; + } + + if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes)) + { + options.ImageTypes = (hasDtoOptions.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList(); + } + } + + return options; + } + protected MusicArtist GetArtist(string name, ILibraryManager libraryManager) { return libraryManager.GetArtist(DeSlugArtistName(name, libraryManager)); @@ -139,11 +174,11 @@ namespace MediaBrowser.Api return libraryManager.GetPerson(DeSlugPersonName(name, libraryManager)); } - protected IEnumerable GetAllLibraryItems(Guid? userId, IUserManager userManager, ILibraryManager libraryManager, string parentId = null) + protected IList GetAllLibraryItems(Guid? userId, IUserManager userManager, ILibraryManager libraryManager, string parentId, Func filter) { if (!string.IsNullOrEmpty(parentId)) { - var folder = (Folder) libraryManager.GetItemById(new Guid(parentId)); + var folder = (Folder)libraryManager.GetItemById(new Guid(parentId)); if (userId.HasValue) { @@ -154,10 +189,13 @@ namespace MediaBrowser.Api throw new ArgumentException("User not found"); } - return folder.GetRecursiveChildren(user); + return folder + .GetRecursiveChildren(user, filter) + .ToList(); } - return folder.GetRecursiveChildren(); + return folder + .GetRecursiveChildren(filter); } if (userId.HasValue) { @@ -168,10 +206,16 @@ namespace MediaBrowser.Api throw new ArgumentException("User not found"); } - return userManager.GetUserById(userId.Value).RootFolder.GetRecursiveChildren(user); + return userManager + .GetUserById(userId.Value) + .RootFolder + .GetRecursiveChildren(user, filter) + .ToList(); } - return libraryManager.RootFolder.GetRecursiveChildren(); + return libraryManager + .RootFolder + .GetRecursiveChildren(filter); } /// @@ -187,8 +231,9 @@ namespace MediaBrowser.Api return name; } - return libraryManager.RootFolder.RecursiveChildren - .OfType