neko/internal/api/room/clipboard.go

32 lines
567 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
)
type ClipboardData struct {
Text string `json:"text"`
}
func (h *RoomHandler) ClipboardRead(w http.ResponseWriter, r *http.Request) {
// TODO: error check?
2020-11-02 04:54:06 +13:00
text := h.desktop.ReadClipboard()
2020-11-01 00:35:02 +13:00
utils.HttpSuccess(w, ClipboardData{
2020-11-01 00:35:02 +13:00
Text: text,
})
}
func (h *RoomHandler) ClipboardWrite(w http.ResponseWriter, r *http.Request) {
data := &ClipboardData{}
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
}