Skip to content

Commit

Permalink
Remove tracking closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnsAnns committed Sep 20, 2023
1 parent ebdbb2f commit db0a9d2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ members = [
resolver = "2"

[workspace.package]
version = "6.2.0"
version = "6.3.0"
authors = ["AnnsAnn"]
4 changes: 3 additions & 1 deletion sphene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ impl EventHandler for Handler {
let options: Vec<CreateSelectMenuOption>;

if twitter::is_twitter_url(content.as_str()) {
url = twitter::convert_url_lazy(content, twitter::UrlType::Vxtwitter).await;
url = twitter::remove_tracking(
twitter::convert_url_lazy(content, twitter::UrlType::Vxtwitter).await,
);
options = self.options_twitter.clone();
} else if bluesky::is_bluesky_url(content.as_str()) {
url = bluesky::convert_url_lazy(content, bluesky::UrlType::FixBluesky).await;
Expand Down
23 changes: 23 additions & 0 deletions thorium/src/twitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ impl UrlType {
}
}

pub fn remove_tracking(url: String) -> String {
let mut new_url = String::new();
for word in url.split_whitespace() {
if word.contains('?') && word.contains('=') {
let url: &str;
if !word.starts_with("https://") && word.contains("https://") {
let split = word.split_once("https://").unwrap();
url = split.1;
new_url.push_str(split.0);
new_url.push(' ');
new_url.push_str("https://");
} else {
url = word.split_once('?').unwrap().0;
}
new_url.push_str(url);
} else {
new_url.push_str(word);
}
new_url.push(' ');
}
new_url.trim().to_string()
}

pub async fn convert_url(url: String, from: UrlType, to: UrlType) -> String {
url.replace(from.as_str(), to.as_str())
}
Expand Down

0 comments on commit db0a9d2

Please sign in to comment.