Add support for .gifv (closes #13) and fixes loading media IDs
This commit is contained in:
parent
156452713b
commit
4572499658
16
api/album.go
16
api/album.go
|
@ -52,6 +52,22 @@ func FetchPosts(albumID string) (types.Album, error) {
|
||||||
return ParseAlbum(data)
|
return ParseAlbum(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FetchMedia(mediaID string) (types.Album, error) {
|
||||||
|
res, err := http.Get("https://api.imgur.com/post/v1/media/" + mediaID + "?client_id=" + viper.GetString("RIMGU_IMGUR_CLIENT_ID") + "&include=media%2Caccount")
|
||||||
|
if err != nil {
|
||||||
|
return types.Album{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return types.Album{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := gjson.Parse(string(body))
|
||||||
|
|
||||||
|
return ParseAlbum(data)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseAlbum(data gjson.Result) (types.Album, error) {
|
func ParseAlbum(data gjson.Result) (types.Album, error) {
|
||||||
media := make([]types.Media, 0)
|
media := make([]types.Media, 0)
|
||||||
data.Get("media").ForEach(
|
data.Get("media").ForEach(
|
||||||
|
|
3
main.go
3
main.go
|
@ -49,7 +49,8 @@ func main() {
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/", pages.FrontpageHandler)
|
app.Get("/", pages.HandleFrontpage)
|
||||||
|
app.Get("/:postID.gifv", pages.HandleEmbed)
|
||||||
app.Get("/:baseName.:extension", pages.HandleMedia)
|
app.Get("/:baseName.:extension", pages.HandleMedia)
|
||||||
app.Get("/:postID", pages.HandlePost)
|
app.Get("/:postID", pages.HandlePost)
|
||||||
app.Get("/a/:galleryID", pages.HandleGallery)
|
app.Get("/a/:galleryID", pages.HandleGallery)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package pages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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")
|
||||||
|
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("embed", fiber.Map{
|
||||||
|
"id": c.Params("postID"),
|
||||||
|
})
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FrontpageHandler(c *fiber.Ctx) error {
|
func HandleFrontpage(c *fiber.Ctx) error {
|
||||||
utils.SetHeaders(c)
|
utils.SetHeaders(c)
|
||||||
c.Set("Cache-Control", "public,max-age=31557600")
|
c.Set("Cache-Control", "public,max-age=31557600")
|
||||||
c.Set("Content-Security-Policy", "default-src 'none'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
|
c.Set("Content-Security-Policy", "default-src 'none'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package pages
|
package pages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"codeberg.org/video-prize-ranch/rimgo/api"
|
"codeberg.org/video-prize-ranch/rimgo/api"
|
||||||
"codeberg.org/video-prize-ranch/rimgo/types"
|
"codeberg.org/video-prize-ranch/rimgo/types"
|
||||||
"codeberg.org/video-prize-ranch/rimgo/utils"
|
"codeberg.org/video-prize-ranch/rimgo/utils"
|
||||||
|
@ -12,7 +14,16 @@ func HandlePost(c *fiber.Ctx) error {
|
||||||
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; img-src 'self'; font-src 'self'; block-all-mixed-content")
|
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 := api.FetchPosts(c.Params("postID"))
|
post, err := api.FetchPosts(c.Params("postID"))
|
||||||
if err != nil {
|
if post.Id == "" {
|
||||||
|
post, err = api.FetchPosts(c.Params("postID"))
|
||||||
|
if post.Id == "" {
|
||||||
|
post, err = api.FetchMedia(c.Params("postID"))
|
||||||
|
if post.Id == "" {
|
||||||
|
return fmt.Errorf("404 page not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
.logo {
|
||||||
|
filter: invert(180deg), hue-rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.postLink {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rimgoLink {
|
||||||
|
width: 100%;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
{{> partials/head }}
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/static/css/embed.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<video loop poster="/{{id}}.webp" autoplay width="100%">
|
||||||
|
<source src="/{{id}}.webm" type="video/webm" />
|
||||||
|
<source src="/{{id}}.mp4" type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
<div class="postLink">
|
||||||
|
<a href="/{{id}}">
|
||||||
|
<img src="/static/img/rimgo.svg" width="32px" height="32px" class="logo">
|
||||||
|
</a>
|
||||||
|
<a href="/{{id}}" class="rimgoLink">
|
||||||
|
rimgo
|
||||||
|
</a>
|
||||||
|
<a href="/{{id}}.mp4?download=1">download</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in New Issue