personal-website/webfilesystem/public.go

71 lines
1.5 KiB
Go
Raw Permalink Normal View History

2023-05-07 01:00:22 +00:00
package webfilesystem
2023-05-10 12:39:49 +00:00
import "go.mongodb.org/mongo-driver/bson/primitive"
2023-05-07 01:00:22 +00:00
func (fs *WebFileSystem) Read(filePath string, fileData interface{}) (*FileHeader, error) {
fileId, err := fs.FindFile(filePath)
if err != nil {
return nil, err
}
2023-05-16 12:12:55 +00:00
fileHeader, err := fs.ReadByObjectID(fileId, fileData)
2023-05-07 01:00:22 +00:00
if err != nil {
return nil, err
}
return fileHeader, nil
}
2023-05-10 12:39:49 +00:00
2023-09-13 01:37:49 +00:00
// 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
}
2023-05-10 12:39:49 +00:00
func (fs *WebFileSystem) ReadByObjectID(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
fileHeader, err := fs.readFSDocs(fileID, fileData)
if err != nil {
return nil, err
}
2023-05-16 12:12:55 +00:00
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
}
2023-05-10 12:39:49 +00:00
return fileHeader, nil
}