mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-12-24 11:20:18 +01:00
Fix error with defined storage
This commit is contained in:
parent
d0dbdd3591
commit
b37e706c7c
2 changed files with 14 additions and 16 deletions
|
@ -97,7 +97,7 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := vars["token"]
|
token := vars["token"]
|
||||||
filename := vars["filename"]
|
filename := vars["filename"]
|
||||||
|
|
||||||
contentType, contentLength, err := storage.Head(token, filename)
|
contentType, contentLength, err := s.storage.Head(token, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(404), 404)
|
http.Error(w, http.StatusText(404), 404)
|
||||||
return
|
return
|
||||||
|
@ -117,7 +117,7 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
templatePath = "download.markdown.html"
|
templatePath = "download.markdown.html"
|
||||||
|
|
||||||
var reader io.ReadCloser
|
var reader io.ReadCloser
|
||||||
if reader, _, _, err = storage.Get(token, filename); err != nil {
|
if reader, _, _, err = s.storage.Get(token, filename); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -255,8 +255,8 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
log.Printf("Uploading %s %s %d %s", token, filename, contentLength, contentType)
|
log.Printf("Uploading %s %s %d %s", token, filename, contentLength, contentType)
|
||||||
|
|
||||||
if err = storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
if err = s.storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
||||||
log.Printf("%s", err.Error())
|
log.Printf("Backend storage error: %s", err.Error())
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -333,8 +333,8 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if err = storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
if err = s.storage.Put(token, filename, reader, contentType, uint64(contentLength)); err != nil {
|
||||||
log.Printf("%s", err.Error())
|
log.Printf("Error putting new file: %s", err.Error())
|
||||||
http.Error(w, errors.New("Could not save file").Error(), 500)
|
http.Error(w, errors.New("Could not save file").Error(), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -396,10 +396,10 @@ func (s *Server) zipHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := strings.Split(key, "/")[0]
|
token := strings.Split(key, "/")[0]
|
||||||
filename := sanitize.Path(strings.Split(key, "/")[1])
|
filename := sanitize.Path(strings.Split(key, "/")[1])
|
||||||
|
|
||||||
reader, _, _, err := storage.Get(token, filename)
|
reader, _, _, err := s.storage.Get(token, filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if storage.IsNotExist(err) {
|
if s.storage.IsNotExist(err) {
|
||||||
http.Error(w, "File not found", 404)
|
http.Error(w, "File not found", 404)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -467,9 +467,9 @@ func (s *Server) tarGzHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := strings.Split(key, "/")[0]
|
token := strings.Split(key, "/")[0]
|
||||||
filename := sanitize.Path(strings.Split(key, "/")[1])
|
filename := sanitize.Path(strings.Split(key, "/")[1])
|
||||||
|
|
||||||
reader, _, contentLength, err := storage.Get(token, filename)
|
reader, _, contentLength, err := s.storage.Get(token, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if storage.IsNotExist(err) {
|
if s.storage.IsNotExist(err) {
|
||||||
http.Error(w, "File not found", 404)
|
http.Error(w, "File not found", 404)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -519,9 +519,9 @@ func (s *Server) tarHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := strings.Split(key, "/")[0]
|
token := strings.Split(key, "/")[0]
|
||||||
filename := strings.Split(key, "/")[1]
|
filename := strings.Split(key, "/")[1]
|
||||||
|
|
||||||
reader, _, contentLength, err := storage.Get(token, filename)
|
reader, _, contentLength, err := s.storage.Get(token, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if storage.IsNotExist(err) {
|
if s.storage.IsNotExist(err) {
|
||||||
http.Error(w, "File not found", 404)
|
http.Error(w, "File not found", 404)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
@ -559,9 +559,9 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
token := vars["token"]
|
token := vars["token"]
|
||||||
filename := vars["filename"]
|
filename := vars["filename"]
|
||||||
|
|
||||||
reader, contentType, contentLength, err := storage.Get(token, filename)
|
reader, contentType, contentLength, err := s.storage.Get(token, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if storage.IsNotExist(err) {
|
if s.storage.IsNotExist(err) {
|
||||||
http.Error(w, "File not found", 404)
|
http.Error(w, "File not found", 404)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,8 +58,6 @@ const SERVER_INFO = "transfer.sh"
|
||||||
// parse request with maximum memory of _24Kilobits
|
// parse request with maximum memory of _24Kilobits
|
||||||
const _24K = (1 << 20) * 24
|
const _24K = (1 << 20) * 24
|
||||||
|
|
||||||
var storage Storage
|
|
||||||
|
|
||||||
type OptionFn func(*Server)
|
type OptionFn func(*Server)
|
||||||
|
|
||||||
func Listener(s string) OptionFn {
|
func Listener(s string) OptionFn {
|
||||||
|
|
Loading…
Reference in a new issue