~xenrox/syncthing-status

da27300196936c58a204722c8521d252c33ec456 — Thorben Günther 6 months ago 1614934 master 0.2.0
Print out how many remote devices are connected

In text form for now (some, none, all).
2 files changed, 22 insertions(+), 5 deletions(-)

M main.go
M status.go
M main.go => main.go +6 -3
@@ 7,8 7,9 @@ import (
)

type Status struct {
	Local  int `json:"local"`
	Remote int `json:"remote"`
	Local            int    `json:"local"`
	Remote           int    `json:"remote"`
	ConnectedRemotes string `json:"connectedRemotes"`
}

func main() {


@@ 16,9 17,11 @@ func main() {
	var status Status

	localStatus := client.localStatus()
	remoteStatus := client.remoteStatus()
	status.Local = int(localStatus.Completion)

	remoteStatus := client.remoteStatus()
	status.Remote = int(remoteStatus.Completion)
	status.ConnectedRemotes = remoteStatus.ConnectedRemotes

	data, err := json.MarshalIndent(status, "", "  ")
	if err != nil {

M status.go => status.go +16 -2
@@ 14,7 14,8 @@ type LocalStatus struct {
}

type RemoteStatus struct {
	Completion float64 `json:"completion"`
	Completion       float64 `json:"completion"`
	ConnectedRemotes string  `json:"connectedRemotes"`
}

type Connection struct {


@@ 52,10 53,15 @@ func (client *Client) remoteStatus() *RemoteStatus {
	}

	var sum float64
	for key := range connections.List {
	var connectedDevices int
	for key, device := range connections.List {
		if key == systemStatus.MyID {
			continue
		}
		if device.Connected {
			connectedDevices++
		}

		path := fmt.Sprintf("/rest/db/completion?device=%s", key)
		var status RemoteStatus
		err = client.get(path, &status)


@@ 73,5 79,13 @@ func (client *Client) remoteStatus() *RemoteStatus {
		totalStatus.Completion = sum / float64(len(connections.List)-1)
	}

	if connectedDevices == 0 {
		totalStatus.ConnectedRemotes = "none"
	} else if connectedDevices == len(connections.List)-1 {
		totalStatus.ConnectedRemotes = "all"
	} else {
		totalStatus.ConnectedRemotes = "some"
	}

	return &totalStatus
}