diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a32b632 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/personal-website.iml b/.idea/personal-website.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/personal-website.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.go b/main.go index f1030b6..7e00034 100644 --- a/main.go +++ b/main.go @@ -3,22 +3,11 @@ package main import ( "context" "errors" - "log" "os" - - "personalwebsite/apps" - blogwriter "personalwebsite/apps/BlogWriter" - "personalwebsite/apps/aboutme" - "personalwebsite/apps/blogviewer" - "personalwebsite/apps/finder" - imgviewer "personalwebsite/apps/img-viewer" - "personalwebsite/routes" - "personalwebsite/wde" - "personalwebsite/webfilesystem" + "personalwebsite/webfs" "github.com/joho/godotenv" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "personalwebsite/routes" ) func main() { @@ -30,7 +19,7 @@ func main() { if err != nil { panic(err.Error()) } - + // dBName, err := FindEnv("DATABASE") if err != nil { panic(err.Error()) @@ -40,46 +29,53 @@ func main() { if err != nil { panic(err.Error()) } + // + //publicPort, err := FindEnv("PUBLIC_PORT") + //if err != nil { + // panic(err.Error()) + //} + // + //privatePort, err := FindEnv("PRIVATE_PORT") + //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) + //} + // + //webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection) + //appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs) + // + //webde := wde.NewWDE(webfs) + // + ////TODO Split to different apps init for private and public? + //persPropsApp := aboutme.NewAboutMeApp(webfs) + //finderApp := finder.NewFinderApplication(webfs) + //imgViewerApp := imgviewer.NewImgViewerApp(webfs) + //blogViewerApp := blogviewer.NewBlogViewerApp(webfs) + //blogWriterApp := blogwriter.NewBlogWriterApp(webfs) + //appsStorage.Apps["personal-properties"] = persPropsApp + //appsStorage.Apps["finder"] = finderApp + //appsStorage.Apps["img-viewer"] = imgViewerApp + //appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp + //appsStorage.Apps["BlogWriter"] = blogWriterApp - publicPort, err := FindEnv("PUBLIC_PORT") + //go routes.PublicRoutes(publicPort, webfs, webde, appsStorage) + ctx := context.Background() + //ctx. + err = webfs.Init(ctx, mongoConnect, dBName, webFsCollection) if err != nil { panic(err.Error()) } - privatePort, err := FindEnv("PRIVATE_PORT") - 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) - } - - webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection) - appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs) - - webde := wde.NewWDE(webfs) - - //TODO Split to different apps init for private and public? - persPropsApp := aboutme.NewAboutMeApp(webfs) - finderApp := finder.NewFinderApplication(webfs) - imgViewerApp := imgviewer.NewImgViewerApp(webfs) - blogViewerApp := blogviewer.NewBlogViewerApp(webfs) - blogWriterApp := blogwriter.NewBlogWriterApp(webfs) - appsStorage.Apps["personal-properties"] = persPropsApp - appsStorage.Apps["finder"] = finderApp - appsStorage.Apps["img-viewer"] = imgViewerApp - appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp - appsStorage.Apps["BlogWriter"] = blogWriterApp - - go routes.PublicRoutes(publicPort, webfs, webde, appsStorage) - routes.PrivateRoutes(privatePort, webfs, webde, appsStorage) + routes.ApiRoutes() } func FindEnv(parameter string) (string, error) { diff --git a/pure-html/base.html b/pure-html/base.html deleted file mode 100644 index 800f80a..0000000 --- a/pure-html/base.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - -
-
- - - diff --git a/pure-html/basic-window.html b/pure-html/basic-window.html deleted file mode 100644 index b3bae90..0000000 --- a/pure-html/basic-window.html +++ /dev/null @@ -1,17 +0,0 @@ - -
-
-
- -
-
- Test Title -
-
- -
-
-
-
-
- diff --git a/pure-html/index.html b/pure-html/index.html deleted file mode 100644 index 3c5701f..0000000 --- a/pure-html/index.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - -
-

↓Scrollable!↓

-

↓Scrollable!↓

-

↓Scrollable!↓

-

↓Scrollable!↓

-

↓Scrollable!↓

-
- - \ No newline at end of file diff --git a/routes/new.go b/routes/new.go new file mode 100644 index 0000000..0b0b40e --- /dev/null +++ b/routes/new.go @@ -0,0 +1,46 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + "log" + "net/http" + "personalwebsite/webfs" +) + +func ApiRoutes() { + router := gin.New() + + router.GET("/", func(ctx *gin.Context) { + ctx.String(http.StatusOK, "index.tmpl") + }) + + libGroup := router.Group("lib") + + webFSGroup := libGroup.Group("fs") + + webFSGroup.POST("write", func(context *gin.Context) { + //err := webfs.Crea() + //if err != nil { + // print() + //} + }) + + webFSGroup.POST("create/dir", func(context *gin.Context) { + _, err := webfs.CreateRoot(context) + if err != nil { + print(err.Error()) + } + }) + + webFSGroup.POST("create/root", func(context *gin.Context) { + _, err := webfs.CreateRoot(context) + if err != nil { + print(err.Error()) + } + }) + + err := router.Run(":" + "5000") + if err != nil { + log.Panicf("error: %s", err) + } +} diff --git a/templates/base/index.tmpl b/templates/base/index.tmpl deleted file mode 100644 index d0542f7..0000000 --- a/templates/base/index.tmpl +++ /dev/null @@ -1,40 +0,0 @@ - - - Greg Brzezinski - - - - - - - - - - - - - - - - - - - - - - - {{ range $app := .autostart }} - - - {{ range $arg := $app.Args }} - - {{ end }} - - - {{ end }} - -
-
-
- - diff --git a/templates/base/mobile-desktop.tmpl b/templates/base/mobile-desktop.tmpl deleted file mode 100644 index 7a288eb..0000000 --- a/templates/base/mobile-desktop.tmpl +++ /dev/null @@ -1,26 +0,0 @@ -{{ define "base/mobile-desktop.tmpl" }} - -
-
-
-
-
-
-
-
-
-
About Me
-
-
-
-
Blog
-
-
-
-
Close
-
-
- -{{ end }} - - \ No newline at end of file diff --git a/templates/blog-viewer/app.tmpl b/templates/blog-viewer/app.tmpl deleted file mode 100644 index 83a6077..0000000 --- a/templates/blog-viewer/app.tmpl +++ /dev/null @@ -1,38 +0,0 @@ -{{ define "blog-viewer/app.tmpl" }} -
- -
-
- Blog Viewer -
-
-
-
-
-
-
- {{ range $block := .blocks }} - {{ if eq $block.Type "image"}} -
- {{ range $data := $block.Data }} - - {{ end }} -
- {{ else }} -
- {{ range $data := $block.Data }} -
- {{$data}} -
- {{ end }} -
- {{ end }} - {{ end }} -
-
- {{template "wde-widgets/scrollbar.tmpl" .}} -
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/blog-viewer/mobile-app.tmpl b/templates/blog-viewer/mobile-app.tmpl deleted file mode 100644 index 4ef60f2..0000000 --- a/templates/blog-viewer/mobile-app.tmpl +++ /dev/null @@ -1,18 +0,0 @@ -{{ define "blog-viewer/mobile-app.tmpl" }} -
-
- {{.header}} -
- {{ range $block := .blocks }} -
- {{ range $data := $block.Data }} -
- {{$data}} -
- {{ end }} -
- {{ end }} -
-{{ end }} - - \ No newline at end of file diff --git a/templates/finder/admin-app.tmpl b/templates/finder/admin-app.tmpl deleted file mode 100644 index f724d2f..0000000 --- a/templates/finder/admin-app.tmpl +++ /dev/null @@ -1,32 +0,0 @@ -{{ define "finder/admin-app.tmpl" }} -
- - -
-
- Admin Finder -
-
- -
-
-
- -
- - - - -
You Favorite Movie
-
-
-
- -
- {{template "wde-widgets/scrollbar.tmpl" .}} -
-
-
-{{ end }} - - diff --git a/templates/finder/app.tmpl b/templates/finder/app.tmpl deleted file mode 100644 index e6d3cc0..0000000 --- a/templates/finder/app.tmpl +++ /dev/null @@ -1,27 +0,0 @@ -{{ define "finder/app.tmpl" }} -
- - -
-
- Finder -
-
- -
-
-
- -
- Folder info -
-
-
-
- {{template "wde-widgets/scrollbar.tmpl" .}} -
-
-
-{{ end }} - - diff --git a/templates/finder/desktop.tmpl b/templates/finder/desktop.tmpl deleted file mode 100644 index 0bccf73..0000000 --- a/templates/finder/desktop.tmpl +++ /dev/null @@ -1,6 +0,0 @@ -{{ define "finder/desktop.tmpl" }} -
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/finder/mobile-app.tmpl b/templates/finder/mobile-app.tmpl deleted file mode 100644 index f936d32..0000000 --- a/templates/finder/mobile-app.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -{{ define "finder/mobile-app.tmpl" }} -
-
-
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/finder/mobile-desktop.tmpl b/templates/finder/mobile-desktop.tmpl deleted file mode 100644 index f4701f4..0000000 --- a/templates/finder/mobile-desktop.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -{{ define "finder/mobile-desktop.tmpl" }} -
-
-
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/finder/props.tmpl b/templates/finder/props.tmpl deleted file mode 100644 index 6fe765b..0000000 --- a/templates/finder/props.tmpl +++ /dev/null @@ -1,62 +0,0 @@ -{{ define "finder/props.tmpl" }} -
- -
-
- File Properties -
-
-
-
-
-
- -
-
{{ .file.Name }}
- -
-
-
- file id : {{.file.MongoId}} -
-
- file type : {{.file.Type}} -
-
- file data id : {{.file.Data}} -
- {{ range $propIsland := .allprops }} -
-
- {{$propIsland.Header}}: -
-
- {{range $prop := $propIsland.Props}} -
-
- {{$prop.Key}}: - {{ range $value := $prop.KeyComments }} -
- {{ $value }} -
- {{ end }} -
-
- {{ range $value := $prop.Values }} -
- {{ $value }} -
- {{ end }} -
-
- {{ end }} -
-
- {{ end }} -
-
- -{{ end }} - - \ No newline at end of file diff --git a/templates/img-viewer/app.tmpl b/templates/img-viewer/app.tmpl deleted file mode 100644 index acbaf52..0000000 --- a/templates/img-viewer/app.tmpl +++ /dev/null @@ -1,20 +0,0 @@ -{{ define "img-viewer/app.tmpl" }} -
- -
-
- About me -
-
-
-
- - - - -
-{{ end }} - - \ No newline at end of file diff --git a/templates/img-viewer/mobile-app.tmpl b/templates/img-viewer/mobile-app.tmpl deleted file mode 100644 index e71d6ce..0000000 --- a/templates/img-viewer/mobile-app.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -{{ define "img-viewer/mobile-app.tmpl" }} -
-
-
-
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/personal-properties/app.tmpl b/templates/personal-properties/app.tmpl deleted file mode 100644 index d45e1b2..0000000 --- a/templates/personal-properties/app.tmpl +++ /dev/null @@ -1,57 +0,0 @@ -{{ define "personal-properties/app.tmpl" }} -
- -
-
About me
-
-
-
-
-
-
- -
- My Photo -
-
{{ .HeaderProps.Name }}
-
{{ .HeaderProps.Value1 }}
-
{{ .HeaderProps.Value2 }}
-
-
- {{ range $island := .Islands }} - -
-
{{$island.Header}}:
-
- {{range $property := $island.Properties}} -
-
- {{$property.Key}}: - {{ range $keyComment := $property.KeyComments }} -
{{ $keyComment }}
- {{ end }} -
-
- {{ range $value := $property.Values }} -
{{ $value }}
- {{ end }} -
-
- {{ end }} -
-
- {{ end }} -
-
- -
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/personal-properties/mobile-app.tmpl b/templates/personal-properties/mobile-app.tmpl deleted file mode 100644 index ae52edf..0000000 --- a/templates/personal-properties/mobile-app.tmpl +++ /dev/null @@ -1,45 +0,0 @@ -{{ define "personal-properties/mobile-app.tmpl" }} -
-
-
-
- My Photo -
-
{{ .Name }}
-
{{ .BasicBio }}
-
-
- {{ range $propIsland := .allprops }} -
-
- {{$propIsland.Header}}: -
-
- {{range $prop := $propIsland.Props}} -
-
- {{$prop.Key}}: - {{ range $value := $prop.KeyComments }} -
- {{ $value }} -
- {{ end }} -
-
- {{ range $value := $prop.Values }} -
- {{ $value }} -
- {{ end }} -
-
- {{ end }} -
-
- {{ end }} -
-
-
-{{ end }} - - \ No newline at end of file diff --git a/templates/posts/index.tmpl b/templates/posts/index.tmpl deleted file mode 100644 index 88f493d..0000000 --- a/templates/posts/index.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -{{ define "posts/index.tmpl" }} -

- {{ .title }} -

-

Using posts/index.tmpl

- -{{ end }} \ No newline at end of file diff --git a/templates/users/index.tmpl b/templates/users/index.tmpl deleted file mode 100644 index 1d76b6e..0000000 --- a/templates/users/index.tmpl +++ /dev/null @@ -1,7 +0,0 @@ -{{ define "users/index.tmpl" }} -

- {{ .title }} -

-

Using users/index.tmpl

- -{{ end }} \ No newline at end of file diff --git a/templates/wde-widgets/context-menu.tmpl b/templates/wde-widgets/context-menu.tmpl deleted file mode 100644 index 9a9f613..0000000 --- a/templates/wde-widgets/context-menu.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -{{ define "wde-widgets/context-menu.tmpl" }} - -{{ end }} \ No newline at end of file diff --git a/templates/wde-widgets/file-tile-view.tmpl b/templates/wde-widgets/file-tile-view.tmpl deleted file mode 100644 index c3d8dc8..0000000 --- a/templates/wde-widgets/file-tile-view.tmpl +++ /dev/null @@ -1,11 +0,0 @@ -{{ define "wde-widgets/file-tile-view.tmpl" }} -
- {{ range $fileTile := .Files }} -
- - -
{{ $fileTile.Name }}
-
- {{ end }} -
-{{ end }} \ No newline at end of file diff --git a/templates/wde-widgets/file-tile.tmpl b/templates/wde-widgets/file-tile.tmpl deleted file mode 100644 index 5642d5c..0000000 --- a/templates/wde-widgets/file-tile.tmpl +++ /dev/null @@ -1,6 +0,0 @@ -{{ define "wde-widgets/file-tile.tmpl" }} -
-
-
{{ .Name }}
-
-{{ end }} \ No newline at end of file diff --git a/templates/wde-widgets/scrollbar.tmpl b/templates/wde-widgets/scrollbar.tmpl deleted file mode 100644 index 4dc0cde..0000000 --- a/templates/wde-widgets/scrollbar.tmpl +++ /dev/null @@ -1,8 +0,0 @@ -{{ define "wde-widgets/scrollbar.tmpl" }} -
-
-
-
-
-
-{{ end }} \ No newline at end of file diff --git a/webfs/directory.go b/webfs/directory.go new file mode 100644 index 0000000..d99d9a9 --- /dev/null +++ b/webfs/directory.go @@ -0,0 +1,7 @@ +package webfs + +import "go.mongodb.org/mongo-driver/bson/primitive" + +type Directory struct { + Children []primitive.ObjectID `json:"children" bson:"children"` +} diff --git a/webfs/utils.go b/webfs/utils.go new file mode 100644 index 0000000..fb6cca3 --- /dev/null +++ b/webfs/utils.go @@ -0,0 +1,23 @@ +package webfs + +import "strings" + +func SplitPath(path string) []string { + var resPath []string + splittedPath := strings.Split(path, "/") + splittedPath[0] = "/" + for _, split := range splittedPath { + if split != "" { + resPath = append(resPath, split) + } + } + return resPath +} + +func GetParentPath(path string) string { + splittedPath := SplitPath(path) + if len(splittedPath) > 1 { + return "/" + strings.Join(splittedPath[1:len(splittedPath)-1], "/") + } + return "/" +} diff --git a/webfs/webfs.go b/webfs/webfs.go new file mode 100644 index 0000000..e123a53 --- /dev/null +++ b/webfs/webfs.go @@ -0,0 +1,131 @@ +package webfs + +import ( + "context" + "errors" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "log" +) + +var mcli *mongo.Client +var filesTable *mongo.Collection +var filesData *mongo.Collection + +//var ctx context.Context + +//type File struct { +// ID primitive.ObjectID `json:"ID" bson:"_id"` +// Header FileHeader `json:"header" bson:"header"` +// Body interface{} `json:"body" bson:"body"` +//} + +type FileHeader struct { + Name string `json:"name" bson:"name"` + DataID primitive.ObjectID `json:"dataID" bson:"data_id"` + Type string `json:"type" bson:"type"` +} + +//type FileBody interface { +//} + +func Init(ctx context.Context, mongoConnect string, mongoDatabaseString string, filesCollectionName string) (err error) { + //ctx = ctx + clientOptions := options.Client().ApplyURI(mongoConnect) + + // Create mongo client for in package usage + mcli, err = mongo.Connect(ctx, clientOptions) + if err != nil { + return err + } + + // Ping database for test new connection + err = mcli.Ping(ctx, nil) + if err != nil { + log.Fatal(err) + } + + filesTable = mcli.Database(mongoDatabaseString).Collection("table-3") + filesData = mcli.Database(mongoDatabaseString).Collection("data-3") + + return nil +} + +func CreateFile(ctx context.Context, path string, fileHeader FileHeader, fileData interface{}) (id primitive.ObjectID, err error) { + //parentPath := GetParentPath(path) + + res, err := filesData.InsertOne(ctx, fileData) + if err != nil { + return + } + splittedPath := SplitPath(path) + + dataId := res.InsertedID.(primitive.ObjectID) + + fileHeader.Name = splittedPath[len(splittedPath)-1] + fileHeader.DataID = dataId + + res, err = filesTable.InsertOne(ctx, fileHeader) + if err != nil { + return + } + id = res.InsertedID.(primitive.ObjectID) + return +} + +func CreateDir(ctx context.Context, path string) (id primitive.ObjectID, err error) { + if len(path) < 2 { + err = errors.New("TODO") + return //TODO + } + + splittedPath := SplitPath(path) + parentPath := GetParentPath(path) + + r := File{ + Header: FileHeader{ + Name: splittedPath[len(splittedPath)-1], + Type: "directory", + }, + Body: Directory{Children: []primitive.ObjectID{}}, + } + + id, err = CreateFile(ctx, "", r) + return +} + +func readFile[T interface{}](ctx context.Context, fileID primitive.ObjectID) (file File) { + filter := primitive.M{ + "_id": fileID, + } + res, err := filesTable.FindOne(ctx, filter) + +} + +//func CreateRoot(ctx context.Context) (id primitive.ObjectID, err error) { +// r := File{ +// Header: FileHeader{ +// Name: "/", +// Type: "directory", +// }, +// Body: Directory{Children: []primitive.ObjectID{}}, +// } +// +// id, err = CreateFile(ctx, "", r) +// return +//} + +//func (fs *WebFileSystem) Read(filePath string, fileData interface{}) (*FileHeader, error) { +// fileId, err := fs.FindFile(filePath) +// if err != nil { +// return nil, err +// } +// +// fileHeader, err := fs.ReadByObjectID(fileId, fileData) +// if err != nil { +// return nil, err +// } +// +// return fileHeader, nil +//}