From 5a8b9320f51ab7d09fdc203d382b6a94d295844d Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 21 May 2026 23:02:53 -0500 Subject: [PATCH] Update servidor_controller.go --- rest/controllers/servidor_controller.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/rest/controllers/servidor_controller.go b/rest/controllers/servidor_controller.go index 9736426..879d7cd 100755 --- a/rest/controllers/servidor_controller.go +++ b/rest/controllers/servidor_controller.go @@ -227,9 +227,10 @@ func SyncServidorFromHostinger(c *fiber.Ctx) error { updates["nucleos"] = fmt.Sprintf("%d", vps.CPU) } - // Disco: Hostinger devuelve en GB directamente + // Disco: Hostinger devuelve en MB (igual que memory) → convertir a GB if vps.DiskBytes > 0 { - updates["disco"] = fmt.Sprintf("%d GB", vps.DiskBytes) + gbDisk := vps.DiskBytes / 1024 + updates["disco"] = fmt.Sprintf("%d GB", gbDisk) } // Vencimiento: resolución en cascada @@ -243,17 +244,29 @@ func SyncServidorFromHostinger(c *fiber.Ctx) error { if subID != "" { // Lookup directo — sin ambigüedad - if sub, sErr := client.GetSubscriptionByID(subID); sErr == nil && sub.ExpiresAt != "" && len(sub.ExpiresAt) >= 10 { - updates["vencimiento"] = sub.ExpiresAt[:10] + if sub, sErr := client.GetSubscriptionByID(subID); sErr == nil { + // Para suscripciones activas con auto-renovación, expires_at viene vacío; + // en ese caso usar next_billing_at como fecha de vencimiento. + venc := sub.ExpiresAt + if venc == "" { + venc = sub.NextBillingAt + } + if venc != "" && len(venc) >= 10 { + updates["vencimiento"] = venc[:10] + } updates["hostinger_subscription_id"] = subID } } else { // Fallback: buscar por nombre si aún no tenemos subscription_id if subs, sErr := client.GetOrders(); sErr == nil { for _, sub := range subs { - if sub.ExpiresAt != "" && len(sub.ExpiresAt) >= 10 && + venc := sub.ExpiresAt + if venc == "" { + venc = sub.NextBillingAt + } + if venc != "" && len(venc) >= 10 && strings.Contains(strings.ToLower(sub.Name), strings.ToLower(vps.Hostname)) { - updates["vencimiento"] = sub.ExpiresAt[:10] + updates["vencimiento"] = venc[:10] updates["hostinger_subscription_id"] = sub.ID break }