mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
get accounts
This commit is contained in:
@@ -894,6 +894,23 @@ func (a *Api) GetQrCodeLink(c *gin.Context) {
|
||||
c.Data(200, "image/png", png)
|
||||
}
|
||||
|
||||
// @Summary List all accounts
|
||||
// @Tags Accounts
|
||||
// @Description Lists all of the accounts linked or registered
|
||||
// @Produce json
|
||||
// @Success 200 {object} []string
|
||||
// @Failure 400 {object} Error
|
||||
// @Router /v1/accounts [get]
|
||||
func (a *Api) GetAccounts(c *gin.Context) {
|
||||
devices, err := a.signalClient.GetAccounts()
|
||||
if err != nil {
|
||||
c.JSON(500, Error{Msg: "Couldn't get list of accounts: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, devices)
|
||||
}
|
||||
|
||||
// @Summary List all attachments.
|
||||
// @Tags Attachments
|
||||
// @Description List all downloaded attachments
|
||||
|
||||
@@ -1076,6 +1076,45 @@ func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int) ([]by
|
||||
return png, nil
|
||||
}
|
||||
|
||||
func (s *SignalClient) GetAccounts() ([]string, error) {
|
||||
accounts := make([]string, 0)
|
||||
var rawData string
|
||||
var err error
|
||||
|
||||
if s.signalCliMode == JsonRpc {
|
||||
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||
if err != nil {
|
||||
return accounts, err
|
||||
}
|
||||
rawData, err = jsonRpc2Client.getRaw("listAccounts", nil, nil)
|
||||
if err != nil {
|
||||
return accounts, err
|
||||
}
|
||||
|
||||
} else {
|
||||
rawData, err = s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "--output", "json", "listAccounts"}, "")
|
||||
if err != nil {
|
||||
return accounts, err
|
||||
}
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
Number string `json:"number"`
|
||||
}
|
||||
accountObjs := []Account{}
|
||||
|
||||
err = json.Unmarshal([]byte(rawData), &accountObjs)
|
||||
if err != nil {
|
||||
return accounts, err
|
||||
}
|
||||
|
||||
for _, account := range accountObjs {
|
||||
accounts = append(accounts, account.Number)
|
||||
}
|
||||
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func (s *SignalClient) GetAttachments() ([]string, error) {
|
||||
files := []string{}
|
||||
|
||||
|
||||
@@ -45,6 +45,35 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/accounts": {
|
||||
"get": {
|
||||
"description": "Lists all of the devices linked or registered",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Accounts"
|
||||
],
|
||||
"summary": "List all accounts",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/attachments": {
|
||||
"get": {
|
||||
"description": "List all downloaded attachments",
|
||||
@@ -1951,6 +1980,9 @@ var doc = `{
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2090,6 +2122,10 @@ var doc = `{
|
||||
"description": "Register and link Devices.",
|
||||
"name": "Devices"
|
||||
},
|
||||
{
|
||||
"description": "List registered and linked accounts",
|
||||
"name": "Accounts"
|
||||
},
|
||||
{
|
||||
"description": "Create, List and Delete Signal Groups.",
|
||||
"name": "Groups"
|
||||
|
||||
@@ -29,6 +29,35 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/accounts": {
|
||||
"get": {
|
||||
"description": "Lists all of the devices linked or registered",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Accounts"
|
||||
],
|
||||
"summary": "List all accounts",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/attachments": {
|
||||
"get": {
|
||||
"description": "List all downloaded attachments",
|
||||
@@ -1935,6 +1964,9 @@
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -2074,6 +2106,10 @@
|
||||
"description": "Register and link Devices.",
|
||||
"name": "Devices"
|
||||
},
|
||||
{
|
||||
"description": "List registered and linked accounts",
|
||||
"name": "Accounts"
|
||||
},
|
||||
{
|
||||
"description": "Create, List and Delete Signal Groups.",
|
||||
"name": "Groups"
|
||||
|
||||
@@ -311,6 +311,25 @@ paths:
|
||||
summary: Lists general information about the API
|
||||
tags:
|
||||
- General
|
||||
/v1/accounts:
|
||||
get:
|
||||
description: Lists all of the devices linked or registered
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/api.Error'
|
||||
summary: List all accounts
|
||||
tags:
|
||||
- Accounts
|
||||
/v1/attachments:
|
||||
get:
|
||||
description: List all downloaded attachments
|
||||
@@ -1372,6 +1391,8 @@ tags:
|
||||
name: General
|
||||
- description: Register and link Devices.
|
||||
name: Devices
|
||||
- description: List registered and linked accounts
|
||||
name: Accounts
|
||||
- description: Create, List and Delete Signal Groups.
|
||||
name: Groups
|
||||
- description: Send and Receive Signal Messages.
|
||||
|
||||
@@ -28,6 +28,9 @@ import (
|
||||
// @tag.name Devices
|
||||
// @tag.description Register and link Devices.
|
||||
|
||||
// @tag.name Accounts
|
||||
// @tag.description List registered and linked accounts
|
||||
|
||||
// @tag.name Groups
|
||||
// @tag.description Create, List and Delete Signal Groups.
|
||||
|
||||
@@ -198,6 +201,11 @@ func main() {
|
||||
link.GET("", api.GetQrCodeLink)
|
||||
}
|
||||
|
||||
accounts := v1.Group("accounts")
|
||||
{
|
||||
accounts.GET("", api.GetAccounts)
|
||||
}
|
||||
|
||||
devices := v1.Group("devices")
|
||||
{
|
||||
devices.POST(":number", api.AddDevice)
|
||||
|
||||
Reference in New Issue
Block a user