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:
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