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

48 lines
954 B
Go
Raw Normal View History

2023-04-12 21:05:23 +00:00
package imgviewer
import (
"personalwebsite/wde"
2023-04-29 16:47:12 +00:00
"personalwebsite/webfilesystem"
2023-04-12 21:05:23 +00:00
"personalwebsite/websiteapp"
"github.com/gin-gonic/gin"
)
type ImgViewerApp struct {
2023-04-29 16:47:12 +00:00
fs *webfilesystem.WebFileSystem
2023-04-12 21:05:23 +00:00
manifest websiteapp.ApplicationManifest
}
2023-04-29 16:47:12 +00:00
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) ImgViewerApp {
2023-04-12 21:05:23 +00:00
newApp := ImgViewerApp{
2023-04-29 16:47:12 +00:00
fs: webFs,
2023-04-12 21:05:23 +00:00
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
}
2023-04-29 16:47:12 +00:00
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
2023-04-29 16:47:12 +00:00
}
return gin.H{
"header": data.Header,
"base64": data.Base64,
2023-04-29 16:47:12 +00:00
}, nil
2023-04-12 21:05:23 +00:00
}