Update vcard_qr.go
This commit is contained in:
@@ -53,7 +53,7 @@ func CreateQr(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
random := helpers.RandomString(4)
|
||||
fileName := fmt.Sprintf("qrs/qr-%s-%s.webp", data.FirstName, random)
|
||||
fileName := fmt.Sprintf("qrs/qr-%s-%s.webp", strings.ReplaceAll(data.FirstName, " ", "_"), random)
|
||||
tmpPath := fmt.Sprintf("/tmp/%s.webp", data.FirstName)
|
||||
|
||||
// 4. Guardar archivo temporal
|
||||
@@ -108,27 +108,26 @@ func CreateQr(c *fiber.Ctx) error {
|
||||
"error": "Error al consultar la base de datos",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Ya existe, eliminar el QR anterior en OSS
|
||||
oldFilePath := strings.Replace(existing.Qr, fmt.Sprintf("https://%s.%s/", ossService.BucketName, ossService.Endpoint), "", 1)
|
||||
|
||||
if err := ossService.DeleteFile(oldFilePath); err != nil {
|
||||
log.Printf("Error al eliminar QR anterior en OSS: %v", err)
|
||||
// No retornamos error, porque queremos continuar de todas formas
|
||||
}
|
||||
|
||||
// Actualizar el registro
|
||||
existing.Qr = url
|
||||
existing.UsuarioID = data.FirstName
|
||||
existing.Email = data.Email
|
||||
|
||||
if err := models.UpdateQrVcard(&existing); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error al actualizar el QR en la base de datos",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// Ya existe, eliminar el QR anterior en OSS
|
||||
oldFilePath := strings.Replace(existing.Qr, fmt.Sprintf("https://%s.%s/", ossService.BucketName, ossService.Endpoint), "", 1)
|
||||
|
||||
if err := ossService.DeleteFile(oldFilePath); err != nil {
|
||||
log.Printf("Error al eliminar QR anterior en OSS: %v", err)
|
||||
// No retornamos error, porque queremos continuar de todas formas
|
||||
}
|
||||
|
||||
|
||||
// Actualizar el registro
|
||||
existing.Qr = url
|
||||
existing.UsuarioID = data.FirstName
|
||||
existing.Email = data.Email
|
||||
|
||||
if err := models.UpdateQrVcard(&existing); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"error": "Error al actualizar el QR en la base de datos",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Retornar la URL
|
||||
return c.JSON(fiber.Map{
|
||||
|
||||
Reference in New Issue
Block a user