2019-11-10 19:03:57 +01:00
|
|
|
package rushlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Where to store the uploaded files
|
|
|
|
var fileStoreDir = ""
|
|
|
|
|
2019-12-03 23:08:58 +01:00
|
|
|
// FileUploadFileSystem is a HTTP filesystem handler
|
|
|
|
type FileUploadFileSystem struct {
|
2019-11-10 19:03:57 +01:00
|
|
|
fs http.FileSystem
|
|
|
|
}
|
|
|
|
|
2019-12-03 23:08:58 +01:00
|
|
|
// Open opens a file
|
|
|
|
func (fs FileUploadFileSystem) Open(path string) (http.File, error) {
|
2019-11-10 19:03:57 +01:00
|
|
|
log.Println(path)
|
|
|
|
file, err := fs.fs.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "opening file")
|
|
|
|
}
|
|
|
|
stat, err := file.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "file.Stat()")
|
|
|
|
}
|
|
|
|
if stat.IsDir() {
|
|
|
|
return nil, errors.New("directory index not allowed")
|
|
|
|
}
|
|
|
|
return file, nil
|
|
|
|
}
|