2021-12-08 15:31:52 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2022-01-08 16:21:53 +00:00
|
|
|
"log"
|
|
|
|
|
2022-12-23 21:50:40 +00:00
|
|
|
"gitea.hackmi.ch/Phil/goshorly/db"
|
|
|
|
"gitea.hackmi.ch/Phil/goshorly/utils"
|
2021-12-08 15:31:52 +00:00
|
|
|
"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 {
|
2022-01-08 16:21:53 +00:00
|
|
|
_, 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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 15:31:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.Render("views/404", fiber.Map{
|
|
|
|
"BASEURL": utils.URL,
|
|
|
|
})
|
|
|
|
}
|
2022-01-08 16:21:53 +00:00
|
|
|
|
|
|
|
_, err = db.StatsIncreaseViewsLinks()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
2021-12-08 15:31:52 +00:00
|
|
|
return c.Redirect(val)
|
|
|
|
}
|