This commit is contained in:
Simon
2026-01-14 11:30:32 +00:00
parent cce6104df3
commit 602dbe50f0
4 changed files with 32 additions and 13 deletions

View File

@@ -28,6 +28,7 @@ rustc-hash = "2.1.1"
async-trait = "0.1" async-trait = "0.1"
regex = "1.12.2" regex = "1.12.2"
titlecase = "3.6.0" titlecase = "3.6.0"
dashmap = "6.1.0"
[lints.rust] [lints.rust]
unexpected_cfgs = "allow" unexpected_cfgs = "allow"

View File

@@ -212,7 +212,7 @@ impl HypnotubeProvider {
.await .await
.unwrap(); .unwrap();
if text.contains("Sorry, no results were found.") { if text.contains("Sorry, no results were found.") {
eprint!("Hypnotube query returned no results for page {}", page); eprintln!("Hypnotube query returned no results for page {}", page);
return vec![]; return vec![];
} }
let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone()).await; let video_items: Vec<VideoItem> = self.get_video_items_from_html(text.clone()).await;

View File

@@ -232,6 +232,7 @@ impl JavtifulProvider {
let futures = block let futures = block
.split("card ") .split("card ")
.skip(1) .skip(1)
.filter(|seg| !seg.contains("SPONSOR"))
.map(|el| self.get_video_item(el.to_string(), requester.clone())); .map(|el| self.get_video_item(el.to_string(), requester.clone()));
join_all(futures) join_all(futures)
@@ -278,7 +279,7 @@ impl JavtifulProvider {
.split(" alt=\"") .split(" alt=\"")
.nth(1) .nth(1)
.and_then(|s| s.split('"').next()) .and_then(|s| s.split('"').next())
.ok_or_else(|| ErrorKind::Parse("video title".into()))? .ok_or_else(|| ErrorKind::Parse(format!("video title\n\n{seg}").into()))?
.trim() .trim()
.to_string(); .to_string();

View File

@@ -1,11 +1,15 @@
use std::error::Error; use std::error::Error;
use std::fmt::Write as _; use std::fmt::Write as _;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use dashmap::DashMap;
use once_cell::sync::Lazy;
use serde_json::json; use serde_json::json;
use crate::util::requester; use crate::util::requester;
// Global cache: Map<ErrorSignature, LastSentTimestamp>
static ERROR_CACHE: Lazy<DashMap<String, u64>> = Lazy::new(DashMap::new);
const COOLDOWN_SECONDS: u64 = 3600; // 1 Hour cooldown
pub fn format_error_chain(err: &dyn Error) -> String { pub fn format_error_chain(err: &dyn Error) -> String {
let mut chain_str = String::new(); let mut chain_str = String::new();
let mut current_err: Option<&dyn Error> = Some(err); let mut current_err: Option<&dyn Error> = Some(err);
@@ -27,10 +31,29 @@ pub async fn send_discord_error_report(
line: u32, line: u32,
module: &str, module: &str,
) { ) {
// 1. Get Webhook from Environment let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
// --- Deduplication Logic ---
// Create a unique key based on error content and location
let error_signature = format!("{}-{}-{}", error_msg, file, line);
if let Some(last_sent) = ERROR_CACHE.get(&error_signature) {
if now - *last_sent < COOLDOWN_SECONDS {
// Error is still in cooldown, skip sending
return;
}
}
// Update the cache with the current timestamp
ERROR_CACHE.insert(error_signature, now);
// ---------------------------
let webhook_url = match std::env::var("DISCORD_WEBHOOK") { let webhook_url = match std::env::var("DISCORD_WEBHOOK") {
Ok(url) => url, Ok(url) => url,
Err(_) => return, // Exit silently if no webhook is configured Err(_) => return,
}; };
const MAX_FIELD: usize = 1024; const MAX_FIELD: usize = 1024;
@@ -42,11 +65,6 @@ pub async fn send_discord_error_report(
} }
}; };
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
let payload = json!({ let payload = json!({
"embeds": [{ "embeds": [{
"title": "🚨 Rust Error Report", "title": "🚨 Rust Error Report",
@@ -79,12 +97,11 @@ pub async fn send_discord_error_report(
} }
], ],
"footer": { "footer": {
"text": format!("Unix time: {}", timestamp) "text": format!("Unix time: {} | Cooldown active", now)
} }
}] }]
}); });
let mut requester = requester::Requester::new(); let mut requester = requester::Requester::new();
let _ = requester.post_json(&webhook_url, &payload, vec![]).await; let _ = requester.post_json(&webhook_url, &payload, vec![]).await;
println!("Error report sent.");
} }