new webfs and whole back

This commit is contained in:
Gregory Brzezinski 2023-11-24 22:12:13 +03:00
parent fb6b310a49
commit 2983f55ea7
32 changed files with 283 additions and 567 deletions

8
.idea/.gitignore vendored Normal file
View File

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

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/personal-website.iml" filepath="$PROJECT_DIR$/.idea/personal-website.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

94
main.go
View File

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

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<link rel="stylesheet" type="text/css" href="res/base.css">
<link rel="stylesheet" type="text/css" href="res/wdeUI.css">
<script src="res/wde.js"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> -->
<!-- <script src="res/decorat.js"></script> -->
<!-- TODO Load with app -->
<!-- <script src="res/personal-properties.js"></script> -->
</head>
<body>
<div id="WindowsLayer"></div>
<div id="Applications"></div>
<!-- <div id="TestWindow" style="width: 100px; height: 100px; background-color: darkkhaki; position: absolute;" >
<div id="TestWindowHeader" class="VisualDragArea" style="width: 100%;height: 15px; background-color: cornflowerblue;">
</div> -->
</body>
</html>

View File

@ -1,17 +0,0 @@
<!-- FIXME delete fixed size -->
<div id="RootWidget" class="Application" style="width: 350px;height: 450px;" >
<div id="WindowBorder" class="Frame">
<div id="TestWindowHeader" class="WindowFrameTopBar">
<button class="WindowFrameTopBarButton"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
Test Title
</div>
<div id="Drag" class="VisualDragArea"></div>
<button class="WindowFrameTopBarButton" ></button>
</div>
<div id="ContentFrame" class="ContentFrame">
</div>
</div>
</div>

View File

@ -1,35 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="stylesheet" href="../../packages/simplebar/dist/simplebar.min.css">
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script src="../../packages/simplebar/dist/simplebar.min.js"></script>
<script>
$(document).ready(function() {
new SimpleBar($('#container')[0]);
});
</script>
<style>
#container {
background-color: lightgray;
max-height: 70px;
overflow: auto;
}
</style>
</head>
<body>
<div id="container">
<p>↓Scrollable!↓</p>
<p>↓Scrollable!↓</p>
<p>↓Scrollable!↓</p>
<p>↓Scrollable!↓</p>
<p>↓Scrollable!↓</p>
</div>
</body>
</html>

46
routes/new.go Normal file
View File

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

View File

@ -1,40 +0,0 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<title>Greg Brzezinski</title>
<head>
<link rel="stylesheet" type="text/css" href="res/dev-fs/wde/base.css">
<link rel="stylesheet" type="text/css" href="res/dev-fs/wde/wdeUI.css">
<link rel="stylesheet" type="text/css" href="res/dev-fs/wde/basic-widgets.css">
<link rel="stylesheet" type="text/css" href="res/dev-fs/wde/wde-scrollbar.css">
<link rel="stylesheet" type="text/css" href="res/dev-fs/wde/file-view.css">
<!-- TODO: Move css init to js -->
<link rel="stylesheet" href="res/dev-fs/apps/Finder/finder.css">
<link rel="stylesheet" href="/res/dev-fs/apps/AboutMe/about-me.css">
<link rel="stylesheet" href="/res/dev-fs/apps/ImgViewer/img-viewer.css">
<link rel="stylesheet" href="/res/dev-fs/apps/BlogViewer/blog-viewer.css">
<script src="res/dev-fs/wde/wde.js"></script>
<script src="res/dev-fs/wde/decorat.js"></script>
<script src="res/dev-fs/wde/webfs.js"></script>
<script src="/res/dev-fs/wde/wde-scrollbar.js"></script>
<script src="/res/dev-fs/wde/file-view.js"></script>
</head>
<body>
<wde-autostart>
{{ range $app := .autostart }}
<app app-path="{{ $app.AppPath }}">
<args>
{{ range $arg := $app.Args }}
<arg string="{{ $arg }}"></arg>
{{ end }}
</args>
</app>
{{ end }}
</wde-autostart>
<div id="applications"></div>
<div id="desktop-layer"></div>
<div id="windows-layer"></div>
</body>
</html>

View File

@ -1,26 +0,0 @@
{{ define "base/mobile-desktop.tmpl" }}
<div id="border" class="">
<div id="windows-layer" class="mobile-windows-layer ContentBorder">
<div class="FileTileView">
</div>
</div>
</div>
<div id="toolbar">
<div id="about-me" class="FileTile" >
<div class="Icon NoClick" style="background-image: url('./res/sys/wde/icons/about-me.png');"></div>
<div class="FileTileTitle NoClick">About Me</div>
</div>
<div id="mobile-desktop-blog" class="FileTile">
<div class="Icon NoClick" style="background-image: url('./res/sys/wde/icons/desktop.png');"></div>
<div class="FileTileTitle NoClick">Blog</div>
</div>
<div id="mobile-dekstop-close" class="FileTile">
<div class="Icon NoClick" style="background-image: url('./res/sys/wde/icons/trash.png');"></div>
<div class="FileTileTitle NoClick">Close</div>
</div>
</div>
{{ end }}

