From e9422f797b72ef9d5ad43436e8d240ce4a7f10a7 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sat, 29 Apr 2023 23:17:34 +0300 Subject: [PATCH] props markup fixes + shared lib to read images --- main.go | 2 +- resources/wde.js | 2 +- templates/personal-properties/app.tmpl | 7 ++-- wde/imglib.go | 29 ++++++++++++++ websiteapp/img-viewer/imgviewer.go | 17 +++------ websiteapp/personalprops/personalprops.go | 46 +++++++++++++++-------- 6 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 wde/imglib.go diff --git a/main.go b/main.go index 7db1803..5a25850 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection) wde := wde.NewWDE(webfs) persPropsApp := personalprops.NewPersPropsApp(webfs) - persPropsApp.WriteToDb() + // finderApp := finder.FinderApplication{} finderApp := finder.NewFinderApplication(webfs) imgViewerApp := imgviewer.NewImgViewerApp(webfs) diff --git a/resources/wde.js b/resources/wde.js index b58cd79..9972160 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function() { if (!WebDesktopEnvironment.isMobile){ WebDesktopEnvironment.Open("finder", ["/home/user"]) // WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) - // WebDesktopEnvironment.Open("personal-properties", ["kek"]) + WebDesktopEnvironment.Open("personal-properties", ["kek"]) } else { WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) } diff --git a/templates/personal-properties/app.tmpl b/templates/personal-properties/app.tmpl index f3481aa..7ee1b31 100644 --- a/templates/personal-properties/app.tmpl +++ b/templates/personal-properties/app.tmpl @@ -13,10 +13,11 @@
- My Photo + My Photo
-
{{ .Name }}
-
{{ .BasicBio }}
+
{{ .headerProps.Name }}
+
{{ .headerProps.Info1 }}
+
{{ .headerProps.Info2 }}
{{ range $propIsland := .allprops }} diff --git a/wde/imglib.go b/wde/imglib.go new file mode 100644 index 0000000..6f549de --- /dev/null +++ b/wde/imglib.go @@ -0,0 +1,29 @@ +package wde + +import ( + "errors" + "personalwebsite/webfilesystem" + + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func ReadImage(img *webfilesystem.WebFSFile) (*Base64Img, error) { + header, ok := img.Data.(primitive.D).Map()["header"].(string) + if !ok { + return nil, errors.New("error in file decoding") + } + base64, ok := img.Data.(primitive.D).Map()["base64"].(string) + if !ok { + return nil, errors.New("error in file decoding") + } + + return &Base64Img{ + Header: header, + Base64: base64, + }, nil +} + +type Base64Img struct { + Header string + Base64 string +} diff --git a/websiteapp/img-viewer/imgviewer.go b/websiteapp/img-viewer/imgviewer.go index b03e32c..10fc7f8 100644 --- a/websiteapp/img-viewer/imgviewer.go +++ b/websiteapp/img-viewer/imgviewer.go @@ -1,12 +1,11 @@ package imgviewer import ( - "errors" + "personalwebsite/wde" "personalwebsite/webfilesystem" "personalwebsite/websiteapp" "github.com/gin-gonic/gin" - "go.mongodb.org/mongo-driver/bson/primitive" ) type ImgViewerApp struct { @@ -37,16 +36,12 @@ func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) { 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") + data, err := wde.ReadImage(img) + if err != nil { + return nil, err } return gin.H{ - "header": header, - "base64": base64, + "header": data.Header, + "base64": data.Base64, }, nil } diff --git a/websiteapp/personalprops/personalprops.go b/websiteapp/personalprops/personalprops.go index 62857b9..429af55 100644 --- a/websiteapp/personalprops/personalprops.go +++ b/websiteapp/personalprops/personalprops.go @@ -1,6 +1,8 @@ package personalprops import ( + "errors" + "personalwebsite/wde" "personalwebsite/webfilesystem" "personalwebsite/websiteapp" @@ -141,7 +143,27 @@ func (p *PersonalPropertiesApp) Render() (gin.H, error) { if err != nil { return nil, err } - _ = props + if props.Data == nil || props.Type != "props" { + return nil, errors.New("bad file") + } + headerProps := props.Data.(primitive.D).Map()["headerprops"].(primitive.D).Map() + file, err := p.fs.Read(headerProps["icon"].(string)) + if err != nil { + //TODO + } + + data, err := wde.ReadImage(file) + if err != nil { + return nil, err + } + + hIsland := HeaderIsland{ + Name: headerProps["name"].(string), + Icon: data, + Info1: "LLL", + Info2: "QQQ", + } + allProps := make([]PropIsland, 0) for _, v := range props.Data.(primitive.D).Map()["props"].(primitive.A) { @@ -150,8 +172,6 @@ func (p *PersonalPropertiesApp) Render() (gin.H, error) { for _, prop := range v.(primitive.D).Map()["props"].(primitive.A) { elem := PropElement{ Key: prop.(primitive.D).Map()["key"].(string), - // KeyComments: prop.(primitive.D).Map()["keycomments"].([]string), - } if prop.(primitive.D).Map()["keycomments"] != nil { for _, keyComments := range prop.(primitive.D).Map()["keycomments"].(primitive.A) { @@ -166,19 +186,17 @@ func (p *PersonalPropertiesApp) Render() (gin.H, error) { allProps = append(allProps, island) } - // allProps = append(allProps) return gin.H{ - // "Name": "Greg Brzezinski", - // "BasicBio": "Born 27.09.1998 at Saint-Petersburg", - // "BasicInfo": basicInfo, - // "career": careerProps, - "allprops": allProps, + "headerProps": hIsland, + "allprops": allProps, }, nil } -type Book struct { - Title string - Author string +type HeaderIsland struct { + Name string + Icon *wde.Base64Img + Info1 string + Info2 string } type PropElement struct { @@ -195,7 +213,3 @@ type PropIsland struct { type PropertiesFile struct { Props []PropIsland `bson:"props"` } - -// func (p *PersonalPropertiesApp) GetContent(ctx *gin.Context) interface{} { - -// }