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

77 lines
1.7 KiB
Go
Raw Normal View History

2023-04-12 21:05:23 +00:00
package imgviewer
import (
2023-05-03 21:50:08 +00:00
"net/http"
websiteapp "personalwebsite/apps"
2023-04-29 16:47:12 +00:00
"personalwebsite/webfilesystem"
2023-04-12 21:05:23 +00:00
"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{
2023-05-07 21:20:40 +00:00
AppId: "img-viewer",
2023-04-12 21:05:23 +00:00
},
}
return newApp
}
2023-05-03 21:50:08 +00:00
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)
}
})
}
2023-04-12 21:05:23 +00:00
func (p *ImgViewerApp) GetManifest() websiteapp.ApplicationManifest {
return p.manifest
}
func (p *ImgViewerApp) GetId() string {
return p.manifest.AppId
}
2023-05-05 20:31:42 +00:00
func (p *ImgViewerApp) Render(filePath string, isMobile bool) (gin.H, error) {
// file, err := p.fs.NewRead(filePath)
// if err != nil {
// return nil, err
// }
// println(file.Data.(primitive.Binary).Data)
// img, err := p.fs.NewRead(path)
// if err != nil {
// return nil, err
// }
// data, err := libs.ReadImage(img)
// if err != nil {
// return nil, err
// }
// url := location.Get(ctx)
2023-04-29 16:47:12 +00:00
return gin.H{
2023-05-05 20:31:42 +00:00
"imgUrl": "/system/libs/img/get?path=" + filePath,
// "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
}