fix(rtty-remote): Fix RPCD rpc_call JSON response format

- jshn cannot embed raw JSON in objects, use printf instead
- Return proper {"success":true,"result":{...}} format
- Handle error cases with escaped error messages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2026-03-08 17:06:32 +01:00
parent 8b65bd64e9
commit 02ed4f3b34

View File

@ -124,23 +124,20 @@ method_rpc_call() {
local result=$($RTTYCTL rpc "$node_id" "$object" "$method" "$params" 2>&1)
local rc=$?
json_init
if [ $rc -eq 0 ]; then
json_add_boolean "success" 1
# Try to parse result as JSON
if [ $rc -eq 0 ] && [ -n "$result" ]; then
# Check if result is valid JSON
if echo "$result" | jsonfilter -e '@' >/dev/null 2>&1; then
json_add_object "result"
# Add result fields
echo "$result" | jsonfilter -e '@' 2>/dev/null
json_close_object
# Output success with embedded JSON result
printf '{"success":true,"result":%s}' "$result"
else
json_add_string "result" "$result"
# Result is not JSON, wrap as string
printf '{"success":true,"result":"%s"}' "$(echo "$result" | sed 's/"/\\"/g')"
fi
else
json_add_boolean "success" 0
json_add_string "error" "$result"
# Error case
local err_msg=$(echo "$result" | sed 's/"/\\"/g' | tr '\n' ' ')
printf '{"success":false,"error":"%s"}' "$err_msg"
fi
json_dump
}
# List remote RPCD objects