fix: URL encoding for API request

This commit is contained in:
etiennecollin
2025-09-07 12:22:01 -04:00
parent ce6c92edf4
commit c9e85d5172
3 changed files with 8 additions and 3 deletions

5
backend/Cargo.lock generated
View File

@@ -115,6 +115,7 @@ dependencies = [
"chrono",
"chrono-tz",
"dotenvy",
"percent-encoding",
"reqwest",
"serde",
"serde_json",
@@ -929,9 +930,9 @@ dependencies = [
[[package]]
name = "percent-encoding"
version = "2.3.1"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]]
name = "phf"

View File

@@ -8,6 +8,7 @@ axum = "0.8.4"
chrono = { version = "0.4.41" }
chrono-tz = "0.10.4"
dotenvy = { version = "0.15.7", optional = true }
percent-encoding = "2.3.2"
reqwest = { version = "0.12.22", features = ["json", "rustls-tls"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"

View File

@@ -1,5 +1,6 @@
use axum::http::HeaderValue;
use chrono::DateTime;
use percent_encoding::{AsciiSet, CONTROLS, utf8_percent_encode};
use reqwest::{Client, ClientBuilder, StatusCode};
use std::{sync::OnceLock, time::Duration};
use tracing::{debug, error, info, warn};
@@ -15,6 +16,7 @@ use crate::{
const UNIFI_API_ROUTE: &str = "proxy/network/integration/v1/sites";
const DATE_TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";
const ROLLING_VOUCHER_NAME_PREFIX: &str = "[ROLLING]";
const FRAGMENT: &AsciiSet = &CONTROLS.add(b'[').add(b']');
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> {
let url = format!(
"{}?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::<&()>)
.await