From ebec1e159c22131bf6fed1c807595894f92427ae Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Sep 2013 13:34:37 -0400 Subject: [PATCH] update default theme endpoints --- MediaBrowser.Api/DefaultTheme/ItemStub.cs | 13 ----- MediaBrowser.Api/DefaultTheme/Models.cs | 50 +++++++++++++++++++ MediaBrowser.Api/DefaultTheme/MoviesView.cs | 24 --------- MediaBrowser.Api/DefaultTheme/TvView.cs | 11 ---- MediaBrowser.Api/MediaBrowser.Api.csproj | 4 +- .../Playback/Hls/AudioHlsService.cs | 2 +- .../Playback/Hls/VideoHlsService.cs | 2 +- .../BaseProgressiveStreamingService.cs | 4 +- MediaBrowser.Common/Net/IHttpResultFactory.cs | 3 +- .../HttpServer/HttpResultFactory.cs | 17 +++++-- 10 files changed, 69 insertions(+), 61 deletions(-) delete mode 100644 MediaBrowser.Api/DefaultTheme/ItemStub.cs create mode 100644 MediaBrowser.Api/DefaultTheme/Models.cs delete mode 100644 MediaBrowser.Api/DefaultTheme/MoviesView.cs delete mode 100644 MediaBrowser.Api/DefaultTheme/TvView.cs diff --git a/MediaBrowser.Api/DefaultTheme/ItemStub.cs b/MediaBrowser.Api/DefaultTheme/ItemStub.cs deleted file mode 100644 index 968154350..000000000 --- a/MediaBrowser.Api/DefaultTheme/ItemStub.cs +++ /dev/null @@ -1,13 +0,0 @@ -using MediaBrowser.Model.Entities; -using System; - -namespace MediaBrowser.Api.DefaultTheme -{ - public class ItemStub - { - public string Name { get; set; } - public string Id { get; set; } - public Guid ImageTag { get; set; } - public ImageType ImageType { get; set; } - } -} diff --git a/MediaBrowser.Api/DefaultTheme/Models.cs b/MediaBrowser.Api/DefaultTheme/Models.cs new file mode 100644 index 000000000..a4167bf33 --- /dev/null +++ b/MediaBrowser.Api/DefaultTheme/Models.cs @@ -0,0 +1,50 @@ +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using System; + +namespace MediaBrowser.Api.DefaultTheme +{ + public class ItemStub + { + public string Name { get; set; } + public string Id { get; set; } + public Guid ImageTag { get; set; } + public ImageType ImageType { get; set; } + } + + public class MoviesView + { + public BaseItemDto[] SpotlightItems { get; set; } + public ItemStub[] MovieItems { get; set; } + public ItemStub[] PeopleItems { get; set; } + + public ItemStub[] BoxSetItems { get; set; } + public ItemStub[] TrailerItems { get; set; } + public ItemStub[] HDItems { get; set; } + public ItemStub[] ThreeDItems { get; set; } + + public ItemStub[] FamilyMovies { get; set; } + + public ItemStub[] RomanceItems { get; set; } + public ItemStub[] ComedyItems { get; set; } + + public double FamilyMoviePercentage { get; set; } + + public double HDMoviePercentage { get; set; } + } + + public class TvView + { + public BaseItemDto[] SpotlightItems { get; set; } + public ItemStub[] ShowsItems { get; set; } + public ItemStub[] ActorItems { get; set; } + + public ItemStub[] RomanceItems { get; set; } + public ItemStub[] ComedyItems { get; set; } + } + + public class HomeView + { + public BaseItemDto[] SpotlightItems { get; set; } + } +} diff --git a/MediaBrowser.Api/DefaultTheme/MoviesView.cs b/MediaBrowser.Api/DefaultTheme/MoviesView.cs deleted file mode 100644 index 11a53a80a..000000000 --- a/MediaBrowser.Api/DefaultTheme/MoviesView.cs +++ /dev/null @@ -1,24 +0,0 @@ -using MediaBrowser.Model.Dto; - -namespace MediaBrowser.Api.DefaultTheme -{ - public class MoviesView - { - public BaseItemDto[] SpotlightItems { get; set; } - public ItemStub[] MovieItems { get; set; } - public ItemStub[] PeopleItems { get; set; } - - public ItemStub[] BoxSetItems { get; set; } - public ItemStub[] TrailerItems { get; set; } - public ItemStub[] HDItems { get; set; } - public ItemStub[] ThreeDItems { get; set; } - - public ItemStub[] FamilyMovies { get; set; } - - public ItemStub[] RomanticItems { get; set; } - - public double FamilyMoviePercentage { get; set; } - - public double HDMoviePercentage { get; set; } - } -} diff --git a/MediaBrowser.Api/DefaultTheme/TvView.cs b/MediaBrowser.Api/DefaultTheme/TvView.cs deleted file mode 100644 index ba7d120f1..000000000 --- a/MediaBrowser.Api/DefaultTheme/TvView.cs +++ /dev/null @@ -1,11 +0,0 @@ -using MediaBrowser.Model.Dto; - -namespace MediaBrowser.Api.DefaultTheme -{ - public class TvView - { - public BaseItemDto[] SpotlightItems { get; set; } - public ItemStub[] ShowsItems { get; set; } - public ItemStub[] ActorItems { get; set; } - } -} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index aa18570e3..70e4e8a9a 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -67,9 +67,7 @@ - - - + diff --git a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs index 68a252d1b..d7ee73a9e 100644 --- a/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/AudioHlsService.cs @@ -70,7 +70,7 @@ namespace MediaBrowser.Api.Playback.Hls file = Path.Combine(ApplicationPaths.EncodedMediaCachePath, file); - return ResultFactory.GetStaticFileResult(RequestContext, file); + return ResultFactory.GetStaticFileResult(RequestContext, file, FileShare.ReadWrite); } /// diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index 2066849ae..7674fe7b7 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -103,7 +103,7 @@ namespace MediaBrowser.Api.Playback.Hls file = Path.Combine(ApplicationPaths.EncodedMediaCachePath, file); - return ResultFactory.GetStaticFileResult(RequestContext, file); + return ResultFactory.GetStaticFileResult(RequestContext, file, FileShare.ReadWrite); } /// diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index 21ef2ba0a..806e55024 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -209,12 +209,12 @@ namespace MediaBrowser.Api.Playback.Progressive if (request.Static) { - return ResultFactory.GetStaticFileResult(RequestContext, state.Item.Path, responseHeaders, isHeadRequest); + return ResultFactory.GetStaticFileResult(RequestContext, state.Item.Path, FileShare.Read, responseHeaders, isHeadRequest); } if (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive)) { - return ResultFactory.GetStaticFileResult(RequestContext, outputPath, responseHeaders, isHeadRequest); + return ResultFactory.GetStaticFileResult(RequestContext, outputPath, FileShare.Read, responseHeaders, isHeadRequest); } return GetStreamResult(state, responseHeaders, isHeadRequest).Result; diff --git a/MediaBrowser.Common/Net/IHttpResultFactory.cs b/MediaBrowser.Common/Net/IHttpResultFactory.cs index 55c0e5b9b..9f3d05d91 100644 --- a/MediaBrowser.Common/Net/IHttpResultFactory.cs +++ b/MediaBrowser.Common/Net/IHttpResultFactory.cs @@ -89,9 +89,10 @@ namespace MediaBrowser.Common.Net /// /// The request context. /// The path. + /// The file share. /// The response headers. /// if set to true [is head request]. /// System.Object. - object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary responseHeaders = null, bool isHeadRequest = false); + object GetStaticFileResult(IRequestContext requestContext, string path, FileShare fileShare = FileShare.Read, IDictionary responseHeaders = null, bool isHeadRequest = false); } } diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 115114e3a..356c6fc4d 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer { AddResponseHeaders(result, responseHeaders); } - + return result; } @@ -271,32 +271,39 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// /// The request context. /// The path. + /// The file share. /// The response headers. /// if set to true [is head request]. /// System.Object. /// path - public object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary responseHeaders = null, bool isHeadRequest = false) + public object GetStaticFileResult(IRequestContext requestContext, string path, FileShare fileShare = FileShare.Read, IDictionary responseHeaders = null, bool isHeadRequest = false) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } + if (fileShare != FileShare.Read && fileShare != FileShare.ReadWrite) + { + throw new ArgumentException("FileShare must be either Read or ReadWrite"); + } + var dateModified = File.GetLastWriteTimeUtc(path); var cacheKey = path + dateModified.Ticks; - return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path)), responseHeaders, isHeadRequest); + return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest); } /// /// Gets the file stream. /// /// The path. + /// The file share. /// Stream. - private Stream GetFileStream(string path) + private Stream GetFileStream(string path, FileShare fileShare) { - return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); + return new FileStream(path, FileMode.Open, FileAccess.Read, fileShare, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); } ///