Skip to content

Commit 35e2e90

Browse files
author
Bernhard B
committed
made qrcode version configureable via query parameter (e.g
?qrcode_version=11) see #402
1 parent 1ba1418 commit 35e2e90

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

src/api/api.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,17 +836,29 @@ func (a *Api) DeleteGroup(c *gin.Context) {
836836
// @Produce json
837837
// @Success 200 {string} string "Image"
838838
// @Param device_name query string true "Device Name"
839+
// @Param qrcode_version query int false "QRCode Version (defaults to 10)"
839840
// @Failure 400 {object} Error
840841
// @Router /v1/qrcodelink [get]
841842
func (a *Api) GetQrCodeLink(c *gin.Context) {
842843
deviceName := c.Query("device_name")
844+
qrCodeVersion := c.Query("qrcode_version")
843845

844846
if deviceName == "" {
845847
c.JSON(400, Error{Msg: "Please provide a name for the device"})
846848
return
847849
}
848850

849-
png, err := a.signalClient.GetQrCodeLink(deviceName)
851+
qrCodeVersionInt := 10
852+
if qrCodeVersion != "" {
853+
var err error
854+
qrCodeVersionInt, err = strconv.Atoi(qrCodeVersion)
855+
if err != nil {
856+
c.JSON(400, Error{Msg: "The qrcode_version parameter needs to be an integer!"})
857+
return
858+
}
859+
}
860+
861+
png, err := a.signalClient.GetQrCodeLink(deviceName, qrCodeVersionInt)
850862
if err != nil {
851863
c.JSON(400, Error{Msg: err.Error()})
852864
return

src/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ func (s *SignalClient) DeleteGroup(number string, groupId string) error {
935935
return err
936936
}
937937

938-
func (s *SignalClient) GetQrCodeLink(deviceName string) ([]byte, error) {
938+
func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int) ([]byte, error) {
939939
if s.signalCliMode == JsonRpc {
940940
return []byte{}, errors.New(endpointNotSupportedInJsonRpcMode)
941941
}
@@ -946,7 +946,7 @@ func (s *SignalClient) GetQrCodeLink(deviceName string) ([]byte, error) {
946946
return []byte{}, errors.New("Couldn't create QR code: " + err.Error())
947947
}
948948

949-
q, err := qrcode.NewWithForcedVersion(string(tsdeviceLink), 10, qrcode.Highest)
949+
q, err := qrcode.NewWithForcedVersion(string(tsdeviceLink), qrCodeVersion, qrcode.Highest)
950950
if err != nil {
951951
return []byte{}, errors.New("Couldn't create QR code: " + err.Error())
952952
}

src/docs/docs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,12 @@ var doc = `{
10261026
"name": "device_name",
10271027
"in": "query",
10281028
"required": true
1029+
},
1030+
{
1031+
"type": "integer",
1032+
"description": "QRCode Version (defaults to 10)",
1033+
"name": "qrcode_version",
1034+
"in": "query"
10291035
}
10301036
],
10311037
"responses": {
@@ -1160,6 +1166,12 @@ var doc = `{
11601166
"description": "Specify whether stories should be ignored when receiving messages",
11611167
"name": "ignore_stories",
11621168
"in": "query"
1169+
},
1170+
{
1171+
"type": "string",
1172+
"description": "Specify the maximum number of messages to receive (default: unlimited)",
1173+
"name": "max_messages",
1174+
"in": "query"
11631175
}
11641176
],
11651177
"responses": {
@@ -1773,6 +1785,9 @@ var doc = `{
17731785
},
17741786
"sticker": {
17751787
"type": "string"
1788+
},
1789+
"text_mode": {
1790+
"type": "string"
17761791
}
17771792
}
17781793
},

src/docs/swagger.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,12 @@
10101010
"name": "device_name",
10111011
"in": "query",
10121012
"required": true
1013+
},
1014+
{
1015+
"type": "integer",
1016+
"description": "QRCode Version (defaults to 10)",
1017+
"name": "qrcode_version",
1018+
"in": "query"
10131019
}
10141020
],
10151021
"responses": {
@@ -1144,6 +1150,12 @@
11441150
"description": "Specify whether stories should be ignored when receiving messages",
11451151
"name": "ignore_stories",
11461152
"in": "query"
1153+
},
1154+
{
1155+
"type": "string",
1156+
"description": "Specify the maximum number of messages to receive (default: unlimited)",
1157+
"name": "max_messages",
1158+
"in": "query"
11471159
}
11481160
],
11491161
"responses": {
@@ -1757,6 +1769,9 @@
17571769
},
17581770
"sticker": {
17591771
"type": "string"
1772+
},
1773+
"text_mode": {
1774+
"type": "string"
17601775
}
17611776
}
17621777
},

src/docs/swagger.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ definitions:
153153
type: array
154154
sticker:
155155
type: string
156+
text_mode:
157+
type: string
156158
type: object
157159
api.TrustIdentityRequest:
158160
properties:
@@ -946,6 +948,10 @@ paths:
946948
name: device_name
947949
required: true
948950
type: string
951+
- description: QRCode Version (defaults to 10)
952+
in: query
953+
name: qrcode_version
954+
type: integer
949955
produces:
950956
- application/json
951957
responses:
@@ -1034,6 +1040,10 @@ paths:
10341040
in: query
10351041
name: ignore_stories
10361042
type: string
1043+
- description: 'Specify the maximum number of messages to receive (default: unlimited)'
1044+
in: query
1045+
name: max_messages
1046+
type: string
10371047
produces:
10381048
- application/json
10391049
responses:

0 commit comments

Comments
 (0)