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

48 lines
959 B
Go
Raw Normal View History

2023-04-12 21:05:23 +00:00
package imgviewer
import (
2023-05-02 00:12:43 +00:00
"personalwebsite/libs"
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
}
2023-05-02 00:12:43 +00:00
data, err := libs.ReadImage(img)
if err != nil {
return nil, err
2023-04-29 16:47:12 +00:00
}
return gin.H{
"header": data.Header,
2023-05-01 12:32:41 +00:00
// "base64": data.Base64,
2023-04-29 16:47:12 +00:00
}, nil
2023-04-12 21:05:23 +00:00
}