personal-website/webfilesystem/newmethods.go

59 lines
1.2 KiB
Go
Raw Normal View History

2023-05-05 14:44:03 +00:00
package webfilesystem
import (
"errors"
"go.mongodb.org/mongo-driver/bson/primitive"
)
2023-05-07 00:14:30 +00:00
// Deprecated
func (fs *WebFileSystem) NewReadDeprecated(filePath string) (*WebFSFile, error) {
2023-05-05 14:44:03 +00:00
splittedPath := fs.SplitPath(filePath)
2023-05-05 22:50:57 +00:00
read := ReadStruct{
2023-05-05 14:44:03 +00:00
File: &WebFSFile{},
Filter: primitive.M{
"name": splittedPath[len(splittedPath)-1],
},
}
2023-05-05 22:50:57 +00:00
fileRaw, err := fs.ReadMongo(read)
2023-05-05 14:44:03 +00:00
if err != nil {
return nil, err
}
file := castToFile(fileRaw)
return file, nil
}
2023-05-07 00:14:30 +00:00
// Deprecated
func (fs *WebFileSystem) NewListDeprecated(dirPath string) ([]*WebFSFile, error) {
dirFile, err := fs.NewReadDeprecated(dirPath)
2023-05-05 14:44:03 +00:00
if err != nil {
return nil, err
}
if dirFile.Type != "directory" {
return nil, errors.New("file is not a directory")
}
2023-05-05 18:32:41 +00:00
fileData, err := castToDirectoryData(dirFile.Data)
2023-05-05 14:44:03 +00:00
if err != nil {
return nil, err
}
files := []*WebFSFile{}
for _, child := range fileData.Children {
file, err := fs.ReadByObjectID(child)
if err != nil {
println(err.Error())
continue
}
files = append(files, file)
}
return files, nil
}
2023-05-05 18:32:41 +00:00
func (fs *WebFileSystem) WriteFile(file *WebFSFile, parentPath string) error {
2023-05-05 14:44:03 +00:00
fs.writeMongo(*file, parentPath)
return errors.New("Not ready yet")
}