Skip to content

Commit

Permalink
Add regex dependency and implement fix_rss function to clean up RSS f…
Browse files Browse the repository at this point in the history
…eed content
  • Loading branch information
nullchinchilla committed Nov 17, 2024
1 parent 0cbac8a commit bbf6234
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
19 changes: 10 additions & 9 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ tmelcrypt = "0.2.7"
sosistab2 = "0.8.16"
http = "0.2"
governor = "0.6.3"
regex = "1.11.1"


[target.'cfg(not(target_env = "msvc"))'.dependencies]
Expand Down
14 changes: 12 additions & 2 deletions src/bindercore_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ impl BinderCoreV2 {

/// Gets announcements.
pub async fn get_announcements(&self) -> String {
self.announcements_cache
let s = self
.announcements_cache
.try_get_with((), async {
let resp = reqwest::get("https://rsshub.app/telegram/channel/gephannounce_mirror")
.compat()
Expand All @@ -897,7 +898,8 @@ impl BinderCoreV2 {
anyhow::Ok(String::from_utf8_lossy(&bts).to_string())
})
.await
.unwrap_or_else(|_| "Failed to fetch announcements".to_string())
.unwrap_or_else(|_| "Failed to fetch announcements".to_string());
fix_rss(&s)
}

async fn get_user_id(&self, credentials: &Credentials) -> Result<Option<i32>, sqlx::Error> {
Expand Down Expand Up @@ -978,6 +980,14 @@ impl BinderCoreV2 {
}
}

fn fix_rss(text: &str) -> String {
// Regular expression to match the forwarded pattern
let re = regex::Regex::new(r"<p>Forwarded[^<]*</p>").unwrap();

// Replace all matched patterns with empty string
re.replace_all(text.trim(), "").to_string()
}

/// Verify a captcha.
async fn verify_captcha(
captcha_service: &str,
Expand Down

0 comments on commit bbf6234

Please sign in to comment.