mirror of
https://github.com/block/buzz.git
synced 2026-10-31 22:41:12 +00:00
fix(relay): reject failed local event writes
Signed-off-by: npub13n66s06epmqf2kc3v373ez8hj65cuzyvxzjf93vwpervxqn2u7jq2qd9je <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
This commit is contained in:
committed by
Brother Darryl
parent
30df44197a
commit
9a800d6d7e
@@ -140,13 +140,18 @@ async fn serve_socket(socket: WebSocket, state: LocalState) {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let inserted = sqlx::query("INSERT OR IGNORE INTO events (id, event_json) VALUES (?, ?)")
|
||||
let inserted = match sqlx::query("INSERT OR IGNORE INTO events (id, event_json) VALUES (?, ?)")
|
||||
.bind(&id)
|
||||
.bind(event_json)
|
||||
.execute(&state.db)
|
||||
.await
|
||||
.map(|result| result.rows_affected() == 1)
|
||||
.unwrap_or(false);
|
||||
{
|
||||
Ok(result) => result.rows_affected() == 1,
|
||||
Err(error) => {
|
||||
let _ = tx.send(Message::Text(RelayMessage::ok(&id, false, &format!("error: {error}")).into())).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if inserted { let _ = state.fanout.send(event); }
|
||||
let _ = tx.send(Message::Text(RelayMessage::ok(&id, true, if inserted { "" } else { "duplicate" }).into())).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user