feat: log analysis
Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
026d4cb607
commit
c6f4295d6a
18 changed files with 487 additions and 20 deletions
25
src/handlers/event/analyze_logs/providers/mclogs.rs
Normal file
25
src/handlers/event/analyze_logs/providers/mclogs.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use crate::api::REQWEST_CLIENT;
|
||||
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"https://mclo\.gs/(\w+)").unwrap());
|
||||
|
||||
pub async fn find(content: &str) -> Result<Option<String>> {
|
||||
let Some(captures) = REGEX.captures(content) else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let url = format!("https://api.mclo.gs/1/raw/{}", &captures[1]);
|
||||
let request = REQWEST_CLIENT.get(&url).build()?;
|
||||
let response = REQWEST_CLIENT.execute(request).await?;
|
||||
let status = response.status();
|
||||
|
||||
if let StatusCode::OK = status {
|
||||
Ok(Some(response.text().await?))
|
||||
} else {
|
||||
Err(eyre!("Failed to fetch log from {url} with {status}"))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue