props markup fixes + shared lib to read images
This commit is contained in:
parent
f736033ce3
commit
e9422f797b
2
main.go
2
main.go
@ -64,7 +64,7 @@ func main() {
|
|||||||
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
|
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
|
||||||
wde := wde.NewWDE(webfs)
|
wde := wde.NewWDE(webfs)
|
||||||
persPropsApp := personalprops.NewPersPropsApp(webfs)
|
persPropsApp := personalprops.NewPersPropsApp(webfs)
|
||||||
persPropsApp.WriteToDb()
|
|
||||||
// finderApp := finder.FinderApplication{}
|
// finderApp := finder.FinderApplication{}
|
||||||
finderApp := finder.NewFinderApplication(webfs)
|
finderApp := finder.NewFinderApplication(webfs)
|
||||||
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
||||||
|
@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
if (!WebDesktopEnvironment.isMobile){
|
if (!WebDesktopEnvironment.isMobile){
|
||||||
WebDesktopEnvironment.Open("finder", ["/home/user"])
|
WebDesktopEnvironment.Open("finder", ["/home/user"])
|
||||||
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
||||||
// WebDesktopEnvironment.Open("personal-properties", ["kek"])
|
WebDesktopEnvironment.Open("personal-properties", ["kek"])
|
||||||
} else {
|
} else {
|
||||||
WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
<div class="ScrollContent">
|
<div class="ScrollContent">
|
||||||
<div class="PropertiesList">
|
<div class="PropertiesList">
|
||||||
<div class="Personal-properties-bio">
|
<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 class="Personal-properties-textbio">
|
||||||
<div>{{ .Name }}</div>
|
<div>{{ .headerProps.Name }}</div>
|
||||||
<div>{{ .BasicBio }}</div>
|
<div>{{ .headerProps.Info1 }}</div>
|
||||||
|
<div>{{ .headerProps.Info2 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ range $propIsland := .allprops }}
|
{{ range $propIsland := .allprops }}
|
||||||
|
29
wde/imglib.go
Normal file
29
wde/imglib.go
Normal 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
|
||||||
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package imgviewer
|
package imgviewer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"personalwebsite/wde"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
"personalwebsite/websiteapp"
|
"personalwebsite/websiteapp"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ImgViewerApp struct {
|
type ImgViewerApp struct {
|
||||||
@ -37,16 +36,12 @@ func (p *ImgViewerApp) Render(path string, isMobile bool) (gin.H, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
header, ok := img.Data.(primitive.D).Map()["header"]
|
data, err := wde.ReadImage(img)
|
||||||
if !ok {
|
if err != nil {
|
||||||
return nil, errors.New("error in file decoding")
|
return nil, err
|
||||||
}
|
|
||||||
base64, ok := img.Data.(primitive.D).Map()["base64"]
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.New("error in file decoding")
|
|
||||||
}
|
}
|
||||||
return gin.H{
|
return gin.H{
|
||||||
"header": header,
|
"header": data.Header,
|
||||||
"base64": base64,
|
"base64": data.Base64,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package personalprops
|
package personalprops
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"personalwebsite/wde"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
"personalwebsite/websiteapp"
|
"personalwebsite/websiteapp"
|
||||||
|
|
||||||
@ -141,7 +143,27 @@ func (p *PersonalPropertiesApp) Render() (gin.H, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
allProps := make([]PropIsland, 0)
|
||||||
|
|
||||||
for _, v := range props.Data.(primitive.D).Map()["props"].(primitive.A) {
|
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) {
|
for _, prop := range v.(primitive.D).Map()["props"].(primitive.A) {
|
||||||
elem := PropElement{
|
elem := PropElement{
|
||||||
Key: prop.(primitive.D).Map()["key"].(string),
|
Key: prop.(primitive.D).Map()["key"].(string),
|
||||||
// KeyComments: prop.(primitive.D).Map()["keycomments"].([]string),
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if prop.(primitive.D).Map()["keycomments"] != nil {
|
if prop.(primitive.D).Map()["keycomments"] != nil {
|
||||||
for _, keyComments := range prop.(primitive.D).Map()["keycomments"].(primitive.A) {
|
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, island)
|
||||||
}
|
}
|
||||||
|
|
||||||
// allProps = append(allProps)
|
|
||||||
return gin.H{
|
return gin.H{
|
||||||
// "Name": "Greg Brzezinski",
|
"headerProps": hIsland,
|
||||||
// "BasicBio": "Born 27.09.1998 at Saint-Petersburg",
|
"allprops": allProps,
|
||||||
// "BasicInfo": basicInfo,
|
|
||||||
// "career": careerProps,
|
|
||||||
"allprops": allProps,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Book struct {
|
type HeaderIsland struct {
|
||||||
Title string
|
Name string
|
||||||
Author string
|
Icon *wde.Base64Img
|
||||||
|
Info1 string
|
||||||
|
Info2 string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PropElement struct {
|
type PropElement struct {
|
||||||
@ -195,7 +213,3 @@ type PropIsland struct {
|
|||||||
type PropertiesFile struct {
|
type PropertiesFile struct {
|
||||||
Props []PropIsland `bson:"props"`
|
Props []PropIsland `bson:"props"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (p *PersonalPropertiesApp) GetContent(ctx *gin.Context) interface{} {
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user