From 052562a1230109b6482f266206ff7c1145feae75 Mon Sep 17 00:00:00 2001 From: zu1k Date: Tue, 12 Oct 2021 16:28:45 +0800 Subject: [PATCH] feat: Action support both single and multi --- rules/ads.yaml | 27 +++++++++++++-------------- src/rule/file.rs | 9 ++++++++- src/rule/mod.rs | 5 ++++- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/rules/ads.yaml b/rules/ads.yaml index 8352fb6..13aff21 100644 --- a/rules/ads.yaml +++ b/rules/ads.yaml @@ -2,31 +2,30 @@ filter: url-regex: '(nfmovies)(?!.*?(\.css|\.js|\.jpeg|\.png|\.gif)).*' action: - - modify-response: - body: - origin: '' - new: ' ' + modify-response: + body: + origin: '' + new: ' ' - name: "低端影视去广告" filter: domain-prefix: 'ddrk.me' action: - - modify-response: - body: - origin: '' - new: '' + modify-response: + body: + origin: '' + new: '' - name: "www.pianku.li 片库网" filter: domain-keyword: 'pianku' action: - - modify-response: - body: - origin: '' - new: '' + modify-response: + body: + origin: '' + new: '' - name: "m.yhdm.io 樱花动漫" filter: url-regex: '^http:\/\/m\.yhdm\.io\/bar\/yfgg\.js' - action: - - reject + action: reject diff --git a/src/rule/file.rs b/src/rule/file.rs index 8a71edd..3fcc9b2 100644 --- a/src/rule/file.rs +++ b/src/rule/file.rs @@ -6,7 +6,14 @@ use std::{error::Error, fs::File, io::BufReader, path::Path}; pub struct Rule { pub name: String, pub filter: Filter, - pub action: Vec, + pub action: Actions, +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(untagged)] +pub enum Actions { + Action(action::Action), + MultiActions(Vec), } #[derive(Debug, Clone, Deserialize, Serialize)] diff --git a/src/rule/mod.rs b/src/rule/mod.rs index ace9a65..9176af4 100644 --- a/src/rule/mod.rs +++ b/src/rule/mod.rs @@ -36,7 +36,10 @@ impl From for Rule { }; Self { filter, - action: rule.action, + action: match rule.action { + file::Actions::Action(action) => vec![action], + file::Actions::MultiActions(actions) => actions, + }, url: None, } }