package webfilesystem import ( "context" "errors" "go.mongodb.org/mongo-driver/bson/primitive" ) // Deprecated type ReadStruct2 struct { File interface{} Id primitive.ObjectID } // Deprecated func (fs *WebFileSystem) Read(read ReadStruct2) (*interface{}, error) { //TODO Check nil Id filter := primitive.M{ "_id": read.Id, } err := fs.webfsCollection.FindOne(fs.ctx, filter).Decode(&read.File) return &read.File, err } // Deprecated func (fs *WebFileSystem) Write(file interface{}, filePath string, force bool) (primitive.ObjectID, error) { foundedFile, err := fs.FindFile(filePath) if err == nil { //FIXME return primitive.NilObjectID, errors.New("file already exists") } _ = foundedFile res, err := fs.webfsCollection.InsertOne(fs.ctx, file) if err != nil { return primitive.NilObjectID, err } _ = res.InsertedID return primitive.NilObjectID, nil //FIXME } // Deprecated func (fs *WebFileSystem) InitFS() error { rootDir := DirectoryFile{ FileHeader: FileHeader{ Name: "/", Type: "directory", Icon: "", }, Data: DirectoryData{ // Parent: id, //FIXME don't work Children: []primitive.ObjectID{}, }, } _, err := fs.webfsCollection.InsertOne(context.Background(), &rootDir) return err } // Deprecated type FileId struct { Id primitive.ObjectID `bson:"_id"` } // Deprecated type FileHeader struct { Name string `bson:"name" json:"name"` Type string `bson:"type" json:"type"` Icon string `bson:"-" json:"icon"` } // Deprecated type DirectoryFile struct { FileHeader `bson:"header"` Data DirectoryData `bson:"data" json:"-"` } // Deprecated type OnlyHeaderFile struct { FileHeader `bson:"header"` // Data DirectoryData `bson:"data" json:"-"` }