Skip to content

Commit 102388e

Browse files
delcin-rajyukibtc
authored andcommitted
blossom: fix url serialization
This was identified when working with whitenoise [pr](parres-hq/whitenoise#237) Pull-Request: #956 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 1d6d47d commit 102388e

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

rfs/nostr-blossom/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
2424
-->
2525

26+
## Unreleased
27+
28+
### Fixed
29+
30+
- blossom: fix url serialization (https://github.com/rust-nostr/nostr/pull/956)
31+
2632
## v0.42.0 - 2025/05/20
2733

2834
First release.

rfs/nostr-blossom/src/client.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl BlossomClient {
5959
where
6060
T: NostrSigner,
6161
{
62-
let url = format!("{}/upload", self.base_url);
62+
let url: Url = self.base_url.join("upload")?;
6363

6464
let hash: Sha256Hash = Sha256Hash::hash(&data);
6565
let file_hashes: Vec<Sha256Hash> = vec![hash];
@@ -111,20 +111,16 @@ impl BlossomClient {
111111
where
112112
T: NostrSigner,
113113
{
114-
let mut url = format!("{}/list/{}", self.base_url, pubkey.to_hex());
115-
116-
let mut query_params = Vec::new();
114+
let mut url: Url = self.base_url.join("list")?.join(&pubkey.to_hex())?;
117115

118116
if let Some(since) = since {
119-
query_params.push(format!("since=\"{}\"", since));
117+
url.query_pairs_mut()
118+
.append_pair("since", since.to_string().as_str());
120119
}
121120

122121
if let Some(until) = until {
123-
query_params.push(format!("until=\"{}\"", until));
124-
}
125-
126-
if !query_params.is_empty() {
127-
url.push_str(&format!("?{}", query_params.join("&")));
122+
url.query_pairs_mut()
123+
.append_pair("until", until.to_string().as_str());
128124
}
129125

130126
let mut request = self.client.get(url);
@@ -169,7 +165,8 @@ impl BlossomClient {
169165
where
170166
T: NostrSigner,
171167
{
172-
let url = format!("{}/{}", self.base_url, sha256);
168+
let url: Url = self.base_url.join(sha256.to_string().as_str())?;
169+
173170
let mut request = self.client.get(url);
174171
let mut headers = HeaderMap::new();
175172

@@ -224,7 +221,7 @@ impl BlossomClient {
224221
where
225222
T: NostrSigner,
226223
{
227-
let url = format!("{}/{}", self.base_url, sha256);
224+
let url: Url = self.base_url.join(sha256.to_string().as_str())?;
228225

229226
let mut request = self.client.head(url);
230227

@@ -267,7 +264,7 @@ impl BlossomClient {
267264
where
268265
T: NostrSigner,
269266
{
270-
let url = format!("{}/{}", self.base_url, sha256);
267+
let url: Url = self.base_url.join(sha256.to_string().as_str())?;
271268

272269
let mut headers = HeaderMap::new();
273270
let default_auth = self.default_auth(

rfs/nostr-blossom/src/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::fmt;
88

99
use nostr::event::builder;
1010
use nostr::signer::SignerError;
11+
use nostr::types::ParseError;
1112
use reqwest::header::{InvalidHeaderValue, ToStrError};
1213
use reqwest::Response;
1314

@@ -22,6 +23,8 @@ pub enum Error {
2223
Reqwest(reqwest::Error),
2324
/// Invalid header value
2425
InvalidHeaderValue(InvalidHeaderValue),
26+
/// Url parse error
27+
Url(ParseError),
2528
/// To string error
2629
ToStr(ToStrError),
2730
/// Response error
@@ -59,6 +62,7 @@ impl fmt::Display for Error {
5962
Self::EventBuilder(e) => write!(f, "{e}"),
6063
Self::Reqwest(e) => write!(f, "{e}"),
6164
Self::InvalidHeaderValue(e) => write!(f, "{e}"),
65+
Self::Url(e) => write!(f, "{e}"),
6266
Self::ToStr(e) => write!(f, "{e}"),
6367
Self::Response { prefix, res } => {
6468
let reason: &str = res
@@ -102,6 +106,12 @@ impl From<InvalidHeaderValue> for Error {
102106
}
103107
}
104108

109+
impl From<ParseError> for Error {
110+
fn from(e: ParseError) -> Self {
111+
Self::Url(e)
112+
}
113+
}
114+
105115
impl From<ToStrError> for Error {
106116
fn from(e: ToStrError) -> Self {
107117
Self::ToStr(e)

0 commit comments

Comments
 (0)