mirror of
https://github.com/etiennecollin/unifi-voucher-manager.git
synced 2025-11-03 05:23:30 +00:00
fix: URL encoding for API request
This commit is contained in:
5
backend/Cargo.lock
generated
5
backend/Cargo.lock
generated
@@ -115,6 +115,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
|
"percent-encoding",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -929,9 +930,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf"
|
name = "phf"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ axum = "0.8.4"
|
|||||||
chrono = { version = "0.4.41" }
|
chrono = { version = "0.4.41" }
|
||||||
chrono-tz = "0.10.4"
|
chrono-tz = "0.10.4"
|
||||||
dotenvy = { version = "0.15.7", optional = true }
|
dotenvy = { version = "0.15.7", optional = true }
|
||||||
|
percent-encoding = "2.3.2"
|
||||||
reqwest = { version = "0.12.22", features = ["json", "rustls-tls"] }
|
reqwest = { version = "0.12.22", features = ["json", "rustls-tls"] }
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.141"
|
serde_json = "1.0.141"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use axum::http::HeaderValue;
|
use axum::http::HeaderValue;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
use percent_encoding::{AsciiSet, CONTROLS, utf8_percent_encode};
|
||||||
use reqwest::{Client, ClientBuilder, StatusCode};
|
use reqwest::{Client, ClientBuilder, StatusCode};
|
||||||
use std::{sync::OnceLock, time::Duration};
|
use std::{sync::OnceLock, time::Duration};
|
||||||
use tracing::{debug, error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
@@ -15,6 +16,7 @@ use crate::{
|
|||||||
const UNIFI_API_ROUTE: &str = "proxy/network/integration/v1/sites";
|
const UNIFI_API_ROUTE: &str = "proxy/network/integration/v1/sites";
|
||||||
const DATE_TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
|
const DATE_TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
|
||||||
const ROLLING_VOUCHER_NAME_PREFIX: &str = "[ROLLING]";
|
const ROLLING_VOUCHER_NAME_PREFIX: &str = "[ROLLING]";
|
||||||
|
const FRAGMENT: &AsciiSet = &CONTROLS.add(b'[').add(b']');
|
||||||
|
|
||||||
pub static UNIFI_API: OnceLock<UnifiAPI> = OnceLock::new();
|
pub static UNIFI_API: OnceLock<UnifiAPI> = OnceLock::new();
|
||||||
|
|
||||||
@@ -359,7 +361,8 @@ impl<'a> UnifiAPI<'a> {
|
|||||||
pub async fn delete_expired_rolling_vouchers(&self) -> Result<DeleteResponse, StatusCode> {
|
pub async fn delete_expired_rolling_vouchers(&self) -> Result<DeleteResponse, StatusCode> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}?filter=and(expired.eq(true),name.like('{}*'))",
|
"{}?filter=and(expired.eq(true),name.like('{}*'))",
|
||||||
self.voucher_api_url, ROLLING_VOUCHER_NAME_PREFIX
|
self.voucher_api_url,
|
||||||
|
utf8_percent_encode(ROLLING_VOUCHER_NAME_PREFIX, FRAGMENT)
|
||||||
);
|
);
|
||||||
self.make_request(RequestType::Delete, &url, None::<&()>)
|
self.make_request(RequestType::Delete, &url, None::<&()>)
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user