View File

@ -1,38 +0,0 @@
{{ define "blog-viewer/app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
Blog Viewer
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div class="ContentBorder AdjectiveElement">
<div class="BlogView">
<div class="Content">
<div class="ScrollContent">
{{ range $block := .blocks }}
{{ if eq $block.Type "image"}}
<div class="{{$block.Type}}" >
{{ range $data := $block.Data }}
<img class="ImageProp" src="/system/libs/img/get?path={{$data}}">
{{ end }}
</div>
{{ else }}
<div class="{{$block.Type}}" >
{{ range $data := $block.Data }}
<div style="font-size: inherit;">
{{$data}}
</div>
{{ end }}
</div>
{{ end }}
{{ end }}
</div>
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
</div>
{{ end }}

View File

@ -1,18 +0,0 @@
{{ 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,32 +0,0 @@
{{ define "finder/admin-app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
Admin Finder
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div id="ContentBorder" class="ContentBorder AdjectiveElement">
<div class="FinderContent">
<!-- TODO Fix ConvexElement -->
<div class="ToolBar ConvexElement">
<button id="BackButton">Back</button>
<button id="UpButton">Up</button>
<button id="RootButton">/</button>
<button id="HomeButton">Home</button>
<div class="AddressBar" contentEditable="true">You Favorite Movie</div>
</div>
<div class="FinderFileView">
<div class="FileTileView">
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
</div>
</div>
{{ end }}

View File

@ -1,27 +0,0 @@
{{ define "finder/app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
Finder
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div id="ContentBorder" class="ContentBorder AdjectiveElement">
<div class="FinderContent">
<!-- TODO Fix ConvexElement -->
<div class="ToolBar ConvexElement">
Folder info
</div>
<div class="FinderFileView">
<div class="FileTileView">
</div>
{{template "wde-widgets/scrollbar.tmpl" .}}
</div>
</div>
</div>
{{ end }}

View File

@ -1,6 +0,0 @@
{{ define "finder/desktop.tmpl" }}
<div class="FileTileView">
</div>
{{ end }}

View File

@ -1,8 +0,0 @@
{{ define "finder/mobile-app.tmpl" }}
<div class="MobileContentBorder">
<div class="FileTileView">
</div>
</div>
{{ end }}

View File

@ -1,8 +0,0 @@
{{ define "finder/mobile-desktop.tmpl" }}
<div class="MobileContentBorder">
<div class="FileTileView">
</div>
</div>
{{ end }}

View File

@ -1,62 +0,0 @@
{{ define "finder/props.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
File Properties
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div class="ContentBorder">
<div class="PropertiesList">
<div class="Personal-properties-bio">
<!-- <img src="data:{{ .headerProps.Icon.Header }},{{ .headerProps.Icon.Base64 }}" alt="File Icon" style="width: 48px;height: 48px;"> -->
<div class="Personal-properties-textbio">
<div>{{ .file.Name }}</div>
<!-- <div>{{ .headerProps.Info1 }}</div>
<div>{{ .headerProps.Info2 }}</div> -->
</div>
</div>
<div>
file id : {{.file.MongoId}}
</div>
<div>
file type : {{.file.Type}}
</div>
<div>
file data id : {{.file.Data}}
</div>
{{ range $propIsland := .allprops }}
<div id="prop" class="Personal-properties-prop">
<div class="Personal-properties-prop-title">
{{$propIsland.Header}}:
</div>
<div class="Personal-properties-prop-content">
{{range $prop := $propIsland.Props}}
<div class="Personal-properties-prop-row">
<div class="Personal-properties-prop-key">
{{$prop.Key}}:
{{ range $value := $prop.KeyComments }}
<div class="Personal-properties-prop-key-comments">
{{ $value }}
</div>
{{ end }}
</div>
<div class="Personal-properties-prop-values">
{{ range $value := $prop.Values }}
<div class="Personal-properties-prop-value">
{{ $value }}
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
</div>
{{ end }}

View File

@ -1,20 +0,0 @@
{{ define "img-viewer/app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">
About me
</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div class="ContentBorder">
<!-- <div class="Img-Viewer-Picture-Toolbar">
Toolbar
</div> -->
<img class="Img-Viewer-Picture-Container"src="{{.imgUrl}}">
</div>
{{ end }}

View File

@ -1,9 +0,0 @@
{{ define "img-viewer/mobile-app.tmpl" }}
<div class="MobileContentBorder">
<div class="Img-Viewer-Picture-Container">
<div class="Img-Viewer-Picture">
</div>
</div>
{{ end }}

View File

@ -1,57 +0,0 @@
{{ define "personal-properties/app.tmpl" }}
<div class="TitleBar DragArea">
<button id="closeWindowButton" class="Button" title="Close Window"></button>
<div id="Drag" class="VisualDragArea"></div>
<div class="Lable">About me</div>
<div id="Drag" class="VisualDragArea"></div>
</div>
<div class="ContentBorder AdjectiveElement">
<div class="PersPropsContent">
<div class="PropsView">
<div class="PropertiesList">
<div class="Links">
{{ range $link := .Links }}
<a href="{{$link.Url}}" target="_blank">
<img class="Link" src="/system/libs/img/get?path={{$link.Icon}}" alt="{{$link.Text}}">
</a>
{{ end }}
</div>
<div class="ShortBio">
<img class="Image" src="/system/libs/img/get?path={{ .HeaderProps.IconPath }}" alt="My Photo">
<div class="Text">
<div class="Name">{{ .HeaderProps.Name }}</div>
<div>{{ .HeaderProps.Value1 }}</div>
<div>{{ .HeaderProps.Value2 }}</div>
</div>
</div>
{{ range $island := .Islands }}
<!-- FIXME -->
<div class="Island">
<div class="Title"> {{$island.Header}}:</div>
<div class="Content">
{{range $property := $island.Properties}}
<div class="Row">
<div class="Key">
{{$property.Key}}:
{{ range $keyComment := $property.KeyComments }}
<div class="KeyComment">{{ $keyComment }}</div>
{{ end }}
</div>
<div class="Values">
{{ range $value := $property.Values }}
<div class="Value">{{ $value }}</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
<!-- {{template "wde-widgets/scrollbar.tmpl" .}} -->
</div>
</div>
{{ end }}

View File

@ -1,45 +0,0 @@
{{ define "personal-properties/mobile-app.tmpl" }}
<div class="MobileContentBorder">
<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;">
<div class="Personal-properties-textbio">
<div>{{ .Name }}</div>
<div>{{ .BasicBio }}</div>
</div>
</div>
{{ range $propIsland := .allprops }}
<div id="prop" class="Personal-properties-prop">
<div class="Personal-properties-prop-title">
{{$propIsland.Header}}:
</div>
<div class="Personal-properties-prop-content">
{{range $prop := $propIsland.Props}}
<div class="Personal-properties-prop-row">
<div class="Personal-properties-prop-key">
{{$prop.Key}}:
{{ range $value := $prop.KeyComments }}
<div class="Personal-properties-prop-key-comments">
{{ $value }}
</div>
{{ end }}
</div>
<div class="Personal-properties-prop-values">
{{ range $value := $prop.Values }}
<div class="Personal-properties-prop-value">
{{ $value }}
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
</div>
</div>
{{ end }}

View File

@ -1,7 +0,0 @@
{{ define "posts/index.tmpl" }}
<html><h1>
{{ .title }}
</h1>
<p>Using posts/index.tmpl</p>
</html>
{{ end }}

View File

@ -1,7 +0,0 @@
{{ define "users/index.tmpl" }}
<html><h1>
{{ .title }}
</h1>
<p>Using users/index.tmpl</p>
</html>
{{ end }}

View File

@ -1,12 +0,0 @@
{{ define "wde-widgets/context-menu.tmpl" }}
<div class="MenuContent ConvexElement">
{{ range $island := .Islands }}
{{ range $row := $island }}
<div class="Row">
<div class="Lable NoClick" action="{{$row.Action}}">{{ $row.Label }}</div>
</div>
{{ end }}
<div class="AdjectiveHorizontalLine"></div>
{{ end }}
</div>
{{ end }}

View File

@ -1,11 +0,0 @@
{{ define "wde-widgets/file-tile-view.tmpl" }}
<div class="FlexContainer NoClick">
{{ range $fileTile := .Files }}
<div fileType="{{ $fileTile.Type }}" class="Tile Click" name="{{$fileTile.Name}}" draggable="true">
<!-- <div class="Icon NoClick"></div> -->
<img class="Icon NoClick" src="{{ $fileTile.Icon }}">
<div class="Lable NoClick">{{ $fileTile.Name }}</div>
</div>
{{ end }}
</div>
{{ end }}

View File

@ -1,6 +0,0 @@
{{ define "wde-widgets/file-tile.tmpl" }}
<div class="FileTile">
<div class="Icon"></div>
<div class="FileTileTitle">{{ .Name }}</div>
</div>
{{ end }}

View File

@ -1,8 +0,0 @@
{{ define "wde-widgets/scrollbar.tmpl" }}
<div class="ScrollbarPlace">
<div class="ScrollBarScrollElement">
<div class="ScrollBarScrollElementDrag">
</div>
</div>
</div>
{{ end }}

7
webfs/directory.go Normal file
View File

@ -0,0 +1,7 @@
package webfs
import "go.mongodb.org/mongo-driver/bson/primitive"
type Directory struct {
Children []primitive.ObjectID `json:"children" bson:"children"`
}

23
webfs/utils.go Normal file
View File

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

131
webfs/webfs.go Normal file
View File

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