goshorly/routes/id.go
Phil fce20e7c61
All checks were successful
ci/woodpecker/pr/0-pre Pipeline was successful
ci/woodpecker/pr/1-build-check Pipeline was successful
removed renderings to comments
2025-04-09 21:06:28 +02:00

35 lines
575 B
Go

package routes
import (
"log"
"git.hackmi.ch/Phil/goshorly/db"
"github.com/gofiber/fiber/v2"
)
func ID(c *fiber.Ctx) error {
val, err := db.Get(c.Params("id"))
if err != nil {
if c.Get("CLI") == "1" {
return c.Status(404).JSON(&fiber.Map{
"error": true,
"url": "URL not found",
})
} else {
return c.SendStatus(404)
}
}
_, err = db.StatsIncreaseViewsLinks()
if err != nil {
log.Fatal(err.Error())
}
if c.Get("CLI") == "1" {
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
})
}
return c.Redirect(val)
}