fix: correct jq syntax for updating stats

- Adjusted the jq command for adding values to arrays to use the correct
  syntax for accessing keys.
- Updated the jq command for updating numeric values to use the
  `--argjson` option for proper type handling.

These changes ensure that the script correctly updates the statistics
file without errors, improving the reliability of the data handling.
This commit is contained in:
songtianlun 2025-01-03 17:27:59 +08:00
parent ca6a80da97
commit b8b2ee6972

View File

@ -38,12 +38,12 @@ update_stats() {
if [ "$type" = "array" ]; then if [ "$type" = "array" ]; then
# 添加到数组 # 添加到数组
jq --arg key "$key" --arg value "$value" \ jq --arg value "$value" \
".details[$key] += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp" ".details.$key += [\$value]" "$STATS_FILE" > "$STATS_FILE.tmp"
else else
# 更新数值 # 更新数值
jq --arg key "$key" --arg value "$value" \ jq --arg key "$key" --argjson value "$value" \
".[$key] = ($value | tonumber)" "$STATS_FILE" > "$STATS_FILE.tmp" ".$key = \$value" "$STATS_FILE" > "$STATS_FILE.tmp"
fi fi
mv "$STATS_FILE.tmp" "$STATS_FILE" mv "$STATS_FILE.tmp" "$STATS_FILE"
} }