neko/internal/api/room/keyboard.go

58 lines
1.3 KiB
Go
Raw Normal View History

2020-10-30 10:23:30 +13:00
package room
2020-11-19 09:53:06 +13:00
import (
"net/http"
"github.com/demodesk/neko/pkg/types"
"github.com/demodesk/neko/pkg/utils"
2020-11-19 09:53:06 +13:00
)
2021-01-16 04:53:03 +13:00
type KeyboardMapData struct {
types.KeyboardMap
2020-11-19 09:53:06 +13:00
}
type KeyboardModifiersData struct {
types.KeyboardModifiers
2020-11-19 09:53:06 +13:00
}
2021-09-17 10:58:50 +12:00
func (h *RoomHandler) keyboardMapSet(w http.ResponseWriter, r *http.Request) error {
2021-01-16 04:53:03 +13:00
data := &KeyboardMapData{}
2021-09-17 10:58:50 +12:00
if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err
2020-11-19 09:53:06 +13:00
}
err := h.desktop.SetKeyboardMap(data.KeyboardMap)
2021-02-15 02:40:17 +13:00
if err != nil {
2021-09-17 10:58:50 +12:00
return utils.HttpInternalServerError().WithInternalErr(err)
2021-01-13 11:48:15 +13:00
}
2020-11-19 09:53:06 +13:00
2021-09-17 10:58:50 +12:00
return utils.HttpSuccess(w)
2020-11-19 09:53:06 +13:00
}
2021-09-17 10:58:50 +12:00
func (h *RoomHandler) keyboardMapGet(w http.ResponseWriter, r *http.Request) error {
2021-01-16 04:53:03 +13:00
data, err := h.desktop.GetKeyboardMap()
2021-02-15 02:40:17 +13:00
if err != nil {
2021-09-17 10:58:50 +12:00
return utils.HttpInternalServerError().WithInternalErr(err)
2021-01-16 04:53:03 +13:00
}
2021-09-17 10:58:50 +12:00
return utils.HttpSuccess(w, KeyboardMapData{
KeyboardMap: *data,
2021-01-16 04:53:03 +13:00
})
}
2021-09-17 10:58:50 +12:00
func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Request) error {
2020-11-19 09:53:06 +13:00
data := &KeyboardModifiersData{}
2021-09-17 10:58:50 +12:00
if err := utils.HttpJsonRequest(w, r, data); err != nil {
return err
2020-11-19 09:53:06 +13:00
}
h.desktop.SetKeyboardModifiers(data.KeyboardModifiers)
2021-09-17 10:58:50 +12:00
return utils.HttpSuccess(w)
2020-11-19 09:53:06 +13:00
}
2021-01-13 11:35:46 +13:00
2021-09-17 10:58:50 +12:00
func (h *RoomHandler) keyboardModifiersGet(w http.ResponseWriter, r *http.Request) error {
return utils.HttpSuccess(w, KeyboardModifiersData{
KeyboardModifiers: h.desktop.GetKeyboardModifiers(),
2021-01-13 11:35:46 +13:00
})
}