update ibn methods to support themes

This commit is contained in:
Luke Pulverenti 2013-05-02 11:31:39 -04:00
parent df8a1d29c4
commit 9105b065e7

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller; using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller;
using ServiceStack.ServiceHost; using ServiceStack.ServiceHost;
using System.IO; using System.IO;
@ -22,7 +23,7 @@ namespace MediaBrowser.Api.Images
/// <summary> /// <summary>
/// Class GetRatingImage /// Class GetRatingImage
/// </summary> /// </summary>
[Route("/Images/{Theme}/Ratings/{Name}", "GET")] [Route("/Images/Ratings/{Theme}/{Name}", "GET")]
[Api(Description = "Gets a rating image by name")] [Api(Description = "Gets a rating image by name")]
public class GetRatingImage : ImageRequest public class GetRatingImage : ImageRequest
{ {
@ -44,7 +45,7 @@ namespace MediaBrowser.Api.Images
/// <summary> /// <summary>
/// Class GetMediaInfoImage /// Class GetMediaInfoImage
/// </summary> /// </summary>
[Route("/Images/{Theme}/MediaInfo/{Name}", "GET")] [Route("/Images/MediaInfo/{Theme}/{Name}", "GET")]
[Api(Description = "Gets a media info image by name")] [Api(Description = "Gets a media info image by name")]
public class GetMediaInfoImage : ImageRequest public class GetMediaInfoImage : ImageRequest
{ {
@ -101,9 +102,45 @@ namespace MediaBrowser.Api.Images
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
public object Get(GetRatingImage request) public object Get(GetRatingImage request)
{ {
var file = Path.Combine(_appPaths.GeneralPath, request.Theme); var themeFolder = Path.Combine(_appPaths.RatingsPath, request.Theme);
return GetImageByName(_appPaths.RatingsPath, request.Name); if (Directory.Exists(themeFolder))
{
var file = Path.Combine(themeFolder, request.Name + ".png");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
file = Path.Combine(themeFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
}
var allFolder = Path.Combine(_appPaths.RatingsPath, "all");
if (Directory.Exists(allFolder))
{
var file = Path.Combine(allFolder, request.Name + ".png");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
file = Path.Combine(allFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
}
throw new ResourceNotFoundException("MediaInfo image not found: " + request.Name);
} }
/// <summary> /// <summary>
@ -113,20 +150,45 @@ namespace MediaBrowser.Api.Images
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
public object Get(GetMediaInfoImage request) public object Get(GetMediaInfoImage request)
{ {
return GetImageByName(_appPaths.MediaInfoImagesPath, request.Name); var themeFolder = Path.Combine(_appPaths.MediaInfoImagesPath, request.Theme);
}
/// <summary> if (Directory.Exists(themeFolder))
/// Gets the name of the image by. {
/// </summary> var file = Path.Combine(themeFolder, request.Name + ".png");
/// <param name="directory">The directory.</param>
/// <param name="name">The name.</param>
/// <returns>System.Object.</returns>
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")); if (File.Exists(file))
{
return ToStaticFileResult(file);
}
file = Path.Combine(themeFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
}
var allFolder = Path.Combine(_appPaths.MediaInfoImagesPath, "all");
if (Directory.Exists(allFolder))
{
var file = Path.Combine(allFolder, request.Name + ".png");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
file = Path.Combine(allFolder, request.Name + ".jpg");
if (File.Exists(file))
{
return ToStaticFileResult(file);
}
}
throw new ResourceNotFoundException("MediaInfo image not found: " + request.Name);
} }
} }
} }