Stream images
This commit is contained in:
parent
2ee4aa7237
commit
ac98a54f79
|
@ -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
|
||||
|
|
2
main.go
2
main.go
|
@ -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)
|
||||
|
|
|
@ -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,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%;
|
||||
}
|
|
@ -1,11 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
{{> partials/head }}
|
||||
<link rel="stylesheet" href="/static/css/album.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{> partials/header }}
|
||||
|
||||
<main>
|
||||
{{#each album.Media}}
|
||||
<img src="{{this}}" loading="lazy">
|
||||
{{/each}}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -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"/>
|
|
@ -1,3 +1,3 @@
|
|||
<nav>
|
||||
<h2>rimgu</h2>
|
||||
<h2>rimgo</h2>
|
||||
</nav>
|
Loading…
Reference in New Issue