diff --git a/admin/DashboardController.php b/admin/DashboardController.php index 25bbcf1..4c4a9d6 100644 --- a/admin/DashboardController.php +++ b/admin/DashboardController.php @@ -2007,13 +2007,22 @@ HTML; if ($err) { echo json_encode(['ok' => false, 'error' => 'cURL: ' . $err]); exit; } - $decoded = json_decode($resp, true); - $preview = is_array($decoded) ? $decoded : (string)$resp; + $isBinary = !empty($contentType) && !str_contains($contentType, 'json') && !str_contains($contentType, 'text'); + $decoded = !$isBinary ? json_decode($resp, true) : null; + + if ($isBinary) { + $preview = sprintf('Archivo recibido: %s — %s KB', explode(';', $contentType)[0], round(strlen($resp) / 1024, 1)); + } elseif (is_array($decoded)) { + $preview = $decoded; + } else { + $preview = mb_convert_encoding(substr((string)$resp, 0, 500), 'UTF-8', 'UTF-8'); + } // Guardar última respuesta if ($key !== '') { + $logVal = $isBinary ? "binary:{$contentType}:" . strlen($resp) . 'B' : substr((string)$resp, 0, 2000); db()->prepare("UPDATE company_endpoints SET last_response=?, last_called_at=NOW() WHERE company_id=? AND endpoint_key=?") - ->execute([is_string($resp) ? substr($resp, 0, 2000) : '', $companyId, $key]); + ->execute([$logVal, $companyId, $key]); } if ($httpCode >= 200 && $httpCode < 300) {