feat: incorporated improvements from NIP-11 discussion

Change descr to description.  Add `id` for websocket URL.  Use
integers for supported NIPs instead of strings.  Top-level is object,
instead of the array before.
This commit is contained in:
Greg Heartsfield 2022-01-03 22:03:30 -05:00
parent 3024e9fba4
commit 2924da88bc
4 changed files with 21 additions and 16 deletions

View File

@ -1,10 +1,15 @@
# Nostr-rs-relay configuration
[info]
# The advertised URL for the Nostr websocket.
relay_url = "wss://nostr.example.com/"
# Relay information for clients. Put your unique server name here.
name = "nostr-rs-relay"
# Description
description = "A newly created nostr-rs-relay.\n\nCustomize this with your own info."
# Administrative contact pubkey
#pubkey = "0c2d168a4ae8ca58c9f1ab237b5df682599c6c7ab74307ea8b05684b60405d41"

View File

@ -11,9 +11,9 @@ lazy_static! {
#[derive(Debug, Serialize, Deserialize)]
#[allow(unused)]
pub struct Info {
pub relay_url: Option<String>,
pub name: Option<String>,
#[serde(rename = "description")]
pub descr: Option<String>,
pub description: Option<String>,
pub pubkey: Option<String>,
pub email: Option<String>,
}
@ -101,8 +101,9 @@ impl Default for Settings {
fn default() -> Self {
Settings {
info: Info {
relay_url: None,
name: Some("Unnamed nostr-rs-relay".to_owned()),
descr: None,
description: None,
pubkey: None,
email: None,
},

View File

@ -1,23 +1,24 @@
use crate::config;
/// Relay Info
use serde::{Deserialize, Serialize};
use serde_json::value::Value;
const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
#[derive(Debug, Serialize, Deserialize)]
#[allow(unused)]
pub struct RelayInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub descr: Option<String>,
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pubkey: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub supported_nips: Option<Vec<String>>,
pub supported_nips: Option<Vec<i64>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub software: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
@ -27,11 +28,12 @@ pub struct RelayInfo {
impl Default for RelayInfo {
fn default() -> Self {
RelayInfo {
id: None,
name: None,
descr: None,
description: None,
pubkey: None,
email: None,
supported_nips: Some(vec!["NIP-01".to_owned()]),
supported_nips: Some(vec![1]),
software: Some("https://git.sr.ht/~gheartsfield/nostr-rs-relay".to_owned()),
version: CARGO_PKG_VERSION.map(|x| x.to_owned()),
}
@ -43,8 +45,9 @@ pub fn relay_info_json(info: &config::Info) -> String {
// get a default RelayInfo
let mut r = RelayInfo::default();
// update fields from Info, if present
r.id = info.relay_url.clone();
r.name = info.name.clone();
r.descr = info.descr.clone();
r.description = info.description.clone();
r.pubkey = info.pubkey.clone();
r.email = info.email.clone();
r.to_json()
@ -52,10 +55,6 @@ pub fn relay_info_json(info: &config::Info) -> String {
impl RelayInfo {
pub fn to_json(self) -> String {
// create the info ARRAY
let mut info_arr: Vec<Value> = vec![];
info_arr.push(Value::String("NOSTR_SERVER_INFO".to_owned()));
info_arr.push(serde_json::to_value(&self).unwrap());
serde_json::to_string_pretty(&info_arr).unwrap()
serde_json::to_string_pretty(&self).unwrap()
}
}

View File

@ -119,9 +119,9 @@ async fn handle_web_request(
}
}
}
return Ok(Response::new(Body::from(
Ok(Response::new(Body::from(
"Please use a Nostr client to connect.",
)));
)))
}
(_, _) => {
//handle any other url