feat: use custom isahc http client
This commit is contained in:
parent
c8baadefd5
commit
fc375711f3
|
@ -4057,8 +4057,7 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
|||
[[package]]
|
||||
name = "web-push"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5c5c6deab45e8820b77c9c8ae168f1ded4595767c746584bb67b9100f2b71d"
|
||||
source = "git+https://github.com/pimeys/rust-web-push?rev=40febe4085e3cef9cdfd539c315e3e945aba0656#40febe4085e3cef9cdfd539c315e3e945aba0656"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.13.1",
|
||||
|
|
|
@ -41,7 +41,7 @@ tracing = "0.1.40"
|
|||
tracing-subscriber = "0.3.18"
|
||||
url = "2.5.0"
|
||||
urlencoding = "2.1.3"
|
||||
web-push = "0.10.1"
|
||||
web-push = { git = "https://github.com/pimeys/rust-web-push", rev = "40febe4085e3cef9cdfd539c315e3e945aba0656" }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::database::db_conn;
|
|||
use crate::misc::get_note_summary::{get_note_summary, NoteLike};
|
||||
use crate::misc::meta::fetch_meta;
|
||||
use crate::model::entity::sw_subscription;
|
||||
use crate::util::http_client;
|
||||
use once_cell::sync::OnceCell;
|
||||
use sea_orm::{prelude::*, DbErr};
|
||||
use web_push::{
|
||||
|
@ -19,12 +20,16 @@ pub enum Error {
|
|||
SerializeErr(#[from] serde_json::Error),
|
||||
#[error("Invalid content: {0}")]
|
||||
InvalidContentErr(String),
|
||||
#[error("HTTP client aquisition error: {0}")]
|
||||
HttpClientErr(#[from] http_client::Error),
|
||||
}
|
||||
|
||||
static CLIENT: OnceCell<IsahcWebPushClient> = OnceCell::new();
|
||||
|
||||
fn get_client() -> Result<IsahcWebPushClient, WebPushError> {
|
||||
CLIENT.get_or_try_init(IsahcWebPushClient::new).cloned()
|
||||
fn get_client() -> Result<IsahcWebPushClient, Error> {
|
||||
Ok(CLIENT
|
||||
.get_or_try_init(|| http_client::client().map(|client| IsahcWebPushClient::from(client)))
|
||||
.cloned()?)
|
||||
}
|
||||
|
||||
#[derive(strum::Display, PartialEq)]
|
||||
|
|
Loading…
Reference in New Issue