mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Add endpoint for QR Code generation
This commit is contained in:
12
README.md
12
README.md
@@ -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'```
|
||||
|
||||
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!**
|
||||
|
||||
|
||||
20
src/main.go
20
src/main.go
@@ -14,7 +14,9 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/h2non/filetype"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user