Skip to content

Commit a913806

Browse files
committed
nostr: change TagStandard::Server variant inner value
Change the inner value of `TagStandard::Server` variant from `String` to `Url`. Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 55b20f1 commit a913806

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

crates/nostr-blossom/src/bud01.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt;
44

55
use nostr::hashes::sha256::Hash as Sha256Hash;
6-
use nostr::{EventBuilder, Kind, Tag, TagStandard, Timestamp};
6+
use nostr::{EventBuilder, Kind, Tag, TagStandard, Timestamp, Url};
77

88
/// Represents the authorization data for accessing a Blossom server.
99
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -45,7 +45,7 @@ pub enum BlossomAuthorizationScope {
4545
/// Authorizes access to blobs with the given SHA256 hashes.
4646
BlobSha256Hashes(Vec<Sha256Hash>),
4747
/// Authorizes access to the given server URL.
48-
ServerUrl(String),
48+
ServerUrl(Url),
4949
}
5050

5151
/// Represents the possible actions that can be authorized by a Blossom authorization event.

crates/nostr-blossom/src/client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use base64::Engine;
77
use nostr::hashes::sha256::Hash as Sha256Hash;
88
use nostr::hashes::Hash;
99
use nostr::signer::NostrSigner;
10-
use nostr::{Event, EventBuilder, JsonUtil, PublicKey, Timestamp};
10+
use nostr::{Event, EventBuilder, JsonUtil, PublicKey, Timestamp, Url};
1111
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE, RANGE};
1212
#[cfg(not(target_arch = "wasm32"))]
1313
use reqwest::redirect::Policy;
@@ -134,10 +134,12 @@ impl BlossomClient {
134134
let mut headers = HeaderMap::new();
135135

136136
if let Some(signer) = signer {
137+
// TODO: change self.base_url type to Url
138+
let url = Url::parse(&self.base_url).unwrap();
137139
let default_auth = self.default_auth(
138140
BlossomAuthorizationVerb::List,
139141
"Blossom list authorization",
140-
BlossomAuthorizationScope::ServerUrl(self.base_url.clone()),
142+
BlossomAuthorizationScope::ServerUrl(url),
141143
);
142144
let final_auth = authorization_options
143145
.map(|opts| Self::update_authorization_fixture(&default_auth, opts))

crates/nostr/src/event/tag/standard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub enum TagStandard {
188188
key: String,
189189
iv: String,
190190
},
191-
Server(String),
191+
Server(Url),
192192
Sha256(Sha256Hash),
193193
Size(usize),
194194
Dim(ImageDimensions),
@@ -427,7 +427,7 @@ impl TagStandard {
427427
TagKind::Title => Ok(Self::Title(tag_1.to_string())),
428428
TagKind::Image => Ok(Self::Image(Url::parse(tag_1)?, None)),
429429
TagKind::Thumb => Ok(Self::Thumb(Url::parse(tag_1)?, None)),
430-
TagKind::Server => Ok(Self::Server(tag_1.to_string())),
430+
TagKind::Server => Ok(Self::Server(Url::parse(tag_1)?)),
431431
TagKind::Summary => Ok(Self::Summary(tag_1.to_string())),
432432
TagKind::PublishedAt => Ok(Self::PublishedAt(Timestamp::from_str(tag_1)?)),
433433
TagKind::Description => Ok(Self::Description(tag_1.to_string())),
@@ -930,7 +930,7 @@ impl From<TagStandard> for Vec<String> {
930930
TagStandard::Url(url) => vec![tag_kind, url.to_string()],
931931
TagStandard::MimeType(mime) => vec![tag_kind, mime],
932932
TagStandard::Aes256Gcm { key, iv } => vec![tag_kind, key, iv],
933-
TagStandard::Server(url) => vec![tag_kind, url],
933+
TagStandard::Server(url) => vec![tag_kind, url.to_string()],
934934
TagStandard::Sha256(hash) => vec![tag_kind, hash.to_string()],
935935
TagStandard::Size(bytes) => vec![tag_kind, bytes.to_string()],
936936
TagStandard::Dim(dim) => vec![tag_kind, dim.to_string()],

0 commit comments

Comments
 (0)