personal-website/webfilesystem/webfilesystem.go

72 lines
1.5 KiB
Go
Raw Normal View History

2023-03-22 21:53:06 +00:00
package webfilesystem
2023-04-25 09:37:42 +00:00
import (
"context"
"strings"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
2023-04-12 17:04:25 +00:00
2023-03-22 21:53:06 +00:00
type WebFileSystem struct {
2023-04-25 09:37:42 +00:00
webfsCollection *mongo.Collection
// folders []*Folder
}
func NewWebFileSystem(mongoClient *mongo.Client, dBName string, fsCollectionName string) *WebFileSystem {
return &WebFileSystem{
webfsCollection: mongoClient.Database(dBName).Collection(fsCollectionName), // TODO Check collection is exist
}
2023-03-22 21:53:06 +00:00
}
2023-04-25 09:37:42 +00:00
func (fs *WebFileSystem) List(path string) ([]*WebFSFile, error) {
return nil, nil
2023-03-22 21:53:06 +00:00
}
2023-04-25 09:37:42 +00:00
func (fs *WebFileSystem) Read(path string) (*WebFSFile, error) {
splittedPath := strings.Split(path, "/")
filter := primitive.D{
{
Key: "filename",
Value: splittedPath[len(splittedPath)-1],
},
}
if splittedPath == []string{"",""}
res := fs.webfsCollection.FindOne(context.TODO(), &filter)
findedFile := WebFSFile{}
err := res.Decode(&findedFile)
return &findedFile, err
2023-03-22 21:53:06 +00:00
}
2023-04-13 01:09:07 +00:00
type WebFSFile struct {
2023-04-25 09:37:42 +00:00
MongoId primitive.ObjectID `bson:"_id"`
Name string `bson:"name"`
Type string `bson:"type"`
data interface{} `bson:"data"`
2023-04-13 01:09:07 +00:00
}
2023-04-25 09:37:42 +00:00
type FolderData struct {
Parent primitive.ObjectID `bson:"parent"`
Childs []primitive.ObjectID `bson:"childs"`
}
2023-04-13 01:09:07 +00:00
type File interface {
GetUuid() string
GetFileName() string
}
type Image struct {
}
type Exec struct {
WebFSFile
}
2023-04-25 09:37:42 +00:00
// func (e *Exec) GetUuid() string {
// return e.Id
// }
2023-04-13 01:09:07 +00:00
func (e *Exec) GetFileName() string {
2023-04-25 09:37:42 +00:00
return e.Name
2023-03-22 21:53:06 +00:00
}