rimgo/pages/gallery.go

35 lines
854 B
Go
Raw Normal View History

2022-01-18 21:45:57 +00:00
package pages
import (
"codeberg.org/video-prize-ranch/rimgo/api"
2022-01-20 21:09:57 +00:00
"codeberg.org/video-prize-ranch/rimgo/types"
2022-01-28 01:41:10 +00:00
"codeberg.org/video-prize-ranch/rimgo/utils"
2022-01-18 21:45:57 +00:00
"github.com/gofiber/fiber/v2"
)
func HandleGallery(c *fiber.Ctx) error {
2022-01-28 01:41:10 +00:00
utils.SetHeaders(c)
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
2022-01-18 21:45:57 +00:00
album, err := api.FetchAlbum(c.Params("galleryID"))
if err != nil {
return err
}
2022-01-20 21:09:57 +00:00
comments := []types.Comment{}
2022-01-24 01:59:29 +00:00
if album.SharedWithCommunity {
2022-01-28 01:41:10 +00:00
c.Set("Cache-Control", "public,max-age=604800")
2022-01-20 21:09:57 +00:00
comments, err = api.FetchComments(c.Params("galleryID"))
if err != nil {
return err
}
2022-01-28 01:41:10 +00:00
} else {
c.Set("Cache-Control", "public,max-age=31557600")
2022-01-18 23:05:06 +00:00
}
return c.Render("post", fiber.Map{
"post": album,
2022-01-18 23:05:06 +00:00
"comments": comments,
2022-01-18 21:45:57 +00:00
})
}