mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-27 14:54:14 +00:00
extended qrcodelink endpoint
* added possibility to specify the QR Code Version & the QR Code Error Correction Level via URL query parameters. see #257
This commit is contained in:
parent
1fbef2aed0
commit
74277fa24a
@ -12,6 +12,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
log "github.com/sirupsen/logrus"
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
|
||||
"github.com/bbernhard/signal-cli-rest-api/client"
|
||||
utils "github.com/bbernhard/signal-cli-rest-api/utils"
|
||||
@ -802,7 +803,35 @@ func (a *Api) GetQrCodeLink(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
png, err := a.signalClient.GetQrCodeLink(deviceName)
|
||||
qrCodeVersion := c.DefaultQuery("qr_code_version", "10")
|
||||
qrCodeVersionInt, err := strconv.Atoi(qrCodeVersion)
|
||||
if err != nil || qrCodeVersionInt < 1 || qrCodeVersionInt > 40 {
|
||||
c.JSON(400, Error{Msg: "Invalid qr_code_version parameter provided. allowed values: 1...40"})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
qrCodeErrorCorrectionLevel := c.DefaultQuery("qr_code_error_correction_level", "high")
|
||||
if(!(qrCodeErrorCorrectionLevel == "low" || qrCodeErrorCorrectionLevel == "medium" || qrCodeErrorCorrectionLevel == "high" || qrCodeErrorCorrectionLevel == "highest")) {
|
||||
c.JSON(400, Error{Msg: "Invalid qr_code_error_correction_level parameter provided. allowed values: 'low', 'medium', 'high', 'highest'"})
|
||||
return
|
||||
}
|
||||
|
||||
qrCodeErrorCorrectionLvl := qrcode.High
|
||||
if qrCodeErrorCorrectionLevel == "low" {
|
||||
qrCodeErrorCorrectionLvl = qrcode.Low
|
||||
} else if qrCodeErrorCorrectionLevel == "medium" {
|
||||
qrCodeErrorCorrectionLvl = qrcode.Medium
|
||||
} else if qrCodeErrorCorrectionLevel == "high" {
|
||||
qrCodeErrorCorrectionLvl = qrcode.High
|
||||
} else if qrCodeErrorCorrectionLevel == "highest" {
|
||||
qrCodeErrorCorrectionLvl = qrcode.Highest
|
||||
} else {
|
||||
c.JSON(400, Error{Msg: "Invalid qr_code_error_correction_level parameter provided. allowed values: 'low', 'medium', 'high', 'highest'"})
|
||||
return
|
||||
}
|
||||
|
||||
png, err := a.signalClient.GetQrCodeLink(deviceName, qrCodeVersionInt, qrCodeErrorCorrectionLvl)
|
||||
if err != nil {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
|
||||
@ -848,7 +848,7 @@ func (s *SignalClient) DeleteGroup(number string, groupId string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SignalClient) GetQrCodeLink(deviceName string) ([]byte, error) {
|
||||
func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int, qrCodeErrorCorrectionLevel qrcode.RecoveryLevel) ([]byte, error) {
|
||||
if s.signalCliMode == JsonRpc {
|
||||
return []byte{}, errors.New(endpointNotSupportedInJsonRpcMode)
|
||||
}
|
||||
@ -859,7 +859,7 @@ func (s *SignalClient) GetQrCodeLink(deviceName string) ([]byte, error) {
|
||||
return []byte{}, errors.New("Couldn't create QR code: " + err.Error())
|
||||
}
|
||||
|
||||
q, err := qrcode.NewWithForcedVersion(string(tsdeviceLink), 10, qrcode.Highest)
|
||||
q, err := qrcode.NewWithForcedVersion(string(tsdeviceLink), qrCodeVersion, qrCodeErrorCorrectionLevel)
|
||||
if err != nil {
|
||||
return []byte{}, errors.New("Couldn't create QR code: " + err.Error())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user