package imgviewer import ( "errors" "personalwebsite/webfilesystem" "personalwebsite/websiteapp" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) 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 } header, ok := img.Data.(primitive.D).Map()["header"] if !ok { return nil, errors.New("error in file decoding") } base64, ok := img.Data.(primitive.D).Map()["base64"] if !ok { return nil, errors.New("error in file decoding") } return gin.H{ "header": header, "base64": base64, }, nil }