goshorly/routes/id.go

44 lines
748 B
Go
Raw Permalink Normal View History

package routes
import (
"log"
"git.ucode.space/Phil/goshorly/db"
"git.ucode.space/Phil/goshorly/utils"
"github.com/gofiber/fiber/v2"
)
func ID(c *fiber.Ctx) error {
2022-01-13 19:06:30 +00:00
val, err := db.Get(c.Params("id"))
2021-12-10 21:38:02 +00:00
if c.Get("CLI") == "1" {
if err != nil {
return c.Status(404).JSON(&fiber.Map{
"error": true,
"url": "URL not found",
})
} else {
_, err = db.StatsIncreaseViewsLinks()
if err != nil {
log.Fatal(err.Error())
}
2021-12-10 21:38:02 +00:00
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
})
}
}
if err != nil {
return c.Render("views/404", fiber.Map{
"BASEURL": utils.URL,
})
}
_, err = db.StatsIncreaseViewsLinks()
if err != nil {
log.Fatal(err.Error())
}
return c.Redirect(val)
}