DtoOptions.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.Querying;
  8. namespace MediaBrowser.Controller.Dto
  9. {
  10. public class DtoOptions
  11. {
  12. private static readonly ItemFields[] DefaultExcludedFields = new[]
  13. {
  14. ItemFields.SeasonUserData,
  15. ItemFields.RefreshState
  16. };
  17. public IReadOnlyList<ItemFields> Fields { get; set; }
  18. public IReadOnlyList<ImageType> ImageTypes { get; set; }
  19. public int ImageTypeLimit { get; set; }
  20. public bool EnableImages { get; set; }
  21. public bool AddProgramRecordingInfo { get; set; }
  22. public bool EnableUserData { get; set; }
  23. public bool AddCurrentProgram { get; set; }
  24. public DtoOptions()
  25. : this(true)
  26. {
  27. }
  28. private static readonly ImageType[] AllImageTypes = Enum.GetNames(typeof(ImageType))
  29. .Select(i => (ImageType)Enum.Parse(typeof(ImageType), i, true))
  30. .ToArray();
  31. private static readonly ItemFields[] AllItemFields = Enum.GetNames(typeof(ItemFields))
  32. .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
  33. .Except(DefaultExcludedFields)
  34. .ToArray();
  35. public bool ContainsField(ItemFields field)
  36. => Fields.Contains(field);
  37. public DtoOptions(bool allFields)
  38. {
  39. ImageTypeLimit = int.MaxValue;
  40. EnableImages = true;
  41. EnableUserData = true;
  42. AddCurrentProgram = true;
  43. Fields = allFields ? AllItemFields : Array.Empty<ItemFields>();
  44. ImageTypes = AllImageTypes;
  45. }
  46. public int GetImageLimit(ImageType type)
  47. {
  48. if (EnableImages && ImageTypes.Contains(type))
  49. {
  50. return ImageTypeLimit;
  51. }
  52. return 0;
  53. }
  54. }
  55. }