up
This commit is contained in:
@@ -149,3 +149,19 @@ func GenerateVCardQR(data ContactData) ([]byte, error) {
|
|||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateURlQR(url string) ([]byte, error) {
|
||||||
|
qr, err := qrcode.New(url, qrcode.Medium)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
img := qr.Image(300)
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
if err := png.Encode(&buf, img); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -169,3 +169,39 @@ func CreateQrTmp(c *fiber.Ctx) error {
|
|||||||
c.Type("webp")
|
c.Type("webp")
|
||||||
return c.Send(webpBuffer.Bytes())
|
return c.Send(webpBuffer.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateUrlQr(c *fiber.Ctx) error {
|
||||||
|
var data struct {
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(c.Body(), &data); err != nil {
|
||||||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||||
|
"error": "Datos inválidos",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
qrBytes, err := services.GenerateURlQR(data.URL)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"error": "No se pudo generar el QR",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
img, err := png.Decode(bytes.NewReader(qrBytes))
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"error": "No se pudo procesar la imagen",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Codificar a WebP
|
||||||
|
var webpBuffer bytes.Buffer
|
||||||
|
if err := webp.Encode(&webpBuffer, img, &webp.Options{Lossless: true}); err != nil {
|
||||||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||||
|
"error": "No se pudo convertir a WebP",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Type("webp")
|
||||||
|
return c.Send(webpBuffer.Bytes())
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ func v1AuthRoutes(api fiber.Router) {
|
|||||||
api.Get("/dlocal/subscription/:subscriptionId/execution/:invoiceId", apiControllers.SeeSubscription)
|
api.Get("/dlocal/subscription/:subscriptionId/execution/:invoiceId", apiControllers.SeeSubscription)
|
||||||
api.Post("/dlocal/payment/crear-pago", apiControllers.CreatePago)
|
api.Post("/dlocal/payment/crear-pago", apiControllers.CreatePago)
|
||||||
api.Post("/rapyd/wallet/create", apiControllers.MakeWallet)
|
api.Post("/rapyd/wallet/create", apiControllers.MakeWallet)
|
||||||
|
api.Post("/generate-url-qr", apiControllers.CreateUrlQr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func v1Routes(api fiber.Router) {
|
func v1Routes(api fiber.Router) {
|
||||||
|
|||||||
Reference in New Issue
Block a user