38 lines
663 B
Go
38 lines
663 B
Go
package routes
|
|
|
|
import (
|
|
"log"
|
|
|
|
"gitea.hackmi.ch/Phil/goshorly/db"
|
|
"gitea.hackmi.ch/Phil/goshorly/utils"
|
|
"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.Render("views/404", fiber.Map{
|
|
"BASEURL": utils.URL,
|
|
})
|
|
}
|
|
}
|
|
|
|
_, 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)
|
|
}
|