From 2983f55ea70735680582db272ac1f3b4ecb75c02 Mon Sep 17 00:00:00 2001 From: Gregory Brzezinski Date: Fri, 24 Nov 2023 22:12:13 +0300 Subject: [PATCH] new webfs and whole back --- .idea/.gitignore | 8 ++ .idea/modules.xml | 8 ++ .idea/personal-website.iml | 9 ++ .idea/vcs.xml | 6 + main.go | 94 ++++++------- pure-html/base.html | 19 --- pure-html/basic-window.html | 17 --- pure-html/index.html | 35 ----- routes/new.go | 46 ++++++ templates/base/index.tmpl | 40 ------ templates/base/mobile-desktop.tmpl | 26 ---- templates/blog-viewer/app.tmpl | 38 ----- templates/blog-viewer/mobile-app.tmpl | 18 --- templates/finder/admin-app.tmpl | 32 ----- templates/finder/app.tmpl | 27 ---- templates/finder/desktop.tmpl | 6 - templates/finder/mobile-app.tmpl | 8 -- templates/finder/mobile-desktop.tmpl | 8 -- templates/finder/props.tmpl | 62 --------- templates/img-viewer/app.tmpl | 20 --- templates/img-viewer/mobile-app.tmpl | 9 -- templates/personal-properties/app.tmpl | 57 -------- templates/personal-properties/mobile-app.tmpl | 45 ------ templates/posts/index.tmpl | 7 - templates/users/index.tmpl | 7 - templates/wde-widgets/context-menu.tmpl | 12 -- templates/wde-widgets/file-tile-view.tmpl | 11 -- templates/wde-widgets/file-tile.tmpl | 6 - templates/wde-widgets/scrollbar.tmpl | 8 -- webfs/directory.go | 7 + webfs/utils.go | 23 +++ webfs/webfs.go | 131 ++++++++++++++++++ 32 files changed, 283 insertions(+), 567 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/modules.xml create mode 100644 .idea/personal-website.iml create mode 100644 .idea/vcs.xml delete mode 100644 pure-html/base.html delete mode 100644 pure-html/basic-window.html delete mode 100644 pure-html/index.html create mode 100644 routes/new.go delete mode 100644 templates/base/index.tmpl delete mode 100644 templates/base/mobile-desktop.tmpl delete mode 100644 templates/blog-viewer/app.tmpl delete mode 100644 templates/blog-viewer/mobile-app.tmpl delete mode 100644 templates/finder/admin-app.tmpl delete mode 100644 templates/finder/app.tmpl delete mode 100644 templates/finder/desktop.tmpl delete mode 100644 templates/finder/mobile-app.tmpl delete mode 100644 templates/finder/mobile-desktop.tmpl delete mode 100644 templates/finder/props.tmpl delete mode 100644 templates/img-viewer/app.tmpl delete mode 100644 templates/img-viewer/mobile-app.tmpl delete mode 100644 templates/personal-properties/app.tmpl delete mode 100644 templates/personal-properties/mobile-app.tmpl delete mode 100644 templates/posts/index.tmpl delete mode 100644 templates/users/index.tmpl delete mode 100644 templates/wde-widgets/context-menu.tmpl delete mode 100644 templates/wde-widgets/file-tile-view.tmpl delete mode 100644 templates/wde-widgets/file-tile.tmpl delete mode 100644 templates/wde-widgets/scrollbar.tmpl create mode 100644 webfs/directory.go create mode 100644 webfs/utils.go create mode 100644 webfs/webfs.go 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 +//}