@@ -25,18 +25,15 @@ use crate::error::Error;
25
25
/// <https://github.com/hzrd149/blossom>
26
26
#[ derive( Debug , Clone ) ]
27
27
pub struct BlossomClient {
28
- base_url : String ,
28
+ base_url : Url ,
29
29
client : reqwest:: Client ,
30
30
}
31
31
32
32
impl BlossomClient {
33
33
/// Creates a new `BlossomClient` with the given base URL.
34
- pub fn new < T > ( base_url : T ) -> Self
35
- where
36
- T : Into < String > ,
37
- {
34
+ pub fn new ( base_url : Url ) -> Self {
38
35
Self {
39
- base_url : base_url . into ( ) ,
36
+ base_url,
40
37
client : Self :: build_client ( ) . unwrap ( ) ,
41
38
}
42
39
}
@@ -67,7 +64,7 @@ impl BlossomClient {
67
64
let hash: Sha256Hash = Sha256Hash :: hash ( & data) ;
68
65
let file_hashes: Vec < Sha256Hash > = vec ! [ hash] ;
69
66
70
- let mut request = self . client . put ( & url) . body ( data) ;
67
+ let mut request = self . client . put ( url) . body ( data) ;
71
68
let mut headers = HeaderMap :: new ( ) ;
72
69
73
70
if let Some ( ct) = content_type {
@@ -130,16 +127,14 @@ impl BlossomClient {
130
127
url. push_str ( & format ! ( "?{}" , query_params. join( "&" ) ) ) ;
131
128
}
132
129
133
- let mut request = self . client . get ( & url) ;
130
+ let mut request = self . client . get ( url) ;
134
131
let mut headers = HeaderMap :: new ( ) ;
135
132
136
133
if let Some ( signer) = signer {
137
- // TODO: change self.base_url type to Url
138
- let url = Url :: parse ( & self . base_url ) . unwrap ( ) ;
139
134
let default_auth = self . default_auth (
140
135
BlossomAuthorizationVerb :: List ,
141
136
"Blossom list authorization" ,
142
- BlossomAuthorizationScope :: ServerUrl ( url ) ,
137
+ BlossomAuthorizationScope :: ServerUrl ( self . base_url . clone ( ) ) ,
143
138
) ;
144
139
let final_auth = authorization_options
145
140
. map ( |opts| Self :: update_authorization_fixture ( & default_auth, opts) )
@@ -175,7 +170,7 @@ impl BlossomClient {
175
170
T : NostrSigner ,
176
171
{
177
172
let url = format ! ( "{}/{}" , self . base_url, sha256) ;
178
- let mut request = self . client . get ( & url) ;
173
+ let mut request = self . client . get ( url) ;
179
174
let mut headers = HeaderMap :: new ( ) ;
180
175
181
176
if let Some ( range_value) = range {
@@ -231,7 +226,7 @@ impl BlossomClient {
231
226
{
232
227
let url = format ! ( "{}/{}" , self . base_url, sha256) ;
233
228
234
- let mut request = self . client . head ( & url) ;
229
+ let mut request = self . client . head ( url) ;
235
230
236
231
if let Some ( signer) = signer {
237
232
let default_auth = self . default_auth (
@@ -288,7 +283,7 @@ impl BlossomClient {
288
283
let auth_header = Self :: build_auth_header ( signer, & final_auth) . await ?;
289
284
headers. insert ( AUTHORIZATION , auth_header) ;
290
285
291
- let response: Response = self . client . delete ( & url) . headers ( headers) . send ( ) . await ?;
286
+ let response: Response = self . client . delete ( url) . headers ( headers) . send ( ) . await ?;
292
287
293
288
if response. status ( ) . is_success ( ) {
294
289
Ok ( ( ) )
0 commit comments