@@ -1,6 +1,6 @@ | |||||
The MIT License (MIT) | The MIT License (MIT) | ||||
Copyright (c) 2014 DutchCoders [https://github.com/dutchcoders/] | |||||
Copyright (c) 2014-2018 DutchCoders [https://github.com/dutchcoders/] | |||||
Permission is hereby granted, free of charge, to any person obtaining a copy | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
of this software and associated documentation files (the "Software"), to deal | of this software and associated documentation files (the "Software"), to deal | ||||
@@ -8,15 +8,19 @@ Transfer.sh currently supports the s3 (Amazon S3), gdrive (Google Drive) provide | |||||
``` | ``` | ||||
Upload: | Upload: | ||||
$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt | $ curl --upload-file ./hello.txt https://transfer.sh/hello.txt | ||||
Encrypt & upload: | Encrypt & upload: | ||||
$ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/test.txt | $ cat /tmp/hello.txt|gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/test.txt | ||||
Download & decrypt: | Download & decrypt: | ||||
$ curl https://transfer.sh/1lDau/test.txt|gpg -o- > /tmp/hello.txt | $ curl https://transfer.sh/1lDau/test.txt|gpg -o- > /tmp/hello.txt | ||||
Upload to virustotal: | Upload to virustotal: | ||||
$ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal | $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal | ||||
``` | ``` | ||||
@@ -33,6 +37,16 @@ Now run it like this | |||||
$ transfer test.txt | $ transfer test.txt | ||||
``` | ``` | ||||
## Link aliases | |||||
Create direct download link: | |||||
https://transfer.sh/1lDau/test.txt --> https://transfer.sh/get/1lDau/test.txt | |||||
Inline file: | |||||
https://transfer.sh/1lDau/test.txt --> https://transfer.sh/inline/1lDau/test.txt | |||||
### On Windows | ### On Windows | ||||
Put a file called transfer.cmd somewhere in your PATH with this inside it: | Put a file called transfer.cmd somewhere in your PATH with this inside it: | ||||
@@ -70,7 +84,7 @@ basedir | path storage for local/gdrive provider| | | |||||
gdrive-client-json-filepath | path to client json config for gdrive provider| | | gdrive-client-json-filepath | path to client json config for gdrive provider| | | ||||
gdrive-local-config-path | path to local transfer.sh config cache for gdrive provider| | | gdrive-local-config-path | path to local transfer.sh config cache for gdrive provider| | | ||||
lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | | lets-encrypt-hosts | hosts to use for lets encrypt certificates (comma seperated) | | | ||||
log | path to log file| | | |||||
log | path to log file| | | |||||
If you want to use TLS using lets encrypt certificates, set lets-encrypt-hosts to your domain, set tls-listener to :443 and enable force-https. | If you want to use TLS using lets encrypt certificates, set lets-encrypt-hosts to your domain, set tls-listener to :443 and enable force-https. | ||||
@@ -81,7 +95,7 @@ If you want to use TLS using your own certificates, set tls-listener to :443, fo | |||||
Make sure your GOPATH is set correctly. | Make sure your GOPATH is set correctly. | ||||
``` | ``` | ||||
go run main.go -provider=local --listener :8080 --temp-path=/tmp/ --basedir=/tmp/ | |||||
go run main.go -provider=local --listener :8080 --temp-path=/tmp/ --basedir=/tmp/ | |||||
``` | ``` | ||||
## Build | ## Build | ||||
@@ -102,7 +116,7 @@ docker run --publish 8080:8080 dutchcoders/transfer.sh:latest --provider local - | |||||
Contributions are welcome. | Contributions are welcome. | ||||
## Creators | |||||
## Creators | |||||
**Remco Verhoef** | **Remco Verhoef** | ||||
- <https://twitter.com/remco_verhoef> | - <https://twitter.com/remco_verhoef> | ||||
@@ -112,5 +126,5 @@ Contributions are welcome. | |||||
## Copyright and license | ## Copyright and license | ||||
Code and documentation copyright 2011-2014 Remco Verhoef. | |||||
Code released under [the MIT license](LICENSE). | |||||
Code and documentation copyright 2011-2014 Remco Verhoef. | |||||
Code released under [the MIT license](LICENSE). |
@@ -791,9 +791,37 @@ func (s *Server) tarHandler(w http.ResponseWriter, r *http.Request) { | |||||
} | } | ||||
} | } | ||||
func (s *Server) headHandler(w http.ResponseWriter, r *http.Request) { | |||||
vars := mux.Vars(r) | |||||
token := vars["token"] | |||||
filename := vars["filename"] | |||||
if err := s.CheckMetadata(token, filename); err != nil { | |||||
log.Printf("Error metadata: %s", err.Error()) | |||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) | |||||
return | |||||
} | |||||
contentType, contentLength, err := s.storage.Head(token, filename) | |||||
if s.storage.IsNotExist(err) { | |||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) | |||||
return | |||||
} else if err != nil { | |||||
log.Printf("%s", err.Error()) | |||||
http.Error(w, "Could not retrieve file.", 500) | |||||
return | |||||
} | |||||
w.Header().Set("Content-Type", contentType) | |||||
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10)) | |||||
w.Header().Set("Connection", "close") | |||||
} | |||||
func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) { | func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) { | ||||
vars := mux.Vars(r) | vars := mux.Vars(r) | ||||
action := vars["action"] | |||||
token := vars["token"] | token := vars["token"] | ||||
filename := vars["filename"] | filename := vars["filename"] | ||||
@@ -815,10 +843,18 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) { | |||||
defer reader.Close() | defer reader.Close() | ||||
var disposition string | |||||
if action == "inline" { | |||||
disposition = "inline" | |||||
} else { | |||||
disposition = "attachment" | |||||
} | |||||
w.Header().Set("Content-Type", contentType) | w.Header().Set("Content-Type", contentType) | ||||
w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10)) | w.Header().Set("Content-Length", strconv.FormatUint(contentLength, 10)) | ||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) | |||||
w.Header().Set("Connection", "close") | |||||
w.Header().Set("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, filename)) | |||||
w.Header().Set("Connection", "keep-alive") | |||||
if _, err = io.Copy(w, reader); err != nil { | if _, err = io.Copy(w, reader); err != nil { | ||||
log.Printf("%s", err.Error()) | log.Printf("%s", err.Error()) | ||||
@@ -324,6 +324,9 @@ func (s *Server) Run() { | |||||
r.HandleFunc("/({files:.*}).tar", s.tarHandler).Methods("GET") | r.HandleFunc("/({files:.*}).tar", s.tarHandler).Methods("GET") | ||||
r.HandleFunc("/({files:.*}).tar.gz", s.tarGzHandler).Methods("GET") | r.HandleFunc("/({files:.*}).tar.gz", s.tarGzHandler).Methods("GET") | ||||
r.HandleFunc("/{token}/{filename}", s.headHandler).Methods("HEAD") | |||||
r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", s.headHandler).Methods("HEAD") | |||||
r.HandleFunc("/{token}/{filename}", s.previewHandler).MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) (match bool) { | r.HandleFunc("/{token}/{filename}", s.previewHandler).MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) (match bool) { | ||||
match = false | match = false | ||||
@@ -352,8 +355,7 @@ func (s *Server) Run() { | |||||
} | } | ||||
r.HandleFunc("/{token}/{filename}", getHandlerFn).Methods("GET") | r.HandleFunc("/{token}/{filename}", getHandlerFn).Methods("GET") | ||||
r.HandleFunc("/get/{token}/{filename}", getHandlerFn).Methods("GET") | |||||
r.HandleFunc("/download/{token}/{filename}", getHandlerFn).Methods("GET") | |||||
r.HandleFunc("/{action:(?:download|get|inline)}/{token}/{filename}", getHandlerFn).Methods("GET") | |||||
r.HandleFunc("/{filename}/virustotal", s.virusTotalHandler).Methods("PUT") | r.HandleFunc("/{filename}/virustotal", s.virusTotalHandler).Methods("PUT") | ||||
r.HandleFunc("/{filename}/scan", s.scanHandler).Methods("PUT") | r.HandleFunc("/{filename}/scan", s.scanHandler).Methods("PUT") | ||||