rimgo/pages/tag.go

48 lines
1.0 KiB
Go
Raw Normal View History

2022-02-18 21:56:56 +00:00
package pages
import (
"strconv"
"codeberg.org/video-prize-ranch/rimgo/api"
"codeberg.org/video-prize-ranch/rimgo/utils"
"github.com/gofiber/fiber/v2"
)
func HandleTag(c *fiber.Ctx) error {
utils.SetHeaders(c)
c.Set("Cache-Control", "public,max-age=604800")
2022-06-25 19:23:59 +00:00
c.Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline' 'self'; media-src 'self'; img-src 'self'; font-src 'self'; manifest-src 'self'; block-all-mixed-content")
2022-02-18 21:56:56 +00:00
page := "1"
if c.Query("page") != "" {
page = c.Query("page")
}
pageNumber, err := strconv.Atoi(c.Query("page"))
if err != nil {
pageNumber = 0
}
displayPrevPage := true
if page == "1" {
displayPrevPage = false
}
tag, err := api.FetchTag(c.Params("tag"), c.Query("sort"), page)
if err != nil {
return err
}
2022-05-23 15:30:17 +00:00
if tag.Display == "" {
c.Status(404)
return c.Render("errors/404", nil)
}
2022-02-18 21:56:56 +00:00
return c.Render("tag", fiber.Map{
"tag": tag,
"page": page,
"displayPrev": displayPrevPage,
"nextPage": pageNumber + 1,
"prevPage": pageNumber - 1,
})
}