Gallery and video support

This commit is contained in:
video-prize-ranch 2022-01-18 16:45:57 -05:00
parent af756d2b0a
commit 87c8618cf5
No known key found for this signature in database
GPG Key ID: D8EAA4C5B12A7281
8 changed files with 48 additions and 3 deletions

View File

@ -35,6 +35,8 @@ func FetchAlbum(albumID string) (types.Album, error) {
media = append(media, types.Media{ media = append(media, types.Media{
Id: value.Get("id").String(), Id: value.Get("id").String(),
Name: value.Get("name").String(), Name: value.Get("name").String(),
MimeType: value.Get("mime_type").String(),
Type: value.Get("type").String(),
Title: value.Get("metadata.title").String(), Title: value.Get("metadata.title").String(),
Description: value.Get("metadata.description").String(), Description: value.Get("metadata.description").String(),
Url: url, Url: url,

View File

@ -48,8 +48,8 @@ func main() {
app.Get("/a/:albumID", pages.HandleAlbum) app.Get("/a/:albumID", pages.HandleAlbum)
app.Get("/t/:tagID", pages.HandleAlbum) app.Get("/t/:tagID", pages.HandleAlbum)
/*app.Get("/user/:userID", pages.HandleUser) /*app.Get("/user/:userID", pages.HandleUser)
app.Get("/user/:userID/cover", pages.HandleUserCover) app.Get("/user/:userID/cover", pages.HandleUserCover)*/
app.Get("/gallery/:galleryID", pages.HandleGallery)*/ app.Get("/gallery/:galleryID", pages.HandleGallery)
app.Listen(":" + viper.GetString("RIMGU_PORT")) app.Listen(":" + viper.GetString("RIMGU_PORT"))
} }

27
pages/gallery.go Normal file
View File

@ -0,0 +1,27 @@
package pages
import (
"codeberg.org/video-prize-ranch/rimgo/api"
"github.com/gofiber/fiber/v2"
)
func HandleGallery(c *fiber.Ctx) error {
c.Set("Cache-Control", "public,max-age=604800")
c.Set("X-Frame-Options", "DENY")
c.Set("Referrer-Policy", "no-referrer")
c.Set("X-Content-Type-Options", "nosniff")
c.Set("X-Robots-Tag", "noindex, noimageindex, nofollow")
c.Set("Strict-Transport-Security", "max-age=31557600")
c.Set("Permissions-Policy", "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), interest-cohort=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()")
c.Set("Content-Security-Policy", "default-src 'none'; media-src 'self'; style-src 'self'; script-src 'none'; img-src 'self'; font-src 'self'; block-all-mixed-content; manifest-src 'self'")
album, err := api.FetchAlbum(c.Params("galleryID"))
if err != nil {
return err
}
return c.Render("gallery", fiber.Map{
"album": album,
"isAlbum": false,
})
}

View File

@ -6,6 +6,7 @@ p {
margin: 0.5em 0; margin: 0.5em 0;
} }
video,
img { img {
max-width: 100%; max-width: 100%;
} }

View File

@ -6,4 +6,6 @@ type Media struct {
Title string Title string
Description string Description string
Url string Url string
Type string
MimeType string
} }

View File

@ -18,7 +18,11 @@
<h3>Try it!</h3> <h3>Try it!</h3>
<a href="/a/H8M4rcp">Album</a> <ul>
<li><a href="/a/H8M4rcp">Album</a></li>
<li><a href="/gallery/gYiQLWy">Gallery</a></li>
<li><a href="/gallery/cTRwaJU">Video</a></li>
</ul>
<h2>Features</h2> <h2>Features</h2>

View File

@ -42,6 +42,8 @@
</div>--> </div>-->
</div> </div>
<br>
{{#each album.Media}} {{#each album.Media}}
{{#if this.Title}} {{#if this.Title}}
<h3>{{this.Title}}</h3> <h3>{{this.Title}}</h3>
@ -51,7 +53,14 @@
{{/if}} {{/if}}
<div class="center"> <div class="center">
{{#equal this.Type "image"}}
<img src="{{this.Url}}" loading="lazy"> <img src="{{this.Url}}" loading="lazy">
{{/equal}}
{{#equal this.Type "video"}}
<video controls loop>
<source type="{{this.MimeType}}" src="{{this.Url}}" />
</video>
{{/equal}}
</div> </div>
<br> <br>