DtoOptions.cs 1.7 KB

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