83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package imgviewer
|
|
|
|
import (
|
|
"net/http"
|
|
"personalwebsite/apps"
|
|
"personalwebsite/webfilesystem"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type ImgViewerApp struct {
|
|
fs *webfilesystem.WebFileSystem
|
|
appID string
|
|
path string
|
|
manifest apps.ApplicationManifest
|
|
}
|
|
|
|
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) *ImgViewerApp {
|
|
newApp := ImgViewerApp{
|
|
fs: webFs,
|
|
appID: "ImgViewer",
|
|
}
|
|
return &newApp
|
|
}
|
|
func (p *ImgViewerApp) PrivateRoutes(route *gin.RouterGroup) {
|
|
p.PublicRoutes(route)
|
|
}
|
|
func (i *ImgViewerApp) GetManifest() apps.ApplicationManifest {
|
|
return i.manifest
|
|
}
|
|
func (p *ImgViewerApp) PublicRoutes(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)
|
|
}
|
|
})
|
|
}
|
|
|
|
func (p *ImgViewerApp) GetPath() string {
|
|
return p.path
|
|
}
|
|
|
|
func (p *ImgViewerApp) GetAppID() string {
|
|
return p.appID
|
|
}
|
|
|
|
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)
|
|
return gin.H{
|
|
"imgUrl": "/system/libs/img/get?path=" + filePath,
|
|
// "header": data.Header,
|
|
// "base64": data.Base64,
|
|
}, nil
|
|
}
|