From 95eaf959b0f08ffe9a6ab8d43bfba3ab9ddcbfe3 Mon Sep 17 00:00:00 2001 From: video-prize-ranch Date: Sat, 16 Jul 2022 15:59:06 -0400 Subject: [PATCH] Support embedded images/albums (closes #41) --- main.go | 5 ++++- pages/embed.go | 31 +++++++++++++++++++++++++++++ static/css/embed.css | 46 +++++++++++++++++++++++++++++++++++++++---- views/embed.hbs | 47 +++++++++++++++++++++++++++++++++----------- views/gifv.hbs | 28 ++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 17 deletions(-) create mode 100644 views/gifv.hbs diff --git a/main.go b/main.go index 362896a..2ab358c 100644 --- a/main.go +++ b/main.go @@ -51,16 +51,19 @@ func main() { }) app.Get("/", pages.HandleFrontpage) - app.Get("/:postID.gifv", pages.HandleEmbed) + app.Get("/:postID.gifv", pages.HandleGifv) app.Get("/:baseName.:extension", pages.HandleMedia) app.Get("/:postID", pages.HandlePost) + app.Get("/:postID/embed", pages.HandleEmbed) app.Get("/a/:postID", pages.HandlePost) + app.Get("/a/:postID/embed", pages.HandleEmbed) app.Get("/t/:tag", pages.HandleTag) app.Get("/user/:userID", pages.HandleUser) app.Get("/r/:sub/:postID", pages.HandlePost) app.Get("/user/:userID/cover", pages.HandleUserCover) app.Get("/user/:userID/avatar", pages.HandleUserAvatar) app.Get("/gallery/:postID", pages.HandlePost) + app.Get("/gallery/:postID/embed", pages.HandleEmbed) app.Listen(utils.Config["addr"].(string) + ":" + utils.Config["port"].(string)) } diff --git a/pages/embed.go b/pages/embed.go index d425781..3471337 100644 --- a/pages/embed.go +++ b/pages/embed.go @@ -1,6 +1,10 @@ package pages import ( + "strings" + + "codeberg.org/video-prize-ranch/rimgo/api" + "codeberg.org/video-prize-ranch/rimgo/types" "codeberg.org/video-prize-ranch/rimgo/utils" "github.com/gofiber/fiber/v2" ) @@ -10,7 +14,34 @@ func HandleEmbed(c *fiber.Ctx) error { c.Set("Cache-Control", "public,max-age=31557600") c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content") + post, err := types.Album{}, error(nil) + 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")) + } + if post.Id == "" || (err != nil && strings.Contains(err.Error(), "404")) { + c.Status(404) + return c.Render("errors/404", nil) + } + if err != nil { + return err + } + return c.Render("embed", fiber.Map{ + "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'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content") + + return c.Render("gifv", fiber.Map{ "id": c.Params("postID"), }) } \ No newline at end of file diff --git a/static/css/embed.css b/static/css/embed.css index 9c5f952..2fb8652 100644 --- a/static/css/embed.css +++ b/static/css/embed.css @@ -2,12 +2,50 @@ filter: invert(180deg), hue-rotate(180deg); } -.postLink { +body { + overflow: hidden; +} + +.mediaWrapper { + display: flex; + justify-content: center; +} + +.media { + display: flex; + overflow: scroll; + gap: 1rem; + align-items: center; + height: 90vh; +} + +.media img, .media video { + height: 100%; +} + +.logoContainer { display: flex; - flex-direction: row; align-items: center; } -.rimgoLink { - width: 100%; +.views { + display: flex; + gap: 4px; + align-items: center; +} + +.postDetails { + display: flex; + gap: 1rem; +} + +h3 { + font-size: 1em; +} + +.postMeta { + display: flex; + align-items: center; + justify-content: space-between; + height: 9vh; } \ No newline at end of file diff --git a/views/embed.hbs b/views/embed.hbs index e7438ae..5097639 100644 --- a/views/embed.hbs +++ b/views/embed.hbs @@ -4,22 +4,45 @@ {{> partials/head }} + - -