URL shortener and file dump for hashru.link https://hashru.link
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

34 lines
644 B

  1. package rushlink
  2. import (
  3. "log"
  4. "net/http"
  5. "github.com/pkg/errors"
  6. )
  7. // Where to store the uploaded files
  8. var fileStoreDir = ""
  9. // FileUploadFileSystem is a HTTP filesystem handler
  10. type FileUploadFileSystem struct {
  11. fs http.FileSystem
  12. }
  13. // Open opens a file
  14. func (fs FileUploadFileSystem) Open(path string) (http.File, error) {
  15. log.Println(path)
  16. file, err := fs.fs.Open(path)
  17. if err != nil {
  18. return nil, errors.Wrap(err, "opening file")
  19. }
  20. stat, err := file.Stat()
  21. if err != nil {
  22. return nil, errors.Wrap(err, "file.Stat()")
  23. }
  24. if stat.IsDir() {
  25. return nil, errors.New("directory index not allowed")
  26. }
  27. return file, nil
  28. }