mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-23 20:50:18 +01:00
added head function to storage
This commit is contained in:
parent
2d303a68a6
commit
4f3347aaab
1 changed files with 26 additions and 0 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
type Storage interface {
|
||||
Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error)
|
||||
Head(token string, filename string) (contentType string, contentLength uint64, err error)
|
||||
Put(token string, filename string, reader io.Reader, contentType string, contentLength uint64) error
|
||||
}
|
||||
|
||||
|
@ -24,6 +25,20 @@ func NewLocalStorage(basedir string) (*LocalStorage, error) {
|
|||
return &LocalStorage{basedir: basedir}, nil
|
||||
}
|
||||
|
||||
func (s *LocalStorage) Head(token string, filename string) (contentType string, contentLength uint64, err error) {
|
||||
path := filepath.Join(s.basedir, token, filename)
|
||||
|
||||
var fi os.FileInfo
|
||||
if fi, err = os.Lstat(path); err != nil {
|
||||
}
|
||||
|
||||
contentLength = uint64(fi.Size())
|
||||
|
||||
contentType = mime.TypeByExtension(filepath.Ext(filename))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) {
|
||||
path := filepath.Join(s.basedir, token, filename)
|
||||
|
||||
|
@ -81,6 +96,17 @@ func NewS3Storage() (*S3Storage, error) {
|
|||
return &S3Storage{bucket: bucket}, nil
|
||||
}
|
||||
|
||||
func (s *S3Storage) Head(token string, filename string) (contentType string, contentLength uint64, err error) {
|
||||
key := fmt.Sprintf("%s/%s", token, filename)
|
||||
|
||||
// content type , content length
|
||||
response, err := s.bucket.Head(key, map[string][]string{})
|
||||
contentType = ""
|
||||
contentLength, err = strconv.ParseUint(response.Header.Get("Content-Length"), 10, 0)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *S3Storage) Get(token string, filename string) (reader io.ReadCloser, contentType string, contentLength uint64, err error) {
|
||||
key := fmt.Sprintf("%s/%s", token, filename)
|
||||
|
||||
|
|
Loading…
Reference in a new issue