Fix JSON output corruption from API log noise
- Redirect console.log to stderr before importing @actual-app/api so breadcrumb/sync messages don't mix with JSON output - Use groupId (not cloudFileId) for downloadBudget sync ID - Fix setup.sh to display and select groupId
This commit is contained in:
@@ -51,7 +51,7 @@ npm install @actual-app/api --silent 2>&1 | tail -1
|
||||
# List available budgets and let user pick
|
||||
echo ""
|
||||
echo "Connecting to server and listing budgets..."
|
||||
budgets_json=$(node "${SCRIPT_DIR}/actual-query.mjs" budgets 2>&1) || {
|
||||
budgets_json=$(node "${SCRIPT_DIR}/actual-query.mjs" budgets 2>/dev/null) || {
|
||||
echo "ERROR: Failed to connect to server"
|
||||
echo "${budgets_json}"
|
||||
exit 1
|
||||
@@ -62,7 +62,7 @@ echo "Available budgets:"
|
||||
echo "${budgets_json}" | node -e "
|
||||
const data = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf-8'));
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach((b, i) => console.log(' ' + (i+1) + ') ' + (b.name || b.cloudFileId || b.id || 'unnamed') + ' [' + (b.cloudFileId || b.groupId || b.id || 'unknown') + ']'));
|
||||
data.forEach((b, i) => console.log(' ' + (i+1) + ') ' + (b.name || b.groupId || b.id || 'unnamed') + ' [groupId: ' + (b.groupId || b.id || 'unknown') + ']'));
|
||||
} else {
|
||||
console.log(' (unexpected format)');
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
@@ -77,7 +77,7 @@ if [[ "${sync_id}" =~ ^[0-9]+$ ]]; then
|
||||
sync_id=$(echo "${budgets_json}" | node -e "
|
||||
const data = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf-8'));
|
||||
const idx = ${sync_id} - 1;
|
||||
if (data[idx]) console.log(data[idx].cloudFileId || data[idx].groupId || data[idx].id || '');
|
||||
if (data[idx]) console.log(data[idx].groupId || data[idx].id || '');
|
||||
else console.log('');
|
||||
")
|
||||
fi
|
||||
@@ -92,7 +92,7 @@ echo "ACTUAL_SYNC_ID=\"${sync_id}\"" >> "${CONFIG_FILE}"
|
||||
|
||||
echo ""
|
||||
echo "Testing connection..."
|
||||
test_result=$(node "${SCRIPT_DIR}/actual-query.mjs" accounts 2>&1) || {
|
||||
test_result=$(node "${SCRIPT_DIR}/actual-query.mjs" accounts 2>/dev/null) || {
|
||||
echo "ERROR: Failed to load budget"
|
||||
echo "${test_result}"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user