props markup fixes + shared lib to read images

This commit is contained in:
cyber-dream 2023-04-29 23:17:34 +03:00
parent f736033ce3
commit e9422f797b
6 changed files with 71 additions and 32 deletions

View File

@ -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)

View File

@ -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"])
}

View File

@ -13,10 +13,11 @@
<div class="ScrollContent">
<div class="PropertiesList">
<div class="Personal-properties-bio">
<img src="res/img/default-avatar-photo-placeholder-profile-picture-vector.jpg" alt="My Photo" style="width: 48px;height: 48px;">
<img src="data:{{ .headerProps.Icon.Header }},{{ .headerProps.Icon.Base64 }}" alt="My Photo" style="width: 48px;height: 48px;">
<div class="Personal-properties-textbio">
<div>{{ .Name }}</div>
<div>{{ .BasicBio }}</div>
<div>{{ .headerProps.Name }}</div>
<div>{{ .headerProps.Info1 }}</div>
<div>{{ .headerProps.Info2 }}</div>
</div>
</div>
{{ range $propIsland := .allprops }}

29
wde/imglib.go Normal file
View File

@ -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
}

View File

@ -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
}

View File

@ -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{} {
// }