mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
generate screenshot using Xlib.
This commit is contained in:
@ -61,7 +61,8 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
})
|
||||
|
||||
r.Route("/screen", func(r chi.Router) {
|
||||
r.Get("/", h.screenConfiguration)
|
||||
r.With(auth.CanWatchOnly).Get("/", h.screenConfiguration)
|
||||
r.With(auth.CanWatchOnly).Get("/image", h.screenImageGet)
|
||||
|
||||
r.With(auth.AdminsOnly).Post("/", h.screenConfigurationChange)
|
||||
r.With(auth.AdminsOnly).Get("/configurations", h.screenConfigurationsList)
|
||||
|
@ -1,6 +1,9 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image/jpeg"
|
||||
"strconv"
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
@ -72,3 +75,23 @@ func (h *RoomHandler) screenConfigurationsList(w http.ResponseWriter, r *http.Re
|
||||
|
||||
utils.HttpSuccess(w, list)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) screenImageGet(w http.ResponseWriter, r *http.Request) {
|
||||
var options *jpeg.Options
|
||||
if quality, err := strconv.Atoi(r.URL.Query().Get("quality")); err == nil {
|
||||
options = &jpeg.Options{ quality }
|
||||
} else {
|
||||
options = &jpeg.Options{ 90 }
|
||||
}
|
||||
|
||||
img := h.desktop.GetScreenshotImage()
|
||||
out := new(bytes.Buffer)
|
||||
err := jpeg.Encode(out, img, options)
|
||||
if err != nil {
|
||||
utils.HttpInternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "image/jpeg")
|
||||
w.Write(out.Bytes())
|
||||
}
|
||||
|
Reference in New Issue
Block a user