refinement
This commit is contained in:
@ -32,6 +32,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -52,7 +53,6 @@ import (
|
|||||||
text_template "text/template"
|
text_template "text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"encoding/base64"
|
|
||||||
web "github.com/dutchcoders/transfer.sh-web"
|
web "github.com/dutchcoders/transfer.sh-web"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
@ -460,7 +460,7 @@ func (s *Server) postHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata := metadataForRequest(contentType, s.randomTokenLength, r)
|
metadata := metadataForRequest(contentType, contentLength, s.randomTokenLength, r)
|
||||||
|
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
|
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
|
||||||
@ -537,9 +537,10 @@ type metadata struct {
|
|||||||
DecryptedContentType string
|
DecryptedContentType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataForRequest(contentType string, randomTokenLength int, r *http.Request) metadata {
|
func metadataForRequest(contentType string, contentLength int64, randomTokenLength int, r *http.Request) metadata {
|
||||||
metadata := metadata{
|
metadata := metadata{
|
||||||
ContentType: strings.ToLower(contentType),
|
ContentType: strings.ToLower(contentType),
|
||||||
|
ContentLength: contentLength,
|
||||||
MaxDate: time.Time{},
|
MaxDate: time.Time{},
|
||||||
Downloads: 0,
|
Downloads: 0,
|
||||||
MaxDownloads: -1,
|
MaxDownloads: -1,
|
||||||
@ -639,7 +640,7 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
token := token(s.randomTokenLength)
|
token := token(s.randomTokenLength)
|
||||||
|
|
||||||
metadata := metadataForRequest(contentType, s.randomTokenLength, r)
|
metadata := metadataForRequest(contentType, contentLength, s.randomTokenLength, r)
|
||||||
|
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
|
if err := json.NewEncoder(buffer).Encode(metadata); err != nil {
|
||||||
@ -1095,6 +1096,7 @@ func (s *Server) headHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
metadata, err := s.checkMetadata(r.Context(), token, filename, false)
|
metadata, err := s.checkMetadata(r.Context(), token, filename, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Printf("Error metadata: %s", err.Error())
|
||||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1129,6 +1131,7 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
metadata, err := s.checkMetadata(r.Context(), token, filename, true)
|
metadata, err := s.checkMetadata(r.Context(), token, filename, true)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
s.logger.Printf("Error metadata: %s", err.Error())
|
||||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1147,9 +1150,9 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var disposition string
|
var disposition string
|
||||||
|
if action == "inline" {
|
||||||
disposition = action
|
disposition = "inline"
|
||||||
if action != "inline" {
|
} else {
|
||||||
disposition = "attachment"
|
disposition = "attachment"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user