DeeplinkParseRuleDTO.cs 3.5 KB

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