Skip to content

Commit

Permalink
Fix report, rm unused response, test discord
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed May 5, 2024
1 parent 5234ffe commit 6773a61
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 139 deletions.
1 change: 0 additions & 1 deletion .github/workflows/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

entries = sorted(entries, key = lambda x: x[1])

print(covered, coverable)
this_coverage = round(100.0*covered/coverable, 2)

diff = None
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl ApiRequest for StatsDigest

if self.payload.post_discord
{
match post(config.notification_endpoint, msg.clone()).await
match post(&config.notification_endpoint, msg.clone()).await
{
Ok(_s) => (),
Err(e) => {crate::debug(format!("Error posting to discord\n{}", e), None);}
Expand Down
4 changes: 2 additions & 2 deletions src/web/discord/request/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl Webhook
Webhook { addr: url }
}

pub fn get_addr(self: Webhook) -> String
pub fn get_addr(&self) -> String
{
self.addr
self.addr.clone()
}
}
6 changes: 3 additions & 3 deletions src/web/discord/request/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::web::discord::request::model::Webhook;
///
/// pub async fn post_to_discord(){
/// let w = Webhook::new("https://discord.com/api/webhooks/xxx/yyy".to_string());
/// post(w, "this is some plaintext".to_string());
/// post(&w, "this is some plaintext".to_string());
/// }
/// ```
///
Expand All @@ -34,7 +34,7 @@ use crate::web::discord::request::model::Webhook;
/// {"content": "this is some plaintext"}
/// ```
pub async fn post(w: Webhook, msg: String) -> Result<String, reqwest::Error>
pub async fn post(w: &Webhook, msg: String) -> Result<String, reqwest::Error>
{

crate::debug(format!("Posting to Discord {:?}", msg), None);
Expand All @@ -43,7 +43,7 @@ pub async fn post(w: Webhook, msg: String) -> Result<String, reqwest::Error>
let mut map = HashMap::new();
map.insert("content", &msg);

match client.post(&w.get_addr())
match client.post(w.clone().get_addr())
.json(&map)
.send()
.await
Expand Down
1 change: 0 additions & 1 deletion src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use regex::Regex;
use crate::util::{read_bytes, dump_bytes};

pub mod throttle;
pub mod response;
pub mod discord;
pub mod stats;

Expand Down
1 change: 0 additions & 1 deletion src/web/response/mod.rs

This file was deleted.

128 changes: 0 additions & 128 deletions src/web/response/util.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/web/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl Stats
{
stats.summary = Self::process_hits(stats_config.path.clone(), Some(stats.last_digest), None, stats_config.top_n_digest, Some(stats.to_owned()));
let msg = Stats::digest_message(stats.summary.clone(), Some(stats.last_digest), None);
match post(config.notification_endpoint, msg).await
match post(&config.notification_endpoint, msg).await
{
Ok(_s) => (),
Err(e) => {crate::debug(format!("Error posting to discord\n{}", e), None);}
Expand Down
2 changes: 1 addition & 1 deletion src/web/throttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::net::{SocketAddr, Ipv4Addr, IpAddr};
use std::time::{Instant, Duration};
use std::sync::Arc;
use openssl::sha::{self, sha512};
use openssl::sha::sha512;
use tokio::sync::Mutex;

use axum::
Expand Down
18 changes: 18 additions & 0 deletions tests/test_discord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod common;

#[cfg(test)]
mod discord
{
use busser::web::discord::request::{model::Webhook, post::post};


#[tokio::test]
async fn test_webhook()
{
let w = Webhook::new("https://discord.com/api/webhooks/xxx/yyy".to_string());

assert_eq!(w.get_addr(), "https://discord.com/api/webhooks/xxx/yyy");

assert!(post(&w, "400".to_string()).await.is_ok());
}
}

0 comments on commit 6773a61

Please sign in to comment.