Update servidor_controller.go
This commit is contained in:
@@ -227,9 +227,10 @@ func SyncServidorFromHostinger(c *fiber.Ctx) error {
|
|||||||
updates["nucleos"] = fmt.Sprintf("%d", vps.CPU)
|
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 {
|
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
|
// Vencimiento: resolución en cascada
|
||||||
@@ -243,17 +244,29 @@ func SyncServidorFromHostinger(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
if subID != "" {
|
if subID != "" {
|
||||||
// Lookup directo — sin ambigüedad
|
// Lookup directo — sin ambigüedad
|
||||||
if sub, sErr := client.GetSubscriptionByID(subID); sErr == nil && sub.ExpiresAt != "" && len(sub.ExpiresAt) >= 10 {
|
if sub, sErr := client.GetSubscriptionByID(subID); sErr == nil {
|
||||||
updates["vencimiento"] = sub.ExpiresAt[:10]
|
// 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
|
updates["hostinger_subscription_id"] = subID
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback: buscar por nombre si aún no tenemos subscription_id
|
// Fallback: buscar por nombre si aún no tenemos subscription_id
|
||||||
if subs, sErr := client.GetOrders(); sErr == nil {
|
if subs, sErr := client.GetOrders(); sErr == nil {
|
||||||
for _, sub := range subs {
|
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)) {
|
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
|
updates["hostinger_subscription_id"] = sub.ID
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user