2023-08-14 22:47:59 +00:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"codeberg.org/rimgo/rimgo/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleTrending(c *fiber.Ctx) error {
|
|
|
|
utils.SetHeaders(c)
|
|
|
|
c.Set("X-Frame-Options", "DENY")
|
|
|
|
c.Set("Cache-Control", "public,max-age=604800")
|
2023-06-13 13:37:00 +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' https://i.imgur.com https://i.stack.imgur.com; img-src 'self' https://i.imgur.com https://i.stack.imgur.com; manifest-src 'self'; block-all-mixed-content")
|
2023-08-14 22:47:59 +00:00
|
|
|
|
|
|
|
page := "1"
|
|
|
|
if c.Query("page") != "" {
|
|
|
|
page = c.Query("page")
|
|
|
|
}
|
|
|
|
|
|
|
|
pageNumber, err := strconv.Atoi(c.Query("page"))
|
|
|
|
if err != nil {
|
|
|
|
pageNumber = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
section := c.Query("section")
|
|
|
|
switch section {
|
|
|
|
case "hot", "new", "top":
|
|
|
|
default:
|
|
|
|
section = "hot"
|
|
|
|
}
|
|
|
|
sort := c.Query("sort")
|
|
|
|
switch sort {
|
|
|
|
case "newest", "best", "popular":
|
|
|
|
default:
|
|
|
|
sort = "popular"
|
|
|
|
}
|
|
|
|
|
|
|
|
results, err := ApiClient.FetchTrending(section, sort, page)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Render("trending", fiber.Map{
|
|
|
|
"results": results,
|
|
|
|
"section": section,
|
|
|
|
"sort": sort,
|
|
|
|
"page": pageNumber,
|
|
|
|
"nextPage": pageNumber + 1,
|
|
|
|
"prevPage": pageNumber - 1,
|
|
|
|
})
|
|
|
|
}
|