neko/internal/api/room/clipboard.go

32 lines
576 B
Go
Raw Normal View History

2020-10-30 10:23:30 +13:00
package room
2020-11-01 00:35:02 +13:00
import (
"net/http"
"demodesk/neko/internal/utils"
2020-11-01 00:35:02 +13:00
)
2020-11-19 09:56:42 +13:00
type ClipboardPayload struct {
2020-11-01 00:35:02 +13:00
Text string `json:"text"`
}
2020-11-19 10:35:50 +13:00
func (h *RoomHandler) clipboardRead(w http.ResponseWriter, r *http.Request) {
2020-11-01 00:35:02 +13:00
// TODO: error check?
2020-11-02 04:54:06 +13:00
text := h.desktop.ReadClipboard()
2020-11-01 00:35:02 +13:00
2020-11-19 09:56:42 +13:00
utils.HttpSuccess(w, ClipboardPayload{
2020-11-01 00:35:02 +13:00
Text: text,
})
}
2020-11-19 10:35:50 +13:00
func (h *RoomHandler) clipboardWrite(w http.ResponseWriter, r *http.Request) {
2020-11-19 09:56:42 +13:00
data := &ClipboardPayload{}
if !utils.HttpJsonRequest(w, r, data) {
2020-11-01 00:35:02 +13:00
return
}
// TODO: error check?
2020-11-02 04:54:06 +13:00
h.desktop.WriteClipboard(data.Text)
utils.HttpSuccess(w)
2020-11-01 00:35:02 +13:00
}