mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-11-27 06:30:19 +01:00
purge time in ui, fix range regeression from videojs
This commit is contained in:
parent
e9148e0c20
commit
9baefbc4bf
1 changed files with 32 additions and 28 deletions
|
@ -238,16 +238,27 @@ func (s *Server) viewHandler(w http.ResponseWriter, r *http.Request) {
|
|||
hostname := getURL(r, s.proxyPort).Host
|
||||
webAddress := resolveWebAddress(r, s.proxyPath, s.proxyPort)
|
||||
|
||||
purgeTime := ""
|
||||
if s.purgeDays > 0 {
|
||||
purgeTime = s.purgeDays.String()
|
||||
}
|
||||
|
||||
data := struct {
|
||||
Hostname string
|
||||
WebAddress string
|
||||
GAKey string
|
||||
UserVoiceKey string
|
||||
PurgeTime string
|
||||
SampleToken string
|
||||
SampleToken2 string
|
||||
}{
|
||||
hostname,
|
||||
webAddress,
|
||||
s.gaKey,
|
||||
s.userVoiceKey,
|
||||
purgeTime,
|
||||
Token(s.randomTokenLength),
|
||||
Token(s.randomTokenLength),
|
||||
}
|
||||
|
||||
if acceptsHTML(r.Header) {
|
||||
|
@ -1025,16 +1036,7 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||
reader = ioutil.NopCloser(bluemonday.UGCPolicy().SanitizeReader(reader))
|
||||
}
|
||||
|
||||
if w.Header().Get("Range") == "" {
|
||||
if _, err = io.Copy(w, reader); err != nil {
|
||||
s.logger.Printf("%s", err.Error())
|
||||
http.Error(w, "Error occurred copying to output stream", 500)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if w.Header().Get("Range") != "" || strings.HasPrefix(metadata.ContentType, "video") || strings.HasPrefix(metadata.ContentType, "audio") {
|
||||
file, err := ioutil.TempFile(s.tempPath, "range-")
|
||||
if err != nil {
|
||||
s.logger.Printf("%s", err.Error())
|
||||
|
@ -1044,22 +1046,24 @@ func (s *Server) getHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
defer s.cleanTmpFile(file)
|
||||
|
||||
tee := io.TeeReader(reader, file)
|
||||
for {
|
||||
b := make([]byte, _5M)
|
||||
_, err = tee.Read(b)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, reader)
|
||||
if err != nil {
|
||||
s.logger.Printf("%s", err.Error())
|
||||
http.Error(w, "Error occurred copying to output stream", 500)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
http.ServeContent(w, r, filename, time.Now(), file)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = io.Copy(w, reader); err != nil {
|
||||
s.logger.Printf("%s", err.Error())
|
||||
http.Error(w, "Error occurred copying to output stream", 500)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Server) RedirectHandler(h http.Handler) http.HandlerFunc {
|
||||
|
|
Loading…
Reference in a new issue