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(
func(key gjson.Result, value gjson.Result) bool {
url := value.Get("url").String()
println(url)
url = strings.ReplaceAll(url, "https://i.imgur.com", "")
url = strings.ReplaceAll(url, "https://i.imgur.com", "/media")
media = append(media, url)
return true

View File

@ -43,7 +43,7 @@ func main() {
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("/t/:tagID", pages.HandleAlbum)
/*app.Get("/user/:userID", pages.HandleUser)

View File

@ -1,29 +1,20 @@
package pages
import (
"io"
"net/http"
"strconv"
"github.com/gofiber/fiber/v2"
)
func HandleMedia(c *fiber.Ctx) error {
res, err := FetchMedia(c.Params("baseName") + "." + c.Params("extension"))
if err != nil {
return err
}
data, err := io.ReadAll(res.Body)
res, err := http.Get("https://i.imgur.com/" + c.Params("baseName") + "." + c.Params("extension"))
if err != nil {
return err
}
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
}
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>
<html lang="en">
<head>
{{> partials/head }}
<link rel="stylesheet" href="/static/css/album.css" />
</head>
<body>
{{#each album.Media}}
<img src="{{this}}" loading="lazy">
{{/each}}
{{> partials/header }}
<main>
{{#each album.Media}}
<img src="{{this}}" loading="lazy">
{{/each}}
</main>
</body>
</html>

View File

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

View File

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