diff --git a/MediaBrowser.Api/Images/ImageByNameService.cs b/MediaBrowser.Api/Images/ImageByNameService.cs new file mode 100644 index 0000000000..1085895172 --- /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")); + } + } +}