clipboard lint fix.

This commit is contained in:
Miroslav Šedivý 2021-02-01 18:29:39 +01:00
parent b420841f9d
commit 7c305b5a27
2 changed files with 30 additions and 19 deletions

View File

@ -1,8 +1,9 @@
package room package room
import ( import (
"bytes" // TODO: Unused now.
"strings" //"bytes"
//"strings"
"net/http" "net/http"
"demodesk/neko/internal/utils" "demodesk/neko/internal/utils"
@ -14,16 +15,6 @@ type ClipboardPayload struct {
HTML string `json:"html,omitempty"` HTML string `json:"html,omitempty"`
} }
func (h *RoomHandler) clipboardGetTargets(w http.ResponseWriter, r *http.Request) {
targets, err := h.desktop.ClipboardGetTargets()
if err != nil {
utils.HttpInternalServerError(w, err)
return
}
utils.HttpSuccess(w, targets)
}
func (h *RoomHandler) clipboardGetText(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) clipboardGetText(w http.ResponseWriter, r *http.Request) {
data, err := h.desktop.ClipboardGetText() data, err := h.desktop.ClipboardGetText()
if err != nil { if err != nil {
@ -69,6 +60,7 @@ func (h *RoomHandler) clipboardGetImage(w http.ResponseWriter, r *http.Request)
w.Write(bytes) w.Write(bytes)
} }
/* TODO: Unused now.
func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) {
err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) err := r.ParseMultipartForm(MAX_UPLOAD_SIZE)
if err != nil { if err != nil {
@ -94,7 +86,11 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request)
} }
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
buffer.ReadFrom(file) _, err = buffer.ReadFrom(file)
if err != nil {
utils.HttpInternalServerError(w, err)
return
}
err = h.desktop.ClipboardSetBinary("image/png", buffer.Bytes()) err = h.desktop.ClipboardSetBinary("image/png", buffer.Bytes())
if err != nil { if err != nil {
@ -104,3 +100,14 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request)
utils.HttpSuccess(w) utils.HttpSuccess(w)
} }
func (h *RoomHandler) clipboardGetTargets(w http.ResponseWriter, r *http.Request) {
targets, err := h.desktop.ClipboardGetTargets()
if err != nil {
utils.HttpInternalServerError(w, err)
return
}
utils.HttpSuccess(w, targets)
}
*/

View File

@ -45,7 +45,7 @@ func (manager *DesktopManagerCtx) ClipboardGetBinary(mime string) ([]byte, error
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
msg := strings.TrimSpace(string(stderr.Bytes())) msg := strings.TrimSpace(stderr.String())
return nil, fmt.Errorf("%s", msg) return nil, fmt.Errorf("%s", msg)
} }
@ -65,11 +65,15 @@ func (manager *DesktopManagerCtx) ClipboardSetBinary(mime string, data []byte) e
err = cmd.Start() err = cmd.Start()
if err != nil { if err != nil {
msg := strings.TrimSpace(string(stderr.Bytes())) msg := strings.TrimSpace(stderr.String())
return fmt.Errorf("%s", msg) return fmt.Errorf("%s", msg)
} }
stdin.Write(data) _, err = stdin.Write(data)
if err != nil {
return err
}
stdin.Close() stdin.Close()
// TODO: Refactor. // TODO: Refactor.
@ -86,12 +90,12 @@ func (manager *DesktopManagerCtx) ClipboardGetTargets() ([]string, error) {
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
msg := strings.TrimSpace(string(stderr.Bytes())) msg := strings.TrimSpace(stderr.String())
return nil, fmt.Errorf("%s", msg) return nil, fmt.Errorf("%s", msg)
} }
var response []string var response []string
targets := strings.Split(string(stdout.Bytes()), "\n") targets := strings.Split(stdout.String(), "\n")
for _, target := range targets { for _, target := range targets {
if target == "" { if target == "" {
continue continue