mirror of
https://github.com/v0l/route96.git
synced 2025-06-20 07:10:30 +00:00
feat: swap ureq for reqwest
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
use anyhow::Error;
|
||||
use reqwest::{Client, ClientBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::filesystem::FileSystemResult;
|
||||
|
||||
pub struct Webhook {
|
||||
url: String,
|
||||
client: Client,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@ -16,19 +18,26 @@ struct WebhookRequest<T> {
|
||||
|
||||
impl Webhook {
|
||||
pub fn new(url: String) -> Self {
|
||||
Self { url }
|
||||
Self {
|
||||
url,
|
||||
client: ClientBuilder::new().build().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Ask webhook api if this file can be accepted
|
||||
pub fn store_file(&self, pubkey: &Vec<u8>, fs: FileSystemResult) -> Result<bool, Error> {
|
||||
pub async fn store_file(&self, pubkey: &Vec<u8>, fs: FileSystemResult) -> Result<bool, Error> {
|
||||
let body: WebhookRequest<FileSystemResult> = WebhookRequest {
|
||||
action: "store_file".to_string(),
|
||||
subject: Some(hex::encode(pubkey)),
|
||||
payload: fs,
|
||||
};
|
||||
let req = ureq::post(&self.url)
|
||||
.set("accept", "application/json")
|
||||
.send_json(body)?;
|
||||
let req = self
|
||||
.client
|
||||
.post(&self.url)
|
||||
.header("accept", "application/json")
|
||||
.json(&body)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if req.status() == 200 {
|
||||
Ok(true)
|
||||
|
Reference in New Issue
Block a user