Add Edit > Show ID with QR (fixes #243)

This commit is contained in:
Jakob Borg
2014-05-21 20:06:14 +02:00
parent 4235175966
commit 6fb05fc82a
10 changed files with 1782 additions and 17 deletions

View File

@@ -19,6 +19,7 @@ import (
"github.com/calmh/syncthing/logger"
"github.com/calmh/syncthing/model"
"github.com/codegangsta/martini"
"github.com/vitrun/qart/qr"
)
type guiError struct {
@@ -80,6 +81,7 @@ func startGUI(cfg config.GUIConfiguration, m *model.Model) error {
router.Get("/rest/system", restGetSystem)
router.Get("/rest/errors", restGetErrors)
router.Get("/rest/discovery", restGetDiscovery)
router.Get("/qr/:text", getQR)
router.Post("/rest/config", restPostConfig)
router.Post("/rest/restart", restPostRestart)
@@ -289,6 +291,17 @@ func restGetDiscovery(w http.ResponseWriter) {
json.NewEncoder(w).Encode(discoverer.All())
}
func getQR(w http.ResponseWriter, params martini.Params) {
code, err := qr.Encode(params["text"], qr.M)
if err != nil {
http.Error(w, "Invalid", 500)
return
}
w.Header().Set("Content-Type", "image/png")
w.Write(code.PNG())
}
func basic(username string, passhash string) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
error := func() {