mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
CGS: implement MimeTyper interface
This commit is contained in:
24
vfs/gcsfs.go
24
vfs/gcsfs.go
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
gcsDefaultFieldsSelection = []string{"Name", "Size", "Deleted", "Updated", "ContentType"}
|
||||
gcsDefaultFieldsSelection = []string{"Name", "Size", "Deleted", "Updated"}
|
||||
)
|
||||
|
||||
// GCSFs is a Fs implementation for Google Cloud Storage.
|
||||
@@ -121,9 +121,6 @@ func (fs GCSFs) Stat(name string) (os.FileInfo, error) {
|
||||
if fs.isEqual(attrs.Name, name) {
|
||||
isDir := strings.HasSuffix(attrs.Name, "/")
|
||||
result = NewFileInfo(name, isDir, attrs.Size, attrs.Updated, false)
|
||||
if !isDir {
|
||||
result.setContentType(attrs.ContentType)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -184,7 +181,7 @@ func (fs GCSFs) Create(name string, flag int) (*os.File, *PipeWriter, func(), er
|
||||
objectWriter := obj.NewWriter(ctx)
|
||||
contentType := mime.TypeByExtension(path.Ext(name))
|
||||
if contentType != "" {
|
||||
objectWriter.ObjectAttrs.ContentType = contentType
|
||||
objectWriter.ObjectAttrs.ContentType = contentType
|
||||
}
|
||||
if len(fs.config.StorageClass) > 0 {
|
||||
objectWriter.ObjectAttrs.StorageClass = fs.config.StorageClass
|
||||
@@ -359,9 +356,6 @@ func (fs GCSFs) ReadDir(dirname string) ([]os.FileInfo, error) {
|
||||
continue
|
||||
}
|
||||
fi := NewFileInfo(name, isDir, attrs.Size, attrs.Updated, false)
|
||||
if !isDir {
|
||||
fi.setContentType(attrs.ContentType)
|
||||
}
|
||||
result = append(result, fi)
|
||||
}
|
||||
}
|
||||
@@ -596,3 +590,17 @@ func (fs *GCSFs) getPrefixForStat(name string) string {
|
||||
}
|
||||
return prefix
|
||||
}
|
||||
|
||||
// GetMimeType implements MimeTyper interface
|
||||
func (fs GCSFs) GetMimeType(name string) (string, error) {
|
||||
ctx, cancelFn := context.WithDeadline(context.Background(), time.Now().Add(fs.ctxTimeout))
|
||||
defer cancelFn()
|
||||
bkt := fs.svc.Bucket(fs.config.Bucket)
|
||||
obj := bkt.Object(name)
|
||||
attrs, err := obj.Attrs(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logger.DebugToConsole("content type: %v", attrs.ContentType)
|
||||
return attrs.ContentType, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user