personal-website/websiteapp/img-viewer/imgviewer.go

48 lines
954 B
Go

package imgviewer
import (
"personalwebsite/wde"
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp"
"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) 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 := wde.ReadImage(img)
if err != nil {
return nil, err
}
return gin.H{
"header": data.Header,
"base64": data.Base64,
}, nil
}