1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 18:34:46 +00:00

Enhanced optimization for better use

This commit is contained in:
Tw93
2025-12-08 15:40:39 +08:00
parent 78e6743666
commit 9e7fc41445
4 changed files with 30 additions and 10 deletions

View File

@@ -84,6 +84,12 @@ get_uptime_days() {
echo "$uptime_days"
}
# JSON escape helper
json_escape() {
# Escape backslash, double quote, tab, and newline
echo -n "$1" | sed 's/\\/\\\\/g; s/"/\\"/g; s/ /\\t/g' | tr '\n' ' '
}
# Generate JSON output
generate_health_json() {
# System info
@@ -127,6 +133,11 @@ EOF
for item in "${items[@]}"; do
IFS='|' read -r action name desc safe <<< "$item"
# Escape strings
action=$(json_escape "$action")
name=$(json_escape "$name")
desc=$(json_escape "$desc")
[[ "$first" == "true" ]] && first=false || echo ","
cat << EOF