mangadex-home-rs/src/stop.rs

33 lines
859 B
Rust
Raw Normal View History

2021-03-22 14:47:56 -07:00
use log::{info, warn};
2021-05-11 18:01:01 -07:00
use reqwest::StatusCode;
2021-03-22 14:47:56 -07:00
use serde::Serialize;
2021-07-09 16:48:25 -07:00
use crate::config::ClientSecret;
2021-03-22 14:47:56 -07:00
const CONTROL_CENTER_STOP_URL: &str = "https://api.mangadex.network/ping";
#[derive(Serialize)]
struct StopRequest<'a> {
2021-07-09 16:48:25 -07:00
secret: &'a ClientSecret,
2021-03-22 14:47:56 -07:00
}
2021-07-09 16:48:25 -07:00
pub async fn send_stop(secret: &ClientSecret) {
2021-03-22 14:47:56 -07:00
let request = StopRequest { secret };
let client = reqwest::Client::new();
match client
.post(CONTROL_CENTER_STOP_URL)
.json(&request)
.send()
.await
{
Ok(resp) => {
2021-05-11 18:01:01 -07:00
if resp.status() == StatusCode::OK {
2021-03-22 20:19:56 -07:00
info!("Successfully sent stop message to control center.");
2021-03-22 14:47:56 -07:00
} else {
warn!("Got weird response from server: {:?}", resp.headers());
}
}
Err(e) => warn!("Got error while sending stop message: {}", e),
}
2021-03-17 18:45:16 -07:00
}