From 6e84441dab0a2b89869e33d7e89d14189d9b67c0 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sat, 1 Jul 2023 17:55:50 +0200 Subject: feat: Add thumbnailer --- pkg/view/media.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pkg/view/media.go') diff --git a/pkg/view/media.go b/pkg/view/media.go index ce9e272..0b588f4 100644 --- a/pkg/view/media.go +++ b/pkg/view/media.go @@ -93,9 +93,23 @@ func (self *MediaView) GetImage(ctx *fasthttp.RequestCtx) error { return nil } +func (self *MediaView) GetThumbnail(ctx *fasthttp.RequestCtx) error { + pathHash := string(ctx.FormValue("path_hash")) + + path, err := self.mediaRepository.GetThumbnailPath(ctx, pathHash) + if err != nil { + return self.GetImage(ctx) + } + + ctx.Request.Header.SetContentType("image/jpeg") + fasthttp.ServeFileUncompressed(ctx, path) + return nil +} + func (self *MediaView) SetMyselfIn(r *ext.Router) { r.GET("/media", self.Index) r.POST("/media", self.Index) r.GET("/media/image", self.GetImage) + r.GET("/media/thumbnail", self.GetThumbnail) } -- cgit v1.2.3