Skip to content

Commit

Permalink
fix http
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Jan 6, 2024
1 parent 556e325 commit 98840d4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn main() {
};


let server = Server::new(0,0,0,0,port,token, Webhook::new(disc_url));
let server = Server::new(0,0,0,0, port,token, Webhook::new(disc_url));

server.serve(cert_path, key_path).await;

Expand Down
46 changes: 44 additions & 2 deletions src/main_http.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "http")]
use pulse::server_http::serve;

use pulse::{server_http::ServerHttp, web::request::discord::model::Webhook};

#[cfg(feature = "http")]
#[tokio::main]
Expand Down Expand Up @@ -27,6 +28,47 @@ async fn main() {
std::process::exit(1);
};

serve(token).await;
let disc_url = if args.iter().any(|x| x == "-w")
{
let i = args.iter().position(|x| x == "-w").unwrap();
if i+1 < args.len()
{
args[i+1].clone()
}
else
{
println!("Discord webhook url not provided, please provide -w https://discord.com/api/webhooks/xxx/yyy");
std::process::exit(1);
}
}
else
{
println!("Discord webhook url not provided, please provide -w https://discord.com/api/webhooks/xxx/yyy");
std::process::exit(1);
};

let args: Vec<String> = std::env::args().collect();

let port = if args.iter().any(|x| x == "-p")
{
let i = args.iter().position(|x| x == "-p").unwrap();
if i+1 < args.len()
{
args[i+1].parse::<u16>().unwrap()
}
else
{
3030
}
}
else
{
3030
};


let server = ServerHttp::new(0,0,0,0, port,token, Webhook::new(disc_url));

server.serve().await;

}
44 changes: 10 additions & 34 deletions src/server_http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

use crate::web::throttle::{IpThrottler, handle_throttle};
use crate::web::response::util::{reflect, stdout_log};
use crate::web::response::github_verify::github_verify;
use crate::web::
{
throttle::{IpThrottler, handle_throttle},
response::github::{filter_github, GithubConfig},
request::discord::model::Webhook
};

use std::clone;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
Expand Down Expand Up @@ -30,7 +33,8 @@ impl ServerHttp
c: u8,
d: u8,
port: u16,
token: String
token: String,
disc: Webhook
)
-> ServerHttp
{
Expand All @@ -43,15 +47,14 @@ impl ServerHttp

let throttle_state = Arc::new(Mutex::new(requests));

let authenticated_state = token;

let github = GithubConfig::new(token, disc);

ServerHttp
{
addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(a,b,c,d)), port),
router: Router::new()
.route("/", post(|| async move { }))
.layer(middleware::from_fn_with_state(authenticated_state.clone(), github_verify))
.layer(middleware::from_fn_with_state(github, filter_github))
.layer(middleware::from_fn_with_state(throttle_state.clone(), handle_throttle))

}
Expand All @@ -70,31 +73,4 @@ impl ServerHttp
.unwrap();
}

}

pub async fn serve(token: String) {

let args: Vec<String> = std::env::args().collect();

let port = if args.iter().any(|x| x == "-p")
{
let i = args.iter().position(|x| x == "-p").unwrap();
if i+1 < args.len()
{
args[i+1].parse::<u16>().unwrap()
}
else
{
3030
}
}
else
{
3030
};

let server = ServerHttp::new(0,0,0,0,port,token);

server.serve().await

}

0 comments on commit 98840d4

Please sign in to comment.