port most routes

This commit is contained in:
orangix
2026-01-19 18:57:06 +01:00
parent 04fbc7f5f4
commit cd4a36c9f7
17 changed files with 310 additions and 213 deletions

View File

@@ -1,48 +1,49 @@
package pages
import (
"net/http"
"strings"
"codeberg.org/rimgo/rimgo/api"
"codeberg.org/rimgo/rimgo/render"
"codeberg.org/rimgo/rimgo/utils"
"github.com/gofiber/fiber/v2"
)
func HandleEmbed(c *fiber.Ctx) error {
utils.SetHeaders(c)
c.Set("Cache-Control", "public,max-age=31557600")
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")
func HandleEmbed(w http.ResponseWriter, r *http.Request) error {
utils.SetHeaders(w)
w.Header().Set("Cache-Control", "public,max-age=31557600")
w.Header().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")
post, err := api.Album{}, error(nil)
switch {
case strings.HasPrefix(c.Path(), "/a"):
post, err = ApiClient.FetchAlbum(c.Params("postID"))
case strings.HasPrefix(c.Path(), "/gallery"):
post, err = ApiClient.FetchPosts(c.Params("postID"))
case strings.HasPrefix(r.URL.Path, "/a"):
post, err = ApiClient.FetchAlbum(r.PathValue("postID"))
case strings.HasPrefix(r.URL.Path, "/gallery"):
post, err = ApiClient.FetchPosts(r.PathValue("postID"))
default:
post, err = ApiClient.FetchMedia(c.Params("postID"))
post, err = ApiClient.FetchMedia(r.PathValue("postID"))
}
if err != nil && err.Error() == "ratelimited by imgur" {
return utils.RenderError(c, 429)
return utils.RenderError(w, r, 429)
}
if err != nil && post.Id == "" && strings.Contains(err.Error(), "404") {
return utils.RenderError(c, 404)
return utils.RenderError(w, r, 404)
}
if err != nil {
return err
}
return c.Render("embed", fiber.Map{
return render.Render(w, "embed", map[string]any{
"post": post,
})
}
func HandleGifv(c *fiber.Ctx) error {
utils.SetHeaders(c)
c.Set("Cache-Control", "public,max-age=31557600")
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")
func HandleGifv(w http.ResponseWriter, r *http.Request) error {
utils.SetHeaders(w)
w.Header().Set("Cache-Control", "public,max-age=31557600")
w.Header().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")
return c.Render("gifv", fiber.Map{
"id": c.Params("postID"),
return render.Render(w, "gifv", map[string]any{
"id": r.PathValue("postID"),
})
}