DtoOptions.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. private static readonly ImageType[] AllImageTypes = Enum.GetValues<ImageType>();
  18. private static readonly ItemFields[] AllItemFields = Enum.GetValues<ItemFields>()
  19. .Except(DefaultExcludedFields)
  20. .ToArray();
  21. public DtoOptions()
  22. : this(true)
  23. {
  24. }
  25. public DtoOptions(bool allFields)
  26. {
  27. ImageTypeLimit = int.MaxValue;
  28. EnableImages = true;
  29. EnableUserData = true;
  30. AddCurrentProgram = true;
  31. Fields = allFields ? AllItemFields : Array.Empty<ItemFields>();
  32. ImageTypes = AllImageTypes;
  33. }
  34. public IReadOnlyList<ItemFields> Fields { get; set; }
  35. public IReadOnlyList<ImageType> ImageTypes { get; set; }
  36. public int ImageTypeLimit { get; set; }
  37. public bool EnableImages { get; set; }
  38. public bool AddProgramRecordingInfo { get; set; }
  39. public bool EnableUserData { get; set; }
  40. public bool AddCurrentProgram { get; set; }
  41. public bool ContainsField(ItemFields field)
  42. => Fields.Contains(field);
  43. public int GetImageLimit(ImageType type)
  44. {
  45. if (EnableImages && ImageTypes.Contains(type))
  46. {
  47. return ImageTypeLimit;
  48. }
  49. return 0;
  50. }
  51. }
  52. }