Compare commits

...

12 Commits

26 changed files with 873 additions and 100 deletions

3
.env Normal file
View File

@ -0,0 +1,3 @@
MONGO_CONNECT=mongodb://localhost:27017
DATABASE=personal-website
COLLECTION_WEBFS=webfs

1
.gitignore vendored
View File

@ -22,3 +22,4 @@
go.work
/__debug_bin
/.env

15
go.mod
View File

@ -4,6 +4,18 @@ go 1.18
require github.com/gin-gonic/gin v1.9.0
require (
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
)
require (
github.com/bytedance/sonic v1.8.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
@ -13,15 +25,18 @@ require (
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/google/uuid v1.3.0
github.com/joho/godotenv v1.5.1
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
go.mongodb.org/mongo-driver v1.11.4
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.7.0 // indirect

39
go.sum
View File

@ -19,24 +19,40 @@ github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVL
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@ -47,26 +63,49 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.9 h1:rmenucSohSTiyL09Y+l2OCk+FrMxGMzho2+tjr5ticU=
github.com/ugorji/go/codec v1.2.9/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.mongodb.org/mongo-driver v1.11.4 h1:4ayjakA013OdpGyL2K3ZqylTac/rMjrJOMZ1EHizXas=
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

187
main.go
View File

@ -1,36 +1,59 @@
package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"personalwebsite/routewde"
"personalwebsite/wde"
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp"
"personalwebsite/websiteapp/blogviewer"
"personalwebsite/websiteapp/finder"
imgviewer "personalwebsite/websiteapp/img-viewer"
"personalwebsite/websiteapp/personalprops"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// func main() {
// router := gin.Default()
// router.LoadHTMLGlob("templates/**/*")
// router.GET("/posts/index", func(c *gin.Context) {
// c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
// "title": "Posts",
// })
// })
// router.GET("/users/index", func(c *gin.Context) {
// c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
// "title": "Users",
// })
// })
// router.Run(":8080")
// }
func main() {
router := gin.New()
if err := godotenv.Load(); err != nil {
println("No .env file found")
}
mongoConnect, err := FindEnv("MONGO_CONNECT")
if err != nil {
panic(err.Error())
}
dBName, err := FindEnv("DATABASE")
if err != nil {
panic(err.Error())
}
webFsCollection, err := FindEnv("COLLECTION_WEBFS")
if err != nil {
panic(err.Error())
}
clientOptions := options.Client().ApplyURI(mongoConnect)
client, err := mongo.Connect(context.TODO(), clientOptions)
if err != nil {
log.Fatal(err)
}
err = client.Ping(context.TODO(), nil)
if err != nil {
log.Fatal(err)
}
router := gin.New()
router.LoadHTMLGlob("templates/**/*")
router.Static("/res", "resources")
@ -38,21 +61,26 @@ func main() {
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
})
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
wde := wde.NewWDE(webfs)
persPropsApp := personalprops.NewPersPropsApp()
finderApp := finder.FinerApplication{}
// finderApp := finder.FinderApplication{}
finderApp := finder.NewFinderApplication(webfs)
imgViewerApp := imgviewer.NewImgViewerApp()
blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
appsStorage := websiteapp.ApplicationsStorage{
Apps: map[string]websiteapp.WebDEApplication{},
}
appsStorage.Apps["personal-properties"] = &persPropsApp
appsStorage.Apps["finder"] = &finderApp
appsStorage.Apps["finder"] = finderApp
appsStorage.Apps["img-viewer"] = &imgViewerApp
appsStorage.Apps["blog-viewer"] = blogViewerApp
system := router.Group("system")
{
wde := system.Group("wde")
wdeGroup := system.Group("wde")
{
routewde.Route(wde)
routewde.Route(wdeGroup, wde)
}
apps := system.Group("applications")
{
@ -81,6 +109,76 @@ func main() {
websiteapp.Route(apps.Group("/storage"), &appsStorage)
}
fs := router.Group("fs")
{
fs.GET("writeFile", func(ctx *gin.Context) {
parentPath := ctx.Query("parentPath")
if parentPath == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return
}
file := webfilesystem.WebFSFile{
MongoId: primitive.NewObjectID(),
Name: "pp",
Type: "test",
Data: nil,
}
err := webfs.CreateFile(&file, parentPath)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
return
}
ctx.JSON(http.StatusOK, "OK")
})
fs.GET("createDir", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return
}
err := webfs.CreateDirectory(path)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
return
}
ctx.JSON(http.StatusOK, "OK")
})
fs.GET("list", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return
}
files, err := webfs.List(path)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
return
}
ctx.JSON(http.StatusOK, &files)
})
fs.GET("read", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return
}
file, err := webfs.Read(path)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
return
}
ctx.JSON(http.StatusOK, &file)
})
}
app := router.Group("application")
{
persPropApp := app.Group("personal-properties")
@ -124,6 +222,41 @@ func main() {
})
}
blogViewerRoute := app.Group("blog-viewer")
{
blogViewerRoute.GET("writeMockBlog", func(ctx *gin.Context) {
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "no path provided")
return
}
blogViewerApp.WriteMock(path)
ctx.JSON(http.StatusOK, "OK")
})
blogViewerRoute.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "no path provided")
return
}
isMobile := isMobileParam == "true"
ginH, err := blogViewerApp.Render(path, isMobile)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO")
return
}
if isMobile {
ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", ginH)
} else {
ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", ginH)
}
})
}
}
router.GET("/test", func(ctx *gin.Context) {
ctx.HTML(200, "kek/kek.tmpl", gin.H{})
@ -137,3 +270,15 @@ func main() {
func index(c *gin.Context) {
c.HTML(http.StatusOK, "base.html", nil)
}
func FindEnv(parameter string) (string, error) {
path, exists := os.LookupEnv(parameter)
if exists {
println("[ENV] Requsted " + parameter + " = " + path) //FIXME Only in Debug log
return path, nil
} else {
panic("[ENV] Requsted " + parameter + " not found")
return "", errors.New("env parameter not found")
}
}

View File

@ -33,6 +33,7 @@ body{
width: 100%;
height: 100%;
margin: 0px;
/* font: normal 14px Summer Pixel 22, "res/SummerPixel22Regular.ttf"; */
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */

View File

@ -3,6 +3,7 @@
height: 100%;
background: #CCCCCC;
/* background: #9999CC; */
/* Auto layout */
display: flex;

View File

@ -0,0 +1,39 @@
.blog-viewer{
background-color: #DDDDDD;
width: 100%;
height: 100%;
/* Auto layout */
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
/* gap: 50px; */
/* row-gap: 20px; */
padding: 0px 20px 0px 20px;
}
.blog-viewer .header-h1{
font-size:x-large;
padding: 10px;
}
.blog-viewer .header-h2{
font-size:large;
padding: 6px;
}
.blog-viewer .header-h3{
font-size:larger;
padding: 2px;
}
.blog-viewer .plain-text{
/* Auto layout */
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: flex-start;
gap: 5px;
/* row-gap: 20px; */
}

View File

@ -0,0 +1,51 @@
class BlogViewer{
appId = "blog-viewer"
constructor(){
}
/**
* @param {string[]} args
*/
NewWindow(args){
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile,
path: args[0],
}))
.then((response) => response.text())
.then((html) => {
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
newWindow.innerHTML = html
// let fileView = new FileView("/kek", newWindow.querySelector(".FileTileView"), Finder.Click)
if (!WebDesktopEnvironment.isMobile){
// let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
WebDesktopEnvironment.CloseWindow(newWindow)
})
}
})
.catch((error) => {
WebDesktopEnvironment.Alert(error);
})
}
/**
* @param {MouseEvent} event
* @param {string} path
*/
static Click(event, path){
let fileType = event.target.getAttribute("fileType")
switch (fileType) {
case "app":
//TODO get real id
WebDesktopEnvironment.Open("personal-properties", [])
break;
case "img":
WebDesktopEnvironment.Open("img-viewer", ["pizda"])
break;
default:
console.log("Unsupported file type")
break;
}
}
}

