DeeplinkParseRuleDTO.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using dodohold.core;
  2. namespace molilian.core
  3. {
  4. public class ReplacementRule
  5. {
  6. public class Rule
  7. {
  8. public class Condition
  9. {
  10. public string Value { get; set; }
  11. public string Operator { get; set; } = "equals";
  12. public bool Evaluate(string input)
  13. {
  14. return Operator switch
  15. {
  16. "equals" => input == Value,
  17. "contains" => input.Contains(Value),
  18. "startsWith" => input.StartsWith(Value),
  19. "endsWith" => input.EndsWith(Value),
  20. _ => false
  21. };
  22. }
  23. }
  24. public Condition When { get; set; }
  25. public string Then { get; set; }
  26. }
  27. public string Name { get; set; }
  28. public List<Rule> Rules { get; set; }
  29. public string Default { get; set; }
  30. internal object FirstOrDefault(Func<object, bool> value)
  31. {
  32. throw new NotImplementedException();
  33. }
  34. }
  35. public enum UrlAction
  36. {
  37. None = 0,
  38. Redirect = 1,
  39. Body = 2,
  40. JsonBody = 3,
  41. }
  42. public class DeeplinkParseRule
  43. {
  44. public UrlAction url_action { get; set; } = UrlAction.None;
  45. public string body_pattern { get; set; } = string.Empty;
  46. public string url_pattern { get; set; } = string.Empty;
  47. public string pattern { get; set; } = string.Empty;
  48. public string plugin { get; set; } = string.Empty;
  49. public List<string[]> replace { get; set; } = new();
  50. public string deeplink_template { get; set; } = string.Empty;
  51. public string prompt_text { get; set; } = string.Empty;
  52. public bool enable { get; set; } = true;
  53. public List<DeeplinkParseRule> childs { get; set; } = new();
  54. public List<DeeplinkResources> resources { get; set; } = new();
  55. public List<ReplacementRule> replacements { get; set; } = new();
  56. }
  57. /// <summary>
  58. /// "resources": [
  59. /// {
  60. /// "name": "info",
  61. /// "url_pattern": "https://api.my.tv.sohu.com/forward/api/h5/getForwardInfo?callback=jsonpx1730973492613_41_1&forward_id={1}",
  62. /// "url_action": 2,
  63. /// "pattern": [
  64. /// "{\"commentDigg\":{\"id\":\"(\\d+)\"",
  65. /// "\"comment_id\":\"(\\d+)\""
  66. /// ]
  67. /// }
  68. /// ]
  69. /// </summary>
  70. public class DeeplinkResources
  71. {
  72. public string name { get; set; } = string.Empty;
  73. public string url_pattern { get; set; } = string.Empty;
  74. public UrlAction url_action { get; set; } = UrlAction.None;
  75. public List<string> pattern { get; set; } = [];
  76. public bool enable { get; set; } = true;
  77. }
  78. [Table("deeplink_parse_rule")]
  79. public class DeeplinkParseRuleDTO
  80. {
  81. [Key]
  82. public int id { get; set; }
  83. public int channel_id { get; set; } = 0;
  84. public int push_channel_id { get; set; } = 0;
  85. public string channel_name { get; set; } = string.Empty;
  86. public string name { get; set; } = string.Empty;
  87. public string logo { get; set; } = string.Empty;
  88. public string rules { get; set; } = string.Empty;
  89. public string IgnorePercentageCity { get; set; } = string.Empty;
  90. public bool status { get; set; } = false;
  91. public DateTime create_time { get; set; } = DateTime.Now;
  92. [IgnoreUpdate]
  93. public DateTime last_time { get; set; } = DateTime.Now;
  94. }
  95. }