format-sse-fix

This commit is contained in:
Untone 2023-10-20 20:50:26 +03:00
parent 5cf79bf531
commit 85502a694d

View File

@ -141,16 +141,12 @@ async fn connect_handler(
match result {
Ok(server_event) => {
let message_data: SSEMessageData = serde_json::from_str(&server_event).unwrap();
let event_entity = message_data.entity; // Assuming 'entity' field represents the entity type
let event_action = message_data.action; // 'action' field represents the operation type
let event_id = format!("{}", Uuid::new_v4()); // Generate a random UUID as the event ID
let formatted_server_event = format!(
"id: {}\nevent: {}\ndata: {{\"action\": \"{}\", \"payload\": {}}}\n\n",
"id: {}\ndata: {}\n\n",
event_id,
event_entity,
event_action,
server_event
message_data
);
Some((Ok::<_, actix_web::Error>(Bytes::from(formatted_server_event)), rx))