|
|
@ -8,7 +8,8 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
type IStorageProvider interface { |
|
|
|
store(bucketName string, objectName string, data []byte) |
|
|
|
storeRaw(bucketName string, objectName string, data []byte) |
|
|
|
storeExisting(bucketName string, objectName string, existingFilePath string) |
|
|
|
} |
|
|
|
|
|
|
|
type FileSystemStorageProvider struct { |
|
|
@ -16,7 +17,7 @@ type FileSystemStorageProvider struct { |
|
|
|
basePath string |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) store(bucketName string, objectName string, data []byte) { |
|
|
|
func (sp FileSystemStorageProvider) storeRaw(bucketName string, objectName string, data []byte) { |
|
|
|
directoryPath := filepath.Join(sp.basePath, bucketName) |
|
|
|
|
|
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm) |
|
|
@ -25,3 +26,14 @@ func (sp FileSystemStorageProvider) store(bucketName string, objectName string, |
|
|
|
|
|
|
|
afero.WriteFile(sp.fileSystem, filePath, data, os.ModePerm) |
|
|
|
} |
|
|
|
|
|
|
|
func (sp FileSystemStorageProvider) storeExisting(bucketName string, objectName string, existingFilePath string) { |
|
|
|
directoryPath := filepath.Join(sp.basePath, bucketName) |
|
|
|
|
|
|
|
sp.fileSystem.MkdirAll(directoryPath, os.ModePerm) |
|
|
|
|
|
|
|
filePath := filepath.Join(directoryPath, objectName) |
|
|
|
|
|
|
|
bytesRead, _ := afero.ReadFile(sp.fileSystem, existingFilePath) |
|
|
|
afero.WriteFile(sp.fileSystem, filePath, bytesRead, os.ModePerm) |
|
|
|
} |