Skip to content

Commit

Permalink
loading pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Jan 25, 2024
1 parent a254dbd commit 3f84295
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 45 deletions.
9 changes: 0 additions & 9 deletions bt/app/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,6 @@ namespace bt {
cfg.commit();
}

bool config::get_unshort_enabled() {
return cfg.get_bool_value(UnshortEnabledKey, true);
}

void config::set_unshort_enabled(bool enabled) {
cfg.set_bool_value(UnshortEnabledKey, enabled);
cfg.commit();
}

std::vector<std::string> config::get_pipeline() {
return cfg.get_all_values(PipelineStepKeyName, PipelineSectionName);
}
Expand Down
4 changes: 0 additions & 4 deletions bt/app/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ namespace bt {
bool get_show_hidden_browsers();
void set_show_hidden_browsers(bool show);

// todo: delete
bool get_unshort_enabled();
void set_unshort_enabled(bool enabled);

std::vector<std::string> get_pipeline();
void set_pipeline(const std::vector<std::string>& steps);

Expand Down
6 changes: 0 additions & 6 deletions bt/app/config_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ namespace bt
mi_log_rule_hits->is_selected = log_rule_hits;

mi_settings->add("", "-");
auto mi_cu = mi_settings->add("unshort", "Enable URL Un-Shortener", ICON_FA_SHIRT);
mi_cu->is_selected = g_config.get_unshort_enabled();
mi_settings->add("pipeline_config", "Configure URL pipeline", ICON_FA_BOLT);

// HELP
Expand Down Expand Up @@ -553,10 +551,6 @@ special keyword - %url% which is replaced by opening url.)";
} else if(mi.id.starts_with("mi_ff_mode_")) {
string name = mi.id.substr(11);
update_firefox_mode(true, config::to_firefox_container_mode(name));
} else if(mi.id == "unshort") {
mi.is_selected = !mi.is_selected;
g_config.set_unshort_enabled(mi.is_selected);
g_pipeline.load();
} else if(mi.id == "pipeline_config") {
bt::ui::url_pipeline();
}
Expand Down
5 changes: 5 additions & 0 deletions bt/app/pipeline/replacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ using namespace std;

namespace bt::pipeline {

replacer::replacer(replacer_kind kind, const std::string& find, const std::string& replace) :
url_pipeline_step{url_pipeline_step_type::find_replace},
kind{kind}, find{find}, replace{replace} {
}

replacer::replacer(const std::string& rule) : url_pipeline_step(url_pipeline_step_type::find_replace) {
// parse rules - each string contains 3 parts separated by a pipe
// kind|match|replace
Expand Down
2 changes: 2 additions & 0 deletions bt/app/pipeline/replacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ namespace bt::pipeline {
std::string find;
std::string replace;

replacer(replacer_kind kind, const std::string& find, const std::string& replace);
replacer(const std::string& rule);


// Inherited via url_pipeline_step
void process(url_payload& up) override;

Expand Down
34 changes: 17 additions & 17 deletions bt/app/pipeline/unshortener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ namespace bt::pipeline {

const string LocationHeaderName = "Location";

const set<string> SupportedDomains = {
"bit.ly",
"rebrand.ly",
"bl.ink",
"zapier.com",
"short.io",
"ow.ly",
"linktr.ee",
"t2m.io",
"linkjoy.io",
"geni.us",
"pxlme.me",
"rb.gy",
"snip.ly",
"tinyurl.com", "tiny.one",
"vrch.at"
};
const set<string> SupportedDomains = {
"bit.ly",
"rebrand.ly",
"bl.ink",
"zapier.com",
"short.io",
"ow.ly",
"linktr.ee",
"t2m.io",
"linkjoy.io",
"geni.us",
"pxlme.me",
"rb.gy",
"snip.ly",
"tinyurl.com", "tiny.one",
"vrch.at"
};

void unshortener::process(url_payload& up) {

Expand Down
28 changes: 21 additions & 7 deletions bt/app/url_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,28 @@ namespace bt {
void url_pipeline::load() {
steps.clear();

steps.push_back(make_shared<bt::pipeline::o365>());
vector<string> steps_str = cfg.get_pipeline();
for(const string& step_str : steps_str) {
vector<string> parts = str::split_pipe(step_str);
if(parts.size() < 1)
continue;

if(cfg.get_unshort_enabled()) {
steps.push_back(make_shared<bt::pipeline::unshortener>());
}
string name = parts[0];

//auto replacer_rules = cfg.get_pipeline_replacement_rules();
steps.push_back(make_shared<bt::pipeline::replacer>(""));
if(name == "o365") {
steps.push_back(make_shared<bt::pipeline::o365>());
} else if(name == "unshorten") {
steps.push_back(make_shared<bt::pipeline::unshortener>());
} else if(name == "find_replace") {
if(parts.size() < 4)
continue;
steps.push_back(make_shared<bt::pipeline::replacer>(
parts[1] == "rgx"
? bt::pipeline::replacer_kind::find_replace : bt::pipeline::replacer_kind::find_replace,
parts[2],
parts[3]));
}
}
}

void url_pipeline::save() {
Expand All @@ -58,7 +72,7 @@ namespace bt {
std::shared_ptr<bt::pipeline::replacer> replacer_step = std::static_pointer_cast<bt::pipeline::replacer>(step);
steps_str.push_back(str::join_with_pipe({
"find_replace",
replacer_step->kind == bt::pipeline::replacer_kind::find_replace ? "substring" : "regex",
replacer_step->kind == bt::pipeline::replacer_kind::find_replace ? "substr" : "rgx",
replacer_step->find,
replacer_step->replace
}));
Expand Down
1 change: 0 additions & 1 deletion bt/bt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void CALLBACK KeepAliveTimerProc(HWND hwnd, UINT message, UINT_PTR idTimer, DWOR
{"event", "ping"},
{"log_rule_hits", g_config.get_log_rule_hits() ? "y" : "n"},
{"theme", g_config.get_theme()},
{"unshort", g_config.get_unshort_enabled() ? "y" : "n"},
{"browsers_total", std::to_string(bt::browser::get_cache().size())}
}, true);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### New features

- Introducing a new type of link pre-processing - **replacement rules**. BT now allows you to to define custom find and replace rules on URLs before applying rules to them. Simple strings and regular expressions are supported. Read more about this (todo: add link).
- Introducing **URL Pipeline**. BT now allows you to to define custom find and replace rules on URLs before applying rules to them. Simple strings and regular expressions are supported. Read more about this (todo: add link).

## Improvements

Expand Down

0 comments on commit 3f84295

Please sign in to comment.