Stream images

This commit is contained in:
video-prize-ranch 2022-01-17 15:48:24 -05:00
parent 2ee4aa7237
commit ac98a54f79
No known key found for this signature in database
GPG Key ID: D8EAA4C5B12A7281
8 changed files with 31 additions and 23 deletions

View File

@ -30,8 +30,7 @@ func FetchAlbum(albumID string) (types.Album, error) {
data.Get("media").ForEach( data.Get("media").ForEach(
func(key gjson.Result, value gjson.Result) bool { func(key gjson.Result, value gjson.Result) bool {
url := value.Get("url").String() url := value.Get("url").String()
println(url) url = strings.ReplaceAll(url, "https://i.imgur.com", "/media")
url = strings.ReplaceAll(url, "https://i.imgur.com", "")
media = append(media, url) media = append(media, url)
return true return true

View File

@ -43,7 +43,7 @@ func main() {
Root: http.FS(static.GetFiles()), Root: http.FS(static.GetFiles()),
})) }))
app.Get("/:baseName.:extension", pages.HandleMedia) app.Get("/media/:baseName.:extension", pages.HandleMedia)
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)

View File

@ -1,29 +1,20 @@
package pages package pages
import ( import (
"io"
"net/http" "net/http"
"strconv"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func HandleMedia(c *fiber.Ctx) error { func HandleMedia(c *fiber.Ctx) error {
res, err := FetchMedia(c.Params("baseName") + "." + c.Params("extension")) res, err := http.Get("https://i.imgur.com/" + c.Params("baseName") + "." + c.Params("extension"))
if err != nil {
return err
}
data, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return err return err
} }
c.Set("Content-Type", res.Header.Get("Content-Type")); c.Set("Content-Type", res.Header.Get("Content-Type"));
c.Write(data) contentLen, _ := strconv.Atoi(res.Header.Get("Content-Length"))
c.SendStream(res.Body, contentLen)
return nil return nil
} }
func FetchMedia(filename string) (*http.Response, error) {
res, err := http.Get("https://i.imgur.com/" + filename)
return res, err
}

0
static/css/album.css Normal file
View File

11
static/css/base.css Normal file
View File

@ -0,0 +1,11 @@
body {
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif;
}
main {
margin: 0 18vw;
}
img {
max-width: 100%;
}

View File

@ -1,11 +1,19 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
{{> partials/head }} {{> partials/head }}
<link rel="stylesheet" href="/static/css/album.css" />
</head> </head>
<body> <body>
{{> partials/header }}
<main>
{{#each album.Media}} {{#each album.Media}}
<img src="{{this}}" loading="lazy"> <img src="{{this}}" loading="lazy">
{{/each}} {{/each}}
</main>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
<title>rimgu</title> <title>rimgo</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
@ -16,5 +16,4 @@
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
--> -->
<link rel="stylesheet" href="/css/styles.css"/> <link rel="stylesheet" href="/static/css/base.css"/>
<link rel="stylesheet" href="/css/custom.css"/>

View File

@ -1,3 +1,3 @@
<nav> <nav>
<h2>rimgu</h2> <h2>rimgo</h2>
</nav> </nav>