diff --git a/main.go b/main.go index ade89bc..67624bc 100644 --- a/main.go +++ b/main.go @@ -66,7 +66,7 @@ func main() { persPropsApp := personalprops.NewPersPropsApp() // finderApp := finder.FinderApplication{} finderApp := finder.NewFinderApplication(webfs) - imgViewerApp := imgviewer.NewImgViewerApp() + imgViewerApp := imgviewer.NewImgViewerApp(webfs) blogViewerApp := blogviewer.NewBlogViewerApp(webfs) appsStorage := websiteapp.ApplicationsStorage{ Apps: map[string]websiteapp.WebDEApplication{}, @@ -214,10 +214,20 @@ func main() { imgViewerRoute.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 := imgViewerApp.Render(path, isMobile) + if err != nil { + ctx.JSON(http.StatusInternalServerError, "TODO") + return + } if isMobile { - ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", imgViewerApp.Render(isMobile)) + ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", ginH) } else { - ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", imgViewerApp.Render(isMobile)) + ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", ginH) } }) diff --git a/resources/sys/finder/finder.js b/resources/sys/finder/finder.js index ef72590..a63bd04 100644 --- a/resources/sys/finder/finder.js +++ b/resources/sys/finder/finder.js @@ -89,9 +89,9 @@ class Finder{ // //TODO get real id // WebDesktopEnvironment.Open("personal-properties", []) // break; - // case "img": - // WebDesktopEnvironment.Open("img-viewer", ["pizda"]) - // break; + case "base64img": + WebDesktopEnvironment.Open("img-viewer", [this.path + "/" + fileName]) + break; default: console.log("Unsupported file type") break; diff --git a/resources/sys/img-viewer/img-viewer.js b/resources/sys/img-viewer/img-viewer.js index f78f24d..dad75d9 100644 --- a/resources/sys/img-viewer/img-viewer.js +++ b/resources/sys/img-viewer/img-viewer.js @@ -1,11 +1,12 @@ class ImgViewer{ appId = "img-viewer" /** - * @param {string} path + * @param {string[]} args */ - NewWindow(path){ + NewWindow(args){ fetch(`${window.location.origin}/application/${this.appId}/render?`+ new URLSearchParams({ isMobile: WebDesktopEnvironment.isMobile, + path: args[0] })) .then((response) => response.text()) .then((html) => { @@ -24,7 +25,3 @@ class ImgViewer{ } } - -class test{ - -} diff --git a/templates/img-viewer/app.tmpl b/templates/img-viewer/app.tmpl index 90caa45..633cf80 100644 --- a/templates/img-viewer/app.tmpl +++ b/templates/img-viewer/app.tmpl @@ -1,5 +1,5 @@ {{ define "img-viewer/app.tmpl" }} -
+
@@ -12,7 +12,7 @@ Toolbar
-->
-
+
{{ end }} diff --git a/websiteapp/img-viewer/imgviewer.go b/websiteapp/img-viewer/imgviewer.go index 1ab6c51..b03e32c 100644 --- a/websiteapp/img-viewer/imgviewer.go +++ b/websiteapp/img-viewer/imgviewer.go @@ -1,17 +1,22 @@ 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() ImgViewerApp { +func NewImgViewerApp(webFs *webfilesystem.WebFileSystem) ImgViewerApp { newApp := ImgViewerApp{ + fs: webFs, manifest: websiteapp.ApplicationManifest{ AppId: "img-viewer", WindowName: "About me", //TODO: delete @@ -27,9 +32,21 @@ func (p *ImgViewerApp) GetId() string { return p.manifest.AppId } -func (p *ImgViewerApp) Render(isMobile bool) gin.H { - return gin.H{ - "Name": "Greg Brzezinski", - "BasicBio": "Born 27.09.1998 at Saint-Petersburg", +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 }