mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-21 16:59:06 -05:00
feat: parse subscription close requests from websockets
This commit is contained in:
parent
e7d0ab1aca
commit
35ceb7cb64
22
src/close.rs
Normal file
22
src/close.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use crate::error::{Error, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||
pub struct Close {
|
||||
cmd: String,
|
||||
id: String,
|
||||
}
|
||||
|
||||
impl Close {
|
||||
pub fn parse(json: &str) -> Result<Close> {
|
||||
let c: Close = serde_json::from_str(json)?; //.map_err(|e| Error::JsonParseFailed(e));
|
||||
if c.cmd != "CLOSE" {
|
||||
return Err(Error::CloseParseFailed);
|
||||
}
|
||||
return Ok(c);
|
||||
}
|
||||
|
||||
pub fn get_id(&self) -> String {
|
||||
self.id.clone()
|
||||
}
|
||||
}
|
|
@ -14,10 +14,13 @@ pub enum Error {
|
|||
ConnError,
|
||||
#[error("Client write error")]
|
||||
ConnWriteError,
|
||||
#[error("Event parse failed")]
|
||||
#[error("EVENT parse failed")]
|
||||
EventParseFailed,
|
||||
#[error("ClOSE message parse failed")]
|
||||
CloseParseFailed,
|
||||
#[error("Event validation failed")]
|
||||
EventInvalid,
|
||||
// this should be used if the JSON is invalid
|
||||
#[error("JSON parsing failed")]
|
||||
JsonParseFailed(serde_json::Error),
|
||||
#[error("WebSocket proto error")]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod conn;
|
||||
pub mod error;
|
||||
pub mod event;
|
||||
pub mod protostream;
|
||||
pub mod event;
|
||||
pub mod subscription;
|
||||
pub mod close;
|
||||
pub mod error;
|
||||
|
|
|
@ -82,9 +82,11 @@ async fn nostr_server(
|
|||
}
|
||||
},
|
||||
Some(Ok(SubMsg(s))) => {
|
||||
info!("Sub request from client: {:?}", s);
|
||||
info!("Sub-open request from client: {:?}", s);
|
||||
},
|
||||
Some(Ok(CloseMsg(c))) => {
|
||||
info!("Sub-close request from client: {:?}", c);
|
||||
},
|
||||
Some(Ok(CloseMsg)) => {},
|
||||
None => {
|
||||
info!("stream ended");
|
||||
//conn_good = true;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::close::Close;
|
||||
use crate::error::{Error, Result};
|
||||
use crate::event::EventCmd;
|
||||
use crate::subscription::Subscription;
|
||||
|
@ -19,7 +20,7 @@ use tungstenite::protocol::Message;
|
|||
pub enum NostrMessage {
|
||||
EventMsg(EventCmd),
|
||||
SubMsg(Subscription),
|
||||
CloseMsg,
|
||||
CloseMsg(Close),
|
||||
}
|
||||
|
||||
// Either an event w/ subscription, or a notice
|
||||
|
|
Loading…
Reference in New Issue
Block a user