From d7be8bd1f59a5f6d0d55b5f6ce0ba6a8422baf7c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 May 2013 11:12:27 -0400 Subject: [PATCH] fixed missing file --- MediaBrowser.Api/Images/ImageByNameService.cs | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 MediaBrowser.Api/Images/ImageByNameService.cs diff --git a/MediaBrowser.Api/Images/ImageByNameService.cs b/MediaBrowser.Api/Images/ImageByNameService.cs new file mode 100644 index 000000000..108589517 --- /dev/null +++ b/MediaBrowser.Api/Images/ImageByNameService.cs @@ -0,0 +1,132 @@ +using MediaBrowser.Controller; +using ServiceStack.ServiceHost; +using System.IO; + +namespace MediaBrowser.Api.Images +{ + /// + /// Class GetGeneralImage + /// + [Route("/Images/General/{Name}", "GET")] + [Api(Description = "Gets a general image by name")] + public class GetGeneralImage : ImageRequest + { + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "The name of the image", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Name { get; set; } + } + + /// + /// Class GetRatingImage + /// + [Route("/Images/{Theme}/Ratings/{Name}", "GET")] + [Api(Description = "Gets a rating image by name")] + public class GetRatingImage : ImageRequest + { + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "The name of the image", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Name { get; set; } + + /// + /// Gets or sets the theme. + /// + /// The theme. + [ApiMember(Name = "Theme", Description = "The theme to get the image from", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Theme { get; set; } + } + + /// + /// Class GetMediaInfoImage + /// + [Route("/Images/{Theme}/MediaInfo/{Name}", "GET")] + [Api(Description = "Gets a media info image by name")] + public class GetMediaInfoImage : ImageRequest + { + /// + /// Gets or sets the name. + /// + /// The name. + [ApiMember(Name = "Name", Description = "The name of the image", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Name { get; set; } + + /// + /// Gets or sets the theme. + /// + /// The theme. + [ApiMember(Name = "Theme", Description = "The theme to get the image from", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Theme { get; set; } + } + + /// + /// Class ImageByNameService + /// + public class ImageByNameService : BaseApiService + { + /// + /// The _app paths + /// + private readonly IServerApplicationPaths _appPaths; + + /// + /// Initializes a new instance of the class. + /// + /// The app paths. + public ImageByNameService(IServerApplicationPaths appPaths) + { + _appPaths = appPaths; + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetGeneralImage request) + { + var file = Path.Combine(_appPaths.GeneralPath, request.Name, "folder.jpg"); + + return ToStaticFileResult(File.Exists(file) ? file : Path.ChangeExtension(file, ".png")); + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetRatingImage request) + { + var file = Path.Combine(_appPaths.GeneralPath, request.Theme); + + return GetImageByName(_appPaths.RatingsPath, request.Name); + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetMediaInfoImage request) + { + return GetImageByName(_appPaths.MediaInfoImagesPath, request.Name); + } + + /// + /// Gets the name of the image by. + /// + /// The directory. + /// The name. + /// System.Object. + private object GetImageByName(string directory, string name) + { + var file = Path.Combine(directory, name, "folder.jpg"); + + return ToStaticFileResult(File.Exists(file) ? file : Path.ChangeExtension(file, ".png")); + } + } +}