2022-02-18 21:56:56 +00:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
2023-06-10 16:27:20 +00:00
|
|
|
"codeberg.org/rimgo/rimgo/utils"
|
2022-02-18 21:56:56 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleTag(c *fiber.Ctx) error {
|
|
|
|
utils.SetHeaders(c)
|
2022-07-16 20:02:59 +00:00
|
|
|
c.Set("X-Frame-Options", "DENY")
|
2022-02-18 21:56:56 +00:00
|
|
|
c.Set("Cache-Control", "public,max-age=604800")
|
2023-08-10 15:02:51 +00:00
|
|
|
c.Set("Content-Security-Policy", "default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; style-src 'unsafe-inline' 'self'; media-src 'self'; img-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
|
|
|
|
}
|
|
|
|
|
2023-01-01 20:12:03 +00:00
|
|
|
tag, err := ApiClient.FetchTag(c.Params("tag"), c.Query("sort"), page)
|
2022-09-10 14:11:17 +00:00
|
|
|
if err != nil && err.Error() == "ratelimited by imgur" {
|
2024-02-05 02:24:55 +00:00
|
|
|
return utils.RenderError(c, 429)
|
2022-09-10 14:11:17 +00:00
|
|
|
}
|
2022-02-18 21:56:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-05-23 15:30:17 +00:00
|
|
|
if tag.Display == "" {
|
2024-02-05 02:24:55 +00:00
|
|
|
return utils.RenderError(c, 404)
|
2022-05-23 15:30:17 +00:00
|
|
|
}
|
2022-02-18 21:56:56 +00:00
|
|
|
|
|
|
|
return c.Render("tag", fiber.Map{
|
2024-02-05 02:24:55 +00:00
|
|
|
"tag": tag,
|
|
|
|
"page": page,
|
|
|
|
"nextPage": pageNumber + 1,
|
|
|
|
"prevPage": pageNumber - 1,
|
2022-02-18 21:56:56 +00:00
|
|
|
})
|
|
|
|
}
|