goshorly/routes/id.go

44 lines
764 B
Go
Raw 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 {
val, err := db.Client.Get(c.Params("id")).Result()
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)
}