View File

@ -1,5 +1,10 @@
class Finder{
appId = "finder"
fileView = undefined
path = "/"
homePath = "/home/user"
// previousPath = "/"
pathHistory = [] //FIXME Fixed length
constructor(){
// this.appElem = appElem
}
@ -7,9 +12,11 @@ class Finder{
/**
* @param {string} path
*/
NewWindow(path){
NewWindow(args){
this.path = args[0]
fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile,
// path: this.path,
// bar: true,
})) //TODO Move to wde func. Or Not?
.then((response) => response.text())
@ -17,11 +24,26 @@ class Finder{
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
newWindow.innerHTML = html
let fileView = new FileView("/kek", newWindow.querySelector(".FileTileView"), Finder.Click)
this.fileView = new FileView(newWindow.querySelector(".FileTileView"), (event) =>{
this.Click(event, this.path)
})
this.OpenDir(this.path)
newWindow.querySelector("#BackButton").addEventListener('click', () =>{
this.OpenPreviousDir()
})
newWindow.querySelector("#HomeButton").addEventListener('click', () =>{
this.OpenDir(this.homePath)
})
if (!WebDesktopEnvironment.isMobile){
let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector
// let scrollBar = new WdeScrollBar(newWindow.children[1].children[1], newWindow.children[1].children[0])// TODO to querry selector
console.log(newWindow.querySelector("#closeWindowButton"))
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
WebDesktopEnvironment.CloseWindow(newWindow)
})
}
})
@ -30,23 +52,65 @@ class Finder{
})
}
OpenPreviousDir(){
if (this.pathHistory.length > 0){
// console.log(this.pathHistory)
let path = this.pathHistory[this.pathHistory.length - 1]
// console.log(typeof( this.pathHistory))
this.pathHistory.pop()
this.OpenDir(this.path)
}
}
/**
* @param {MouseEvent} event
* @param {string} path
*/
static Click(event, path){
OpenDir(path){
console.log()
this.pathHistory += this.path
this.path = path
this.fileView.OpenFolder(this.path)
}
/**
* @param {MouseEvent} event
*/
Click(event){
let fileType = event.target.getAttribute("fileType")
let fileName = event.target.getAttribute("name")
switch (fileType) {
case "app":
//TODO get real id
WebDesktopEnvironment.Open("personal-properties", [])
break;
case "img":
WebDesktopEnvironment.Open("img-viewer", ["pizda"])
break;
case "directory":
this.OpenDir(this.path +"/" + fileName)
break
case "blog-page":
WebDesktopEnvironment.Open("blog-viewer", [this.path + "/" + fileName])
break
// case "app":
// //TODO get real id
// WebDesktopEnvironment.Open("personal-properties", [])
// break;
// case "img":
// WebDesktopEnvironment.Open("img-viewer", ["pizda"])
// break;
default:
console.log("Unsupported file type")
break;
}
}
// /**
// * @param {path} string
// */
// renderFileView(path){
// fetch(`${window.location.origin}/fs/list?` + new URLSearchParams({
// path: path,
// }))
// .then((response) => response.text())
// .then((html) => {
// this.fileView.innerHTML = html
// })
// .catch((error) => {
// WebDesktopEnvironment.Alert(error);
// })
// }
}

