71 lines
1.5 KiB
Go
71 lines
1.5 KiB
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
|
|
}
|
|
|
|
// Oboslete method
|
|
func (fs *WebFileSystem) ReadData(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
|
|
}
|
|
|
|
// New method
|
|
func (fs *WebFileSystem) readData(filePath string) (interface{}, error) {
|
|
fileId, err := fs.FindFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fileData, err := fs.readFileData(fileId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return fileData, 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
|
|
}
|