personal-website/webfilesystem/public.go
2023-05-16 15:12:55 +03:00

41 lines
907 B
Go

package webfilesystem
import "go.mongodb.org/mongo-driver/bson/primitive"
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
}
func (fs *WebFileSystem) ReadByObjectID(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
fileHeader, err := fs.readFSDocs(fileID, fileData)
if err != nil {
return nil, err
}
if fileHeader.Type == "objectlink" {
objectLinkData := ObjectLinkFileData{}
_, err := fs.readFSDocs(fileID, &objectLinkData)
if err != nil {
return nil, err
}
fileHeader, err := fs.readFSDocs(objectLinkData.Link_id, fileData)
if err != nil {
return nil, err
}
return fileHeader, nil
}
return fileHeader, nil
}