This commit is contained in:
Lizandro Guarnizo
2026-06-03 21:32:50 -05:00
parent f087fd46f1
commit c05a2a8137
10 changed files with 453 additions and 175 deletions
+8 -9
View File
@@ -65,14 +65,14 @@ func CreateQr(c *fiber.Ctx) error {
defer os.Remove(tmpPath)
// 5. Subir a OSS
ossService, err := services.NewOSSServiceFromDB()
ossProvider, err := getOSSFromBody(c)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error de conexión con OSS",
})
}
if err := ossService.UploadFile(fileName, tmpPath); err != nil {
if err := ossProvider.UploadFile(fileName, tmpPath); err != nil {
log.Printf("Error subiendo archivo a OSS: %v", err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error subiendo archivo a OSS",
@@ -80,7 +80,7 @@ func CreateQr(c *fiber.Ctx) error {
}
// 6. URL del archivo
url := fmt.Sprintf("https://%s.%s/%s", ossService.BucketName, ossService.Endpoint, fileName)
url := ossProvider.PublicURL(fileName)
// 7. Buscar si ya existe un registro con ese vcard_id
var existing models.QrVcard
@@ -110,9 +110,9 @@ func CreateQr(c *fiber.Ctx) error {
}
} else {
// Ya existe, eliminar el QR anterior en OSS
oldFilePath := strings.Replace(existing.Qr, fmt.Sprintf("https://%s.%s/", ossService.BucketName, ossService.Endpoint), "", 1)
oldFilePath := strings.Replace(existing.Qr, ossProvider.PublicURL(""), "", 1)
if err := ossService.DeleteFile(oldFilePath); err != nil {
if err := ossProvider.DeleteFile(oldFilePath); err != nil {
log.Printf("Error al eliminar QR anterior en OSS: %v", err)
// No retornamos error, porque queremos continuar de todas formas
}
@@ -224,14 +224,14 @@ func CreateUrlQr(c *fiber.Ctx) error {
defer os.Remove(tmpPath)
// 5. Subir a OSS
ossService, err := services.NewOSSServiceFromDB()
ossProvider, err := getOSSFromBody(c)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error de conexión con OSS",
})
}
if err := ossService.UploadFile(fileName, tmpPath); err != nil {
if err := ossProvider.UploadFile(fileName, tmpPath); err != nil {
log.Printf("Error subiendo archivo a OSS: %v", err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error subiendo archivo a OSS",
@@ -239,8 +239,7 @@ func CreateUrlQr(c *fiber.Ctx) error {
}
// 6. URL del archivo
url := fmt.Sprintf("https://%s.%s/%s", ossService.BucketName, ossService.Endpoint, fileName)
url := ossProvider.PublicURL(fileName)
// 8. Retornar la URL