Skip to content

Commit

Permalink
handle empty message
Browse files Browse the repository at this point in the history
  • Loading branch information
Legobas committed May 3, 2024
1 parent 0ba2988 commit 5285211
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ MQTT topic
MQTT message

mqtt4rclone/options/get
{}
<empty message> or {}

mqtt4rclone/options/set
{"main":{"LogLevel":"DEBUG"}}
Expand Down
6 changes: 5 additions & 1 deletion mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os"
"strings"
"time"

MQTT "github.com/eclipse/paho.mqtt.golang"
Expand Down Expand Up @@ -31,7 +32,10 @@ func receive(client MQTT.Client, msg MQTT.Message) {
log.Trace().Msgf("MQTT Message: %s", msg)
if topic != STATUS_TOPIC && topic != RESPONSE_TOPIC {
command := topic[len(APPNAME):]
json := string(msg.Payload()[:])
json := strings.TrimSpace(string(msg.Payload()[:]))
if len(json) == 0 {
json = "{}"
}

response, err := sendToRclone(command, json)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func sendToRclone(command string, payload string) (string, error) {
payload = string(msg)
}

log.Debug().Msgf("url: %s", url)
log.Debug().Msgf("json: %s", payload)
log.Debug().Msgf("Rclone url: %s", url)
log.Debug().Msgf("Rclone json: %s", payload)

req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(payload))
if err != nil {
Expand Down

0 comments on commit 5285211

Please sign in to comment.