View File

@ -1,23 +1,27 @@
.ScrollContent {
/* TODO Move this to body? */
/*.ScrollContent {
width: 100%;
height: 100%;
overflow: scroll;
overflow-x: hidden;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* Internet Explorer 10+ */
/* Firefox */
/* scrollbar-width: none; */
/* Internet Explorer 10+ */
/* -ms-overflow-style: none; */
/* Auto layout */
display: flex;
/*display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-start;
padding: 0px;
}
}*/
.ScrollContent::-webkit-scrollbar { /* WebKit */
/* WebKit */
/* .ScrollContent::-webkit-scrollbar {
width: 0;
height: 0;
}
} */
.PropertiesList{
/* width: 100%;

View File

@ -1,15 +1,14 @@
class FileView{
path = ""
parentElem = undefined
/**
* @param {string} path
* @param {HTMLElement} fileViewElem
* @param {Function} clickCallback
*/
constructor(path, fileViewElem, clickCallback){
constructor(fileViewElem, clickCallback){
//TODO check all params
this.path = path
this.parentElem = fileViewElem
this.openFolder(path, fileViewElem)
// this.OpenFolder(path)
// let scrollDiv = fileViewElem.children[1]
// console.log(scrollDiv)
@ -22,14 +21,17 @@ class FileView{
/** Get html of folder by path
* @param {string} path
* @param {HTMLElement} parentElem
*/
openFolder(path, parentElem){
// console.log(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`)
OpenFolder(path){
fetch(`${window.location.origin}/system/wde/widgets/file-tile-view?path=${path}`) //TODO Move to wde func. Or Not?
.then((response) => response.text())
.then((html) => {
parentElem.innerHTML = html
//TODO
// console.log(responseStatus)
// if (responseStatus != 200) {
// WebDesktopEnvironment.Alert("Error")
// }
this.parentElem.innerHTML = html
}).catch((error) => {
WebDesktopEnvironment.Alert(error);
})

View File

@ -2,8 +2,11 @@ document.addEventListener('DOMContentLoaded', function() {
// console.log(window.screen.width)
wde = new WebDesktopEnvironment
if (!WebDesktopEnvironment.isMobile){
WebDesktopEnvironment.Open("finder", ["kek"])
WebDesktopEnvironment.Open("personal-properties", ["kek"])
WebDesktopEnvironment.Open("finder", ["/home/user"])
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
// WebDesktopEnvironment.Open("personal-properties", ["kek"])
} else {
WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
}
@ -38,6 +41,10 @@ class WebDesktopEnvironment{
//TODO Do not allow launch second instance
WebDesktopEnvironment.Open("personal-properties", [])
})
mobileDesktop.querySelector('#mobile-desktop-blog').addEventListener('click', (event) => {
//TODO Do not allow launch second instance
WebDesktopEnvironment.Open("blog-viewer", ['main-page'])
})
mobileDesktop.querySelector('#mobile-dekstop-close').addEventListener('click', (event) => {
// console.log('close')
WebDesktopEnvironment.CloseFocusedWindow()
@ -89,6 +96,11 @@ class WebDesktopEnvironment{
this.Applications[appId] = newImgViewer
func()
return newImgViewer
case "blog-viewer":
let newBlogViewer = new BlogViewer()
this.Applications[appId] = newBlogViewer
func()
return newBlogViewer
default:
break;
}
@ -193,13 +205,42 @@ var getJSON = function(url, callback) {
class WindowsCompositor{
windowLayer = undefined
movingElement = null
xPosInit = 0
yPosInit = 0
// xPosInit = 0
// yPosInit = 0
//TODO refactor this to dynamic add/remove listeners
constructor(){
this.windowLayer = document.body.querySelector('#windows-layer')
if (!WebDesktopEnvironment.isMobile) {
let startDrag = function(event) {
let targetClasses = event.target.className.split(' ')
if (targetClasses[targetClasses.length - 1] != 'DragArea'){
return
}
// if (event.target.event.target.className != "DragArea"){}
let xPosInit = event.offsetX
let yPosInit = event.offsetY
let window = event.target.closest('.StandartApplicationWindow')
let dragWindow = function(event){
// console.log(window)
// console.log(event.clientX)
// console.log(event.clientX - xPosInit, event.clientY - yPosInit)
WindowsCompositor.dragElement(window,event.clientX - xPosInit, event.clientY - yPosInit)
}
let stopDrag = function(){
removeEventListener('mousemove', dragWindow)
removeEventListener('mouseup', stopDrag)
}
addEventListener('mousemove', dragWindow)
addEventListener('mouseup', stopDrag)
// console.log(event)
}
this.windowLayer.addEventListener('mousedown', startDrag)
}
if (false) { //FIXME
addEventListener("mousedown", (event) => {
this.xPosInit = event.offsetX
this.yPosInit = event.offsetY
@ -249,8 +290,14 @@ class WindowsCompositor{
* @param {number} posX
* @param {number} posY
*/
dragElement(element, posX, posY) { //TODO
static dragElement(element, posX, posY) { //TODO
element.style.left = `${posX}px`
element.style.top = `${posY}px`
}
startDrag(){
this.windowLayer.addEventListener('mousemove', () => {
console.log("move")
})
}
}

View File

@ -326,5 +326,26 @@
}
.FileTileTitle{
white-space: nowrap;
}
.ScrollContent {
width: 100%;
height: 100%;
overflow: scroll;
overflow-x: hidden;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* Internet Explorer 10+ */
/* Auto layout */
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-start;
padding: 0px;
}
.ScrollContent::-webkit-scrollbar { /* WebKit */
width: 0;
height: 0;
}

View File

@ -2,12 +2,12 @@ package routewde
import (
"net/http"
"personalwebsite/webfilesystem"
"personalwebsite/wde"
"github.com/gin-gonic/gin"
)
func Route(route *gin.RouterGroup) {
func Route(route *gin.RouterGroup, wde *wde.WDE) {
route.GET("/getbasicwindow", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "basic-window.html", nil)
})
@ -19,12 +19,17 @@ func Route(route *gin.RouterGroup) {
widgets := route.Group("widgets")
{
widgets.GET("/file-tile-view", func(ctx *gin.Context) {
fs := webfilesystem.WebFileSystem{}
list := fs.List()
ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", gin.H{
"Name": "Greg Brzezinski",
"Files": list,
})
path := ctx.Query("path")
if path == "" {
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
return
}
ginH, err := wde.Render(path)
if err != nil {
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO
return
}
ctx.HTML(http.StatusOK, "wde-widgets/file-tile-view.tmpl", ginH)
})
}
}

View File

@ -8,6 +8,7 @@
<link rel="stylesheet" href="/res/sys/wde/simple-scrollbar.css">
<link rel="stylesheet" href="/res/sys/personal-properties/personal-properies.css">
<link rel="stylesheet" href="/res/sys/img-viewer/img-viewer.css">
<link rel="stylesheet" href="/res/sys/blog-viewer/blog-viewer.css">
<script src="/res/sys/wde/wde-scrollbar.js"></script>
<script src="/res/sys/wde/file-view.js"></script>
<script src="res/wde.js"></script>

View File

@ -11,9 +11,9 @@
<div class="FileTileIcon NoClick" style="background-image: url('./res/sys/wde/icons/about-me.png');"></div>
<div class="FileTileTitle NoClick">About Me</div>
</div>
<div id="Home" class="FileTile">
<div id="mobile-desktop-blog" class="FileTile">
<div class="FileTileIcon NoClick" style="background-image: url('./res/sys/wde/icons/desktop.png');"></div>
<div class="FileTileTitle NoClick">Home</div>
<div class="FileTileTitle NoClick">Blog</div>
</div>
<div id="mobile-dekstop-close" class="FileTile">
<div class="FileTileIcon NoClick" style="background-image: url('./res/sys/wde/icons/trash.png');"></div>

View File

@ -0,0 +1,26 @@
{{ define "blog-viewer/app.tmpl" }}
<div id="TestWindowHeader" class="WindowFrameTopBar">
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
<div id="Drag" class="WindowDragArea"></div>
<div class="WindowFrameTitle">
{{.header}}
</div>
<div id="Drag" class="WindowDragArea"></div>
</div>
<div class="ContentBorder">
<div class="blog-viewer ScrollContent">
{{ range $block := .blocks }}
<div class="{{$block.Type}}" >
{{ range $data := $block.Data }}
<div style="font-size: inherit;">
{{$data}}
</div>
{{ end }}
</div>
{{ end }}
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
{{ end }}

View File

@ -0,0 +1,18 @@
{{ define "blog-viewer/mobile-app.tmpl" }}
<div class="blog-viewer">
<div class="header">
{{.header}}
</div>
{{ range $block := .blocks }}
<div class="{{$block.Type}}">
{{ range $data := $block.Data }}
<div>
{{$data}}
</div>
{{ end }}
</div>
{{ end }}
</div>
{{ end }}

View File

@ -1,5 +1,5 @@
{{ define "finder/app.tmpl" }}
<div id="TestWindowHeader" class="WindowFrameTopBar">
<div id="TestWindowHeader" class="WindowFrameTopBar DragArea">
<button id="closeWindowButton" class="WindowFrameTopBarButton" title="Close Window"></button>
<div id="Drag" class="WindowDragArea"></div>
<div class="WindowFrameTitle">
@ -7,6 +7,10 @@
</div>
<div id="Drag" class="WindowDragArea"></div>
</div>
<div class="ToolBar">
<button id="BackButton">Back</button>
<button id="HomeButton">Home</button>
</div>
<div class="ContentBorder">
<div class="FileTileView">

View File

@ -1,8 +1,8 @@
{{ define "wde-widgets/file-tile-view.tmpl" }}
{{ range $fileTile := .Files }}
<div id="{{ $fileTile.Id }}" fileType="{{ $fileTile.Type }}" class="FileTile" fileName="{{$fileTile.FileName}}">
<div fileType="{{ $fileTile.Type }}" class="FileTile" name="{{$fileTile.Name}}">
<div class="FileTileIcon NoClick"></div>
<div class="FileTileTitle NoClick">{{ $fileTile.FileName }}</div>
<div class="FileTileTitle NoClick">{{ $fileTile.Name }}</div>
</div>
{{ end }}
{{ end }}

32
wde/wde.go Normal file
View File

@ -0,0 +1,32 @@
package wde
import (
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type WDE struct {
fs *webfilesystem.WebFileSystem
FilesWidget FilesWidget
}
func NewWDE(webFs *webfilesystem.WebFileSystem) *WDE {
return &WDE{
fs: webFs,
}
}
type FilesWidget struct {
}
func (w *WDE) Render(path string) (gin.H, error) {
list, err := w.fs.List(path)
if err != nil {
return nil, err
}
return gin.H{
"Name": "Greg Brzezinski",
"Files": list,
}, nil
}

View File

@ -1,37 +1,181 @@
package webfilesystem
import "github.com/google/uuid"
import (
"context"
"errors"
"strings"
"github.com/mitchellh/mapstructure"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
type WebFileSystem struct {
folders []*Folder
webfsCollection *mongo.Collection
// folders []*Folder
}
func (fs *WebFileSystem) List() []*WebFSFile {
// aboutMe := &Exec{
// WebFSFile: WebFSFile{
// Id: uuid.NewString(),
// FileName: "Aboutme.app",
// },
// }
// testImg :=
// mockFolder := Folder{
// files: []File{aboutMe},
// }
// kek := []*WebFSFile{}
return []*WebFSFile{{uuid.NewString(), "Aboutme", "app", "personal-properties"}, {uuid.NewString(), "lel.lol", "lol", nil}, {uuid.NewString(), "lel.img", "img", nil}}
// return mockFolder.files
func NewWebFileSystem(mongoClient *mongo.Client, dBName string, fsCollectionName string) *WebFileSystem {
return &WebFileSystem{
webfsCollection: mongoClient.Database(dBName).Collection(fsCollectionName), // TODO Check collection is exist
}
}
type Folder struct {
files []File
func (fs *WebFileSystem) Read(path string) (*WebFSFile, error) {
splittedPath := fs.SplitPath(path)
filter := primitive.D{
{
Key: "name",
Value: splittedPath[len(splittedPath)-1],
},
}
file, err := fs.findFileInMongo(filter)
return file, err
}
func (fs *WebFileSystem) ReadByObjectID(objectId primitive.ObjectID) (*WebFSFile, error) {
filter := primitive.D{
{
Key: "_id",
Value: objectId,
},
}
file, err := fs.findFileInMongo(filter)
return file, err
}
func (fs *WebFileSystem) findFileInMongo(filter primitive.D) (*WebFSFile, error) {
res := fs.webfsCollection.FindOne(context.Background(), &filter)
file := WebFSFile{}
err := res.Decode(&file)
if err != nil {
return nil, err
}
return &file, nil
}
func (fs *WebFileSystem) List(path string) ([]*WebFSFile, error) {
// dirFile, err := fs.Read(fs.GetParentPath(path))
dirFile, err := fs.Read(path)
if err != nil {
return nil, err
}
if dirFile.Type != "directory" {
return nil, errors.New("file is not a directory")
}
fileData := FolderData{}
err = mapstructure.Decode(dirFile.Data.(primitive.D).Map(), &fileData)
if err != nil {
return nil, err
}
files := []*WebFSFile{}
for _, child := range fileData.Children {
file, err := fs.ReadByObjectID(child)
if err != nil {
println(err.Error())
continue
}
files = append(files, file)
}
return files, nil
}
func (fs *WebFileSystem) CreateDirectory(path string) error {
splittedpath := fs.SplitPath(path)
parentPath := fs.GetParentPath(path)
parentDir, err := fs.Read(parentPath)
if err != nil {
return err
}
directory := WebFSFile{
MongoId: primitive.NewObjectID(),
Name: splittedpath[len(splittedpath)-1],
Type: "directory",
Data: FolderData{
Parent: parentDir.MongoId,
Children: []primitive.ObjectID{},
},
}
fs.CreateFile(&directory, parentPath)
// res, err := fs.webfsCollection.InsertOne(context.Background(), &directory)
// if err != nil {
// return err
// }
// fileId := fs.castInsertId(res)
// fs.insertFileToDirectory(fileId, parentDir.MongoId)
return nil
}
func (fs *WebFileSystem) CreateFile(file *WebFSFile, parentPath string) error {
parentDir, err := fs.Read(parentPath)
if err != nil {
return err
}
res, err := fs.webfsCollection.InsertOne(context.Background(), &file)
if err != nil {
return err
}
_ = parentDir
fileId := fs.castInsertId(res)
fs.insertFileToDirectory(fileId, parentDir.MongoId)
return nil
}
func (fs *WebFileSystem) castInsertId(res *mongo.InsertOneResult) primitive.ObjectID {
return res.InsertedID.(primitive.ObjectID)
}
func (fs *WebFileSystem) insertFileToDirectory(fileId primitive.ObjectID, directoryId primitive.ObjectID) error {
dir, err := fs.ReadByObjectID(directoryId)
if err != nil {
return err
}
//TODO check if file exist
fileData := FolderData{}
err = mapstructure.Decode(dir.Data.(primitive.D).Map(), &fileData)
if err != nil {
return err
}
fileData.Children = append(fileData.Children, fileId)
fs.webfsCollection.UpdateByID(context.Background(), directoryId, bson.M{"$set": bson.M{"data": fileData}})
return nil
}
func (fs *WebFileSystem) SplitPath(path string) []string {
resPath := []string{}
splittedPath := strings.Split(path, "/")
splittedPath[0] = "/"
for _, split := range splittedPath {
if split != "" {
resPath = append(resPath, split)
}
}
return resPath
}
func (fs *WebFileSystem) GetParentPath(path string) string {
splittedPath := fs.SplitPath(path)
parentPath := strings.Join(splittedPath[:len(splittedPath)-1], "/")
return parentPath
}
type WebFSFile struct {
Id string
FileName string
Type string
data interface{}
MongoId primitive.ObjectID `bson:"_id" json:"-"`
Name string `bson:"name" json:"name"`
Type string `bson:"type" json:"type"`
Data interface{} `bson:"data" json:"-"`
}
type FolderData struct {
Parent primitive.ObjectID `bson:"parent"`
Children []primitive.ObjectID `bson:"children"`
}
type File interface {
GetUuid() string
GetFileName() string
@ -44,10 +188,12 @@ type Exec struct {
WebFSFile
}
func (e *Exec) GetUuid() string {
return e.Id
func (e *Exec) GetFileName() string {
return e.Name
}
func (e *Exec) GetFileName() string {
return e.FileName
}
// type WebFSFile2 interface {
// GetName() string
// GetType() string
// GetData() interface{}
// }

View File

@ -0,0 +1,6 @@
package blogviewer
type BlogFileData struct {
Header string `bson:"header"`
Blocks []Block `bson:"blocks"`
}

View File

@ -0,0 +1,90 @@
package blogviewer
import (
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type BlogViewerApplication struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest
}
func NewBlogViewerApp(webFs *webfilesystem.WebFileSystem) *BlogViewerApplication {
return &BlogViewerApplication{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "blog-viewer",
WindowName: "",
},
}
}
func (b *BlogViewerApplication) GetManifest() websiteapp.ApplicationManifest {
return b.manifest
}
func (b *BlogViewerApplication) GetId() string {
return b.manifest.AppId
}
func (b *BlogViewerApplication) WriteMock(path string) {
blogFile := webfilesystem.WebFSFile{
MongoId: primitive.NewObjectID(),
Name: "test-1.blog",
Type: "blog-page",
Data: BlogFileData{
Header: "OMG THIS IS BLOG",
Blocks: []Block{
{
Type: "plain-text",
Data: []string{
"Apoqiwepoqiwepo",
".,mas;dakls;d",
"q[poqwieqpipoi]",
},
},
},
},
}
err := b.fs.CreateFile(&blogFile, path)
if err != nil {
println(err.Error())
}
}
func (b *BlogViewerApplication) Render(path string, isMobile bool) (gin.H, error) {
file, err := b.fs.Read(path)
if err != nil {
println(err.Error())
return nil, err
}
blogDataRaw := file.Data.(primitive.D).Map()
header := blogDataRaw["header"]
blocks := []Block{}
for _, rawBlock := range blogDataRaw["blocks"].(primitive.A) {
lel := rawBlock.(primitive.D).Map()
block := Block{
Type: lel["type"].(string),
Data: []string{},
}
for _, v := range lel["data"].(primitive.A) {
block.Data = append(block.Data, v.(string))
}
blocks = append(blocks, block)
}
return gin.H{
"header": header,
"blocks": blocks,
}, nil
}
type Block struct {
Type string `bson:"type"`
Data []string `bson:"data"`
}

View File

@ -1,22 +1,34 @@
package finder
import (
"personalwebsite/webfilesystem"
"personalwebsite/websiteapp"
"github.com/gin-gonic/gin"
)
type FinerApplication struct {
type FinderApplication struct {
fs *webfilesystem.WebFileSystem
manifest websiteapp.ApplicationManifest
}
func (f *FinerApplication) GetManifest() websiteapp.ApplicationManifest {
func NewFinderApplication(webFs *webfilesystem.WebFileSystem) *FinderApplication {
return &FinderApplication{
fs: webFs,
manifest: websiteapp.ApplicationManifest{
AppId: "finder",
WindowName: "TODO DELETE", //TODO DELETE
},
}
}
func (f *FinderApplication) GetManifest() websiteapp.ApplicationManifest {
return f.manifest
}
func (f *FinerApplication) GetId() string {
func (f *FinderApplication) GetId() string {
return f.manifest.AppId
}
func (f *FinerApplication) Render(isMobile bool) gin.H {
func (f *FinderApplication) Render(isMobile bool) gin.H {
return gin.H{}
}