jellyfin-server/MediaBrowser.Api/IHasDtoOptions.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2015-01-03 19:38:22 +00:00
using MediaBrowser.Controller.Dto;
2014-12-01 12:43:34 +00:00
using MediaBrowser.Model.Entities;
using System;
using System.Linq;
namespace MediaBrowser.Api
{
public interface IHasDtoOptions : IHasItemFields
{
bool? EnableImages { get; set; }
int? ImageTypeLimit { get; set; }
string EnableImageTypes { get; set; }
}
public static class HasDtoOptionsExtensions
{
public static DtoOptions GetDtoOptions(this IHasDtoOptions request)
{
var options = new DtoOptions();
options.Fields = request.GetItemFields().ToList();
options.EnableImages = request.EnableImages ?? true;
if (request.ImageTypeLimit.HasValue)
{
options.ImageTypeLimit = request.ImageTypeLimit.Value;
}
2014-12-27 05:08:39 +00:00
if (!string.IsNullOrWhiteSpace(request.EnableImageTypes))
2014-12-01 12:43:34 +00:00
{
options.ImageTypes = (request.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList();
}
return options;
}
}
}