From 7c305b5a27bad3b6c48a7ced1d1ffe1eeca05101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 1 Feb 2021 18:29:39 +0100 Subject: [PATCH] clipboard lint fix. --- internal/api/room/clipboard.go | 33 ++++++++++++++++++++------------- internal/desktop/clipboard.go | 16 ++++++++++------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/internal/api/room/clipboard.go b/internal/api/room/clipboard.go index 88514484..3bd19341 100644 --- a/internal/api/room/clipboard.go +++ b/internal/api/room/clipboard.go @@ -1,8 +1,9 @@ package room import ( - "bytes" - "strings" + // TODO: Unused now. + //"bytes" + //"strings" "net/http" "demodesk/neko/internal/utils" @@ -14,16 +15,6 @@ type ClipboardPayload struct { 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) { data, err := h.desktop.ClipboardGetText() if err != nil { @@ -69,6 +60,7 @@ func (h *RoomHandler) clipboardGetImage(w http.ResponseWriter, r *http.Request) w.Write(bytes) } +/* TODO: Unused now. func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(MAX_UPLOAD_SIZE) if err != nil { @@ -94,7 +86,11 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) } 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()) if err != nil { @@ -104,3 +100,14 @@ func (h *RoomHandler) clipboardSetImage(w http.ResponseWriter, r *http.Request) 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) +} +*/ diff --git a/internal/desktop/clipboard.go b/internal/desktop/clipboard.go index f6d94fb5..f60a3c1f 100644 --- a/internal/desktop/clipboard.go +++ b/internal/desktop/clipboard.go @@ -45,7 +45,7 @@ func (manager *DesktopManagerCtx) ClipboardGetBinary(mime string) ([]byte, error err := cmd.Run() if err != nil { - msg := strings.TrimSpace(string(stderr.Bytes())) + msg := strings.TrimSpace(stderr.String()) return nil, fmt.Errorf("%s", msg) } @@ -65,11 +65,15 @@ func (manager *DesktopManagerCtx) ClipboardSetBinary(mime string, data []byte) e err = cmd.Start() if err != nil { - msg := strings.TrimSpace(string(stderr.Bytes())) + msg := strings.TrimSpace(stderr.String()) return fmt.Errorf("%s", msg) } - - stdin.Write(data) + + _, err = stdin.Write(data) + if err != nil { + return err + } + stdin.Close() // TODO: Refactor. @@ -86,12 +90,12 @@ func (manager *DesktopManagerCtx) ClipboardGetTargets() ([]string, error) { err := cmd.Run() if err != nil { - msg := strings.TrimSpace(string(stderr.Bytes())) + msg := strings.TrimSpace(stderr.String()) return nil, fmt.Errorf("%s", msg) } var response []string - targets := strings.Split(string(stdout.Bytes()), "\n") + targets := strings.Split(stdout.String(), "\n") for _, target := range targets { if target == "" { continue