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

83 lines
1.8 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"
2023-07-23 03:12:17 +00:00
"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-07-23 03:12:17 +00:00
fs *webfilesystem.WebFileSystem
appID string
path string
manifest apps.ApplicationManifest
2023-04-12 21:05:23 +00:00
}
func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) *ImgViewerApp {
2023-04-12 21:05:23 +00:00
newApp := ImgViewerApp{
fs: webFs,
appID: "ImgViewer",
2023-04-12 21:05:23 +00:00
}
return &newApp
2023-04-12 21:05:23 +00:00
}
func (p *ImgViewerApp) PrivateRoutes(route *gin.RouterGroup) {
p.PublicRoutes(route)
}
2023-07-23 03:12:17 +00:00
func (i *ImgViewerApp) GetManifest() apps.ApplicationManifest {
return i.manifest
}
func (p *ImgViewerApp) PublicRoutes(route *gin.RouterGroup) {
2023-05-03 21:50:08 +00:00
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-07-23 03:12:17 +00:00
func (p *ImgViewerApp) GetPath() string {
return p.path
}
func (p *ImgViewerApp) GetAppID() string {
return p.appID
2023-04-12 21:05:23 +00:00
}
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
}