diff --git a/api/album.go b/api/album.go index 6754ae5..6ef9948 100644 --- a/api/album.go +++ b/api/album.go @@ -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 diff --git a/main.go b/main.go index c253ac1..ea911e2 100644 --- a/main.go +++ b/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) diff --git a/pages/media.go b/pages/media.go index f93011e..6781863 100644 --- a/pages/media.go +++ b/pages/media.go @@ -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 } \ No newline at end of file diff --git a/static/css/album.css b/static/css/album.css new file mode 100644 index 0000000..e69de29 diff --git a/static/css/base.css b/static/css/base.css new file mode 100644 index 0000000..6b4e203 --- /dev/null +++ b/static/css/base.css @@ -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%; +} \ No newline at end of file diff --git a/views/gallery.hbs b/views/gallery.hbs index 2813156..813fc86 100644 --- a/views/gallery.hbs +++ b/views/gallery.hbs @@ -1,11 +1,19 @@ +
{{> partials/head }} + + - {{#each album.Media}} - - {{/each}} + {{> partials/header }} + +