Fixed <1GB Ram issue with it throwing integer error

This commit is contained in:
Muhammad Ibrahim
2025-09-30 21:53:30 +01:00
parent 8be25283dc
commit b3d7e49961
2 changed files with 18 additions and 8 deletions

View File

@@ -683,11 +683,21 @@ get_hardware_info() {
# Memory Information # Memory Information
if command -v free >/dev/null 2>&1; then if command -v free >/dev/null 2>&1; then
ram_installed=$(free -g | grep "^Mem:" | awk '{print $2}') # Use free -m to get MB, then convert to GB with decimal precision
swap_size=$(free -g | grep "^Swap:" | awk '{print $2}') ram_installed=$(free -m | grep "^Mem:" | awk '{printf "%.2f", $2/1024}')
swap_size=$(free -m | grep "^Swap:" | awk '{printf "%.2f", $2/1024}')
elif [[ -f /proc/meminfo ]]; then elif [[ -f /proc/meminfo ]]; then
ram_installed=$(grep "MemTotal" /proc/meminfo | awk '{print int($2/1024/1024)}') # Convert KB to GB with decimal precision
swap_size=$(grep "SwapTotal" /proc/meminfo | awk '{print int($2/1024/1024)}') ram_installed=$(grep "MemTotal" /proc/meminfo | awk '{printf "%.2f", $2/1048576}')
swap_size=$(grep "SwapTotal" /proc/meminfo | awk '{printf "%.2f", $2/1048576}')
fi
# Ensure minimum value of 0.01GB to prevent 0 values
if (( $(echo "$ram_installed < 0.01" | bc -l) )); then
ram_installed="0.01"
fi
if (( $(echo "$swap_size < 0" | bc -l) )); then
swap_size="0"
fi fi
# Disk Information # Disk Information

View File

@@ -281,12 +281,12 @@ router.post(
.withMessage("CPU cores must be a positive integer"), .withMessage("CPU cores must be a positive integer"),
body("ramInstalled") body("ramInstalled")
.optional() .optional()
.isInt({ min: 1 }) .isFloat({ min: 0.01 })
.withMessage("RAM installed must be a positive integer"), .withMessage("RAM installed must be a positive number"),
body("swapSize") body("swapSize")
.optional() .optional()
.isInt({ min: 0 }) .isFloat({ min: 0 })
.withMessage("Swap size must be a non-negative integer"), .withMessage("Swap size must be a non-negative number"),
body("diskDetails") body("diskDetails")
.optional() .optional()
.isArray() .isArray()