github.com/vnforks/kid/v5@v5.22.1-0.20200408055009-b89d99c65676/services/filesstore/filesstore.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package filesstore 5 6 import ( 7 "io" 8 "net/http" 9 10 "github.com/vnforks/kid/v5/model" 11 ) 12 13 type ReadCloseSeeker interface { 14 io.ReadCloser 15 io.Seeker 16 } 17 18 type FileBackend interface { 19 TestConnection() *model.AppError 20 21 Reader(path string) (ReadCloseSeeker, *model.AppError) 22 ReadFile(path string) ([]byte, *model.AppError) 23 FileExists(path string) (bool, *model.AppError) 24 CopyFile(oldPath, newPath string) *model.AppError 25 MoveFile(oldPath, newPath string) *model.AppError 26 WriteFile(fr io.Reader, path string) (int64, *model.AppError) 27 RemoveFile(path string) *model.AppError 28 29 ListDirectory(path string) (*[]string, *model.AppError) 30 RemoveDirectory(path string) *model.AppError 31 } 32 33 func NewFileBackend(settings *model.FileSettings, enableComplianceFeatures bool) (FileBackend, *model.AppError) { 34 switch *settings.DriverName { 35 case model.IMAGE_DRIVER_S3: 36 return &S3FileBackend{ 37 endpoint: *settings.AmazonS3Endpoint, 38 accessKey: *settings.AmazonS3AccessKeyId, 39 secretKey: *settings.AmazonS3SecretAccessKey, 40 secure: settings.AmazonS3SSL == nil || *settings.AmazonS3SSL, 41 signV2: settings.AmazonS3SignV2 != nil && *settings.AmazonS3SignV2, 42 region: *settings.AmazonS3Region, 43 bucket: *settings.AmazonS3Bucket, 44 encrypt: settings.AmazonS3SSE != nil && *settings.AmazonS3SSE && enableComplianceFeatures, 45 trace: settings.AmazonS3Trace != nil && *settings.AmazonS3Trace, 46 }, nil 47 case model.IMAGE_DRIVER_LOCAL: 48 return &LocalFileBackend{ 49 directory: *settings.Directory, 50 }, nil 51 } 52 return nil, model.NewAppError("NewFileBackend", "api.file.no_driver.app_error", nil, "", http.StatusInternalServerError) 53 }