jellyfin-server/MediaBrowser.Api/AppThemeService.cs

99 lines
3.3 KiB
C#
Raw Normal View History

2014-02-28 04:49:02 +00:00
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Themes;
using MediaBrowser.Model.Themes;
using ServiceStack;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace MediaBrowser.Api
{
2014-03-25 21:13:55 +00:00
[Route("/Themes", "GET", Summary = "Gets a list of available themes for an app")]
2014-02-28 04:49:02 +00:00
public class GetAppThemes : IReturn<List<AppThemeInfo>>
{
2014-02-28 05:22:36 +00:00
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string App { get; set; }
2014-02-28 04:49:02 +00:00
}
2014-03-25 21:13:55 +00:00
[Route("/Themes/Info", "GET", Summary = "Gets an app theme")]
2014-02-28 04:49:02 +00:00
public class GetAppTheme : IReturn<AppTheme>
{
2014-02-28 05:22:36 +00:00
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string App { get; set; }
2014-02-28 04:49:02 +00:00
[ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Name { get; set; }
}
2014-03-25 21:13:55 +00:00
[Route("/Themes/Images", "GET", Summary = "Gets an app theme")]
2014-02-28 04:49:02 +00:00
public class GetAppThemeImage
{
2014-02-28 05:22:36 +00:00
[ApiMember(Name = "App", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string App { get; set; }
2014-02-28 04:49:02 +00:00
2014-02-28 05:22:36 +00:00
[ApiMember(Name = "Theme", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Theme { get; set; }
2014-02-28 04:49:02 +00:00
[ApiMember(Name = "Name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Name { get; set; }
2014-02-28 04:51:32 +00:00
[ApiMember(Name = "CacheTag", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string CacheTag { get; set; }
2014-02-28 04:49:02 +00:00
}
2014-03-25 21:13:55 +00:00
[Route("/Themes", "POST", Summary = "Saves a theme")]
2014-02-28 04:49:02 +00:00
public class SaveTheme : AppTheme, IReturnVoid
{
}
2014-03-25 21:13:55 +00:00
2014-02-28 04:49:02 +00:00
public class AppThemeService : BaseApiService
{
private readonly IAppThemeManager _themeManager;
private readonly IFileSystem _fileSystem;
public AppThemeService(IAppThemeManager themeManager, IFileSystem fileSystem)
{
_themeManager = themeManager;
_fileSystem = fileSystem;
}
public object Get(GetAppThemes request)
{
2014-02-28 05:22:36 +00:00
var result = _themeManager.GetThemes(request.App).ToList();
2014-02-28 04:49:02 +00:00
return ToOptimizedResult(result);
}
public object Get(GetAppTheme request)
{
2014-02-28 05:22:36 +00:00
var result = _themeManager.GetTheme(request.App, request.Name);
2014-02-28 04:49:02 +00:00
return ToOptimizedResult(result);
}
public void Post(SaveTheme request)
{
_themeManager.SaveTheme(request);
}
public object Get(GetAppThemeImage request)
{
2014-02-28 05:22:36 +00:00
var info = _themeManager.GetImageImageInfo(request.App, request.Theme, request.Name);
2014-02-28 04:49:02 +00:00
var cacheGuid = new Guid(info.CacheTag);
TimeSpan? cacheDuration = null;
2014-02-28 04:51:32 +00:00
if (!string.IsNullOrEmpty(request.CacheTag) && cacheGuid == new Guid(request.CacheTag))
2014-02-28 04:49:02 +00:00
{
cacheDuration = TimeSpan.FromDays(365);
}
var contentType = MimeTypes.GetMimeType(info.Path);
return ToCachedResult(cacheGuid, info.DateModified, cacheDuration, () => _fileSystem.GetFileStream(info.Path, FileMode.Open, FileAccess.Read, FileShare.Read), contentType);
}
}
}