Add endpoint for QR Code generation

This commit is contained in:
Danijel Fischer
2020-06-13 13:16:23 +02:00
parent 673c7045aa
commit b06dd9afb4
2 changed files with 31 additions and 1 deletions

View File

@@ -122,9 +122,19 @@ The group id can be obtained via the "List groups" REST call.
```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/link/HomeAssistant'``` ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/link/HomeAssistant'```
This provides a tsdevice link which have to be converted to a QR-Code, e.g. `qrencode -o linkqr.png tsdevice:...` This provides a tsdevice link which have to be converted to a QR-Code. For this the endpoint /v1/qrcode/<tsdevice_link> ca be used.
* Get QR Code
```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcode/<tsdevice_link>'```
e.g:
```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcode/tsdevice:?uuid=ZiVIV..'```
This provides a QR-Code image. In case of an error a JSON object will be returned.
The following REST API endpoints are **deprecated and no longer maintained!** The following REST API endpoints are **deprecated and no longer maintained!**

View File

@@ -14,7 +14,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/h2non/filetype" "github.com/h2non/filetype"
uuid "github.com/satori/go.uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
qrcode "github.com/skip2/go-qrcode"
) )
const groupPrefix = "group." const groupPrefix = "group."
@@ -496,5 +498,23 @@ func main() {
} }
}) })
router.GET("/v1/qrcode/:tsdevice_link", func(c *gin.Context) {
deviceLink := c.Param("tsdevice_link")
q, err := qrcode.New(deviceLink, qrcode.Medium)
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
}
q.DisableBorder = true
var png []byte
png, err = q.PNG(256)
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
}
c.Data(200, "image/png", png)
})
router.Run() router.Run()
} }