mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add control give & control take endpoints.
This commit is contained in:
parent
6d27b0a69c
commit
6fbb1a2cc7
@ -9,6 +9,10 @@ import (
|
||||
"demodesk/neko/internal/http/auth"
|
||||
)
|
||||
|
||||
type ControlGivePayload struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ControlRequest(w http.ResponseWriter, r *http.Request) {
|
||||
session := auth.GetSession(r)
|
||||
if session.IsHost() {
|
||||
@ -50,3 +54,40 @@ func (h *RoomHandler) ControlRelease(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ControlTake(w http.ResponseWriter, r *http.Request) {
|
||||
session := auth.GetSession(r)
|
||||
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) ControlGive(w http.ResponseWriter, r *http.Request) {
|
||||
data := &ControlGivePayload{}
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
return
|
||||
}
|
||||
|
||||
target, ok := h.sessions.Get(data.ID)
|
||||
if !ok {
|
||||
utils.HttpBadRequest(w, "Target user was not found.")
|
||||
return
|
||||
}
|
||||
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: target.ID(),
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
@ -50,5 +50,8 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
r.Route("/control", func(r chi.Router) {
|
||||
r.Post("/request", h.ControlRequest)
|
||||
r.Post("/release", h.ControlRelease)
|
||||
|
||||
r.With(auth.AdminsOnly).Post("/take", h.ControlTake)
|
||||
r.With(auth.AdminsOnly).Post("/give", h.ControlGive)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user