mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
@@ -126,6 +126,10 @@ type SearchResponse struct {
|
|||||||
Registered bool `json:"registered"`
|
Registered bool `json:"registered"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddDeviceRequest struct {
|
||||||
|
Uri string `json:uri"`
|
||||||
|
}
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
signalClient *client.SignalClient
|
signalClient *client.SignalClient
|
||||||
}
|
}
|
||||||
@@ -1200,3 +1204,35 @@ func (a *Api) UpdateContact(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary Links another device to this device.
|
||||||
|
// @Tags Devices
|
||||||
|
// @Description Links another device to this device. Only works, if this is the master device.
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param number path string true "Registered Phone Number"
|
||||||
|
// @Success 204
|
||||||
|
// @Param data body AddDeviceRequest true "Request"
|
||||||
|
// @Failure 400 {object} Error
|
||||||
|
// @Router /v1/devices/{number} [post]
|
||||||
|
func (a *Api) AddDevice(c *gin.Context) {
|
||||||
|
number := c.Param("number")
|
||||||
|
if number == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req AddDeviceRequest
|
||||||
|
err := c.BindJSON(&req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.signalClient.AddDevice(number, req.Uri)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1269,3 +1269,22 @@ func (s *SignalClient) UpdateContact(number string, recipient string, name *stri
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SignalClient) AddDevice(number string, uri string) error {
|
||||||
|
var err error
|
||||||
|
if s.signalCliMode == JsonRpc {
|
||||||
|
type Request struct {
|
||||||
|
Uri string `json:"uri"`
|
||||||
|
}
|
||||||
|
request := Request{Uri: uri}
|
||||||
|
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = jsonRpc2Client.getRaw("addDevice", request)
|
||||||
|
} else {
|
||||||
|
cmd := []string{"--config", s.signalCliConfig, "-a", number, "addDevice", "--uri", uri}
|
||||||
|
_, err = runSignalCli(true, cmd, "", s.signalCliMode)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -193,6 +193,11 @@ func main() {
|
|||||||
link.GET("", api.GetQrCodeLink)
|
link.GET("", api.GetQrCodeLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devices := v1.Group("devices")
|
||||||
|
{
|
||||||
|
devices.POST(":number", api.AddDevice)
|
||||||
|
}
|
||||||
|
|
||||||
attachments := v1.Group("attachments")
|
attachments := v1.Group("attachments")
|
||||||
{
|
{
|
||||||
attachments.GET("", api.GetAttachments)
|
attachments.GET("", api.GetAttachments)
|
||||||
|
|||||||
Reference in New Issue
Block a user