package imgviewer import ( "net/http" websiteapp "personalwebsite/apps" "personalwebsite/libs" "personalwebsite/webfilesystem" "github.com/gin-gonic/gin" ) type ImgViewerApp struct { fs *webfilesystem.WebFileSystem manifest websiteapp.ApplicationManifest } func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) ImgViewerApp { newApp := ImgViewerApp{ fs: webFs, manifest: websiteapp.ApplicationManifest{ AppId: "img-viewer", WindowName: "About me", //TODO: delete }, } return newApp } func (p *ImgViewerApp) Route(route *gin.RouterGroup) { route.GET("render", func(ctx *gin.Context) { isMobileParam := ctx.Query("isMobile") isMobile := isMobileParam == "true" path := ctx.Query("path") if path == "" { ctx.JSON(http.StatusBadRequest, "no path provided") return } ginH, err := p.Render(path, isMobile) if err != nil { ctx.JSON(http.StatusInternalServerError, "TODO") return } if isMobile { ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", ginH) } else { ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", ginH) } }) } func (p *ImgViewerApp) GetManifest() websiteapp.ApplicationManifest { return p.manifest } func (p *ImgViewerApp) GetId() string { return p.manifest.AppId } func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) { img, err := p.fs.Read(path) if err != nil { return nil, err } data, err := libs.ReadImage(img) if err != nil { return nil, err } return gin.H{ "header": data.Header, // "base64": data.Base64, }, nil }