goshorly/routes/id.go

39 lines
663 B
Go
Raw Normal View History

package routes
import (
"log"
2022-12-23 21:50:40 +00:00
"gitea.hackmi.ch/Phil/goshorly/db"
"gitea.hackmi.ch/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
2023-04-05 20:29:43 +00:00
if err != nil {
if c.Get("CLI") == "1" {
2021-12-10 21:38:02 +00:00
return c.Status(404).JSON(&fiber.Map{
"error": true,
"url": "URL not found",
})
} else {
2023-04-05 20:29:43 +00:00
return c.Render("views/404", fiber.Map{
"BASEURL": utils.URL,
2021-12-10 21:38:02 +00:00
})
}
}
_, err = db.StatsIncreaseViewsLinks()
if err != nil {
log.Fatal(err.Error())
}
2023-04-05 20:29:43 +00:00
if c.Get("CLI") == "1" {
return c.Status(301).JSON(&fiber.Map{
"error": false,
"url": val,
})
}
return c.Redirect(val)
}