2022-02-23 00:06:39 +00:00
|
|
|
package pages
|
|
|
|
|
|
|
|
import (
|
2022-07-16 19:59:06 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"codeberg.org/video-prize-ranch/rimgo/api"
|
2022-02-23 00:06:39 +00:00
|
|
|
"codeberg.org/video-prize-ranch/rimgo/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleEmbed(c *fiber.Ctx) error {
|
|
|
|
utils.SetHeaders(c)
|
|
|
|
c.Set("Cache-Control", "public,max-age=31557600")
|
2022-11-18 17:08:18 +00:00
|
|
|
c.Set("Content-Security-Policy", "default-src 'none'; base-uri 'none'; form-action 'none'; media-src 'self'; style-src 'self'; img-src 'self'; block-all-mixed-content")
|
2022-02-23 00:06:39 +00:00
|
|
|
|
2022-07-22 15:55:22 +00:00
|
|
|
post, err := api.Album{}, error(nil)
|
2022-07-16 19:59:06 +00:00
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(c.Path(), "/a"):
|
|
|
|
post, err = api.FetchAlbum(c.Params("postID"))
|
|
|
|
case strings.HasPrefix(c.Path(), "/gallery"):
|
|
|
|
post, err = api.FetchPosts(c.Params("postID"))
|
|
|
|
default:
|
|
|
|
post, err = api.FetchMedia(c.Params("postID"))
|
|
|
|
}
|
2022-09-10 14:11:17 +00:00
|
|
|
if err != nil && err.Error() == "ratelimited by imgur" {
|
|
|
|
return c.Status(429).Render("errors/429", nil)
|
|
|
|
}
|
2022-09-13 20:31:55 +00:00
|
|
|
if err != nil && post.Id == "" && strings.Contains(err.Error(), "404") {
|
2022-09-10 14:11:17 +00:00
|
|
|
return c.Status(404).Render("errors/404", nil)
|
2022-07-16 19:59:06 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-23 00:06:39 +00:00
|
|
|
return c.Render("embed", fiber.Map{
|
2022-07-16 19:59:06 +00:00
|
|
|
"post": post,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleGifv(c *fiber.Ctx) error {
|
|
|
|
utils.SetHeaders(c)
|
|
|
|
c.Set("Cache-Control", "public,max-age=31557600")
|
2022-11-18 17:08:18 +00:00
|
|
|
c.Set("Content-Security-Policy", "default-src 'none'; base-uri 'none'; form-action 'none'; media-src 'self'; style-src 'self'; img-src 'self'; block-all-mixed-content")
|
2022-07-16 19:59:06 +00:00
|
|
|
|
|
|
|
return c.Render("gifv", fiber.Map{
|
2022-02-23 00:06:39 +00:00
|
|
|
"id": c.Params("postID"),
|
|
|
|
})
|
|
|
|
}
|