DeeplinkParseRuleDTO.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. /// <summary>
  46. /// 如果url_atciton = 3 ,用来提取body中的json数据,确保输出的是json格式
  47. /// </summary>
  48. public string slice_pattern { get; set; } = string.Empty;
  49. public string body_pattern { get; set; } = string.Empty;
  50. public string url_pattern { get; set; } = string.Empty;
  51. public string pattern { get; set; } = string.Empty;
  52. public string post { get; set; } = string.Empty;
  53. public string plugin { get; set; } = string.Empty;
  54. public List<string[]> replace { get; set; } = new();
  55. public string deeplink_template { get; set; } = string.Empty;
  56. public string prompt_text { get; set; } = string.Empty;
  57. public bool enable { get; set; } = true;
  58. public List<DeeplinkParseRule> childs { get; set; } = new();
  59. public List<DeeplinkResources> resources { get; set; } = new();
  60. public List<ReplacementRule> replacements { get; set; } = new();
  61. }
  62. /// <summary>
  63. /// "resources": [
  64. /// {
  65. /// "name": "info",
  66. /// "url_pattern": "https://api.my.tv.sohu.com/forward/api/h5/getForwardInfo?callback=jsonpx1730973492613_41_1&forward_id={1}",
  67. /// "url_action": 2,
  68. /// "pattern": [
  69. /// "{\"commentDigg\":{\"id\":\"(\\d+)\"",
  70. /// "\"comment_id\":\"(\\d+)\""
  71. /// ]
  72. /// }
  73. /// ]
  74. /// </summary>
  75. public class DeeplinkResources
  76. {
  77. public string name { get; set; } = string.Empty;
  78. public string post { get; set; } = string.Empty;
  79. public string url_pattern { get; set; } = string.Empty;
  80. public UrlAction url_action { get; set; } = UrlAction.None;
  81. public List<string> pattern { get; set; } = [];
  82. public bool enable { get; set; } = true;
  83. }
  84. [Table("deeplink_parse_rule")]
  85. public class DeeplinkParseRuleDTO
  86. {
  87. [Key]
  88. public int id { get; set; }
  89. public int channel_id { get; set; } = 0;
  90. public int push_channel_id { get; set; } = 0;
  91. public string channel_name { get; set; } = string.Empty;
  92. public string name { get; set; } = string.Empty;
  93. public string logo { get; set; } = string.Empty;
  94. public string rules { get; set; } = string.Empty;
  95. public string IgnorePercentageCity { get; set; } = string.Empty;
  96. public bool status { get; set; } = false;
  97. public DateTime create_time { get; set; } = DateTime.Now;
  98. [IgnoreUpdate]
  99. public DateTime last_time { get; set; } = DateTime.Now;
  100. }
  101. }