Closed MesterMan03 closed 1 year ago
API route update
/sse
now returns a SSE stream. This doesn't do much on its own, only sending a heartbeat ping every 15 seconds, but if you include ?test=something
at the end of the URL, it'll send a test alert every 10 seconds.
In JavaScript, you can read it like this:
const es = new EventSource("https://ucp-api.mester.info/sse?test=hi");
es.addEventListener("alert", (event) => {
const message = event.data;
// do something with it
});
The data is sent with JSON encoding, so you might want to JSON.parse()
it first.
API update
/sse
now returns an appeal
alert in production mode.
Closed in favour of #8
Goal: provide a one-directional (server -> client) way of sending alerts and other types of data, either real-time or async. Types
AlertType
= "appeal" | "punishment"AlertMessage<T extends AlertType>
=AlertData<"appeal">
(used for appeals that have been processed by the staff team) =AlertData<"punishment">
(used for new punishments, always in real-time) = same as the punishment object from/user/punishments
Example
Route changes
/user
may return a newalerts
field with typeAlertMessage<unknown>[]
when there are unread alerts./sse
returns a Server-Sent Events stream which may occasionally send aalert
event with aAlertMessage<unknown>
object.