mirror of
https://github.com/m1k1o/neko.git
synced 2025-08-02 00:10:07 +02:00
use custom logger.
This commit is contained in:
parent
5a7cdd31fe
commit
8d0fcbde70
15 changed files with 305 additions and 353 deletions
|
@ -18,82 +18,76 @@ type ControlTargetPayload struct {
|
|||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlStatus(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *RoomHandler) controlStatus(w http.ResponseWriter, r *http.Request) error {
|
||||
host := h.sessions.GetHost()
|
||||
|
||||
if host == nil {
|
||||
utils.HttpSuccess(w, ControlStatusPayload{
|
||||
HasHost: false,
|
||||
})
|
||||
} else {
|
||||
utils.HttpSuccess(w, ControlStatusPayload{
|
||||
if host != nil {
|
||||
return utils.HttpSuccess(w, ControlStatusPayload{
|
||||
HasHost: true,
|
||||
HostId: host.ID(),
|
||||
})
|
||||
}
|
||||
|
||||
return utils.HttpSuccess(w, ControlStatusPayload{
|
||||
HasHost: false,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) error {
|
||||
host := h.sessions.GetHost()
|
||||
if host != nil {
|
||||
utils.HttpUnprocessableEntity(w).Msg("there is already a host")
|
||||
return
|
||||
return utils.HttpUnprocessableEntity("there is already a host")
|
||||
}
|
||||
|
||||
session := auth.GetSession(r)
|
||||
session, _ := auth.GetSession(r)
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) {
|
||||
session := auth.GetSession(r)
|
||||
func (h *RoomHandler) controlRelease(w http.ResponseWriter, r *http.Request) error {
|
||||
session, _ := auth.GetSession(r)
|
||||
if !session.IsHost() {
|
||||
utils.HttpUnprocessableEntity(w).Msg("session is not the host")
|
||||
return
|
||||
return utils.HttpUnprocessableEntity("session is not the host")
|
||||
}
|
||||
|
||||
h.desktop.ResetKeys()
|
||||
h.sessions.ClearHost()
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlTake(w http.ResponseWriter, r *http.Request) {
|
||||
session := auth.GetSession(r)
|
||||
func (h *RoomHandler) controlTake(w http.ResponseWriter, r *http.Request) error {
|
||||
session, _ := auth.GetSession(r)
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *RoomHandler) controlGive(w http.ResponseWriter, r *http.Request) error {
|
||||
sessionId := chi.URLParam(r, "sessionId")
|
||||
|
||||
target, ok := h.sessions.Get(sessionId)
|
||||
if !ok {
|
||||
utils.HttpNotFound(w).Msg("target session was not found")
|
||||
return
|
||||
return utils.HttpNotFound("target session was not found")
|
||||
}
|
||||
|
||||
if !target.Profile().CanHost {
|
||||
utils.HttpBadRequest(w).Msg("target session is not allowed to host")
|
||||
return
|
||||
return utils.HttpBadRequest("target session is not allowed to host")
|
||||
}
|
||||
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) controlReset(w http.ResponseWriter, r *http.Request) {
|
||||
func (h *RoomHandler) controlReset(w http.ResponseWriter, r *http.Request) error {
|
||||
host := h.sessions.GetHost()
|
||||
if host == nil {
|
||||
utils.HttpSuccess(w)
|
||||
return
|
||||
|
||||
if host != nil {
|
||||
h.desktop.ResetKeys()
|
||||
h.sessions.ClearHost()
|
||||
}
|
||||
|
||||
h.desktop.ResetKeys()
|
||||
h.sessions.ClearHost()
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
return utils.HttpSuccess(w)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue