Refactoring for MP4 file handler

This commit is contained in:
Alexey Khit
2023-08-20 18:43:42 +03:00
parent 2ffd859f0e
commit 2091dead3f
+9 -9
View File
@@ -120,15 +120,6 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) {
return
}
defer stream.RemoveConsumer(cons)
header := w.Header()
header.Set("Content-Type", mp4.ContentType(cons.Codecs()))
if filename := query.Get("filename"); filename != "" {
header.Set("Content-Disposition", `attachment; filename="`+filename+`"`)
}
if rotate := query.Get("rotate"); rotate != "" {
cons.Rotate = core.Atoi(rotate)
}
@@ -140,6 +131,13 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) {
}
}
header := w.Header()
header.Set("Content-Type", mp4.ContentType(cons.Codecs()))
if filename := query.Get("filename"); filename != "" {
header.Set("Content-Disposition", `attachment; filename="`+filename+`"`)
}
var duration *time.Timer
if s := query.Get("duration"); s != "" {
if i, _ := strconv.Atoi(s); i > 0 {
@@ -151,6 +149,8 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) {
_, _ = cons.WriteTo(w)
stream.RemoveConsumer(cons)
if duration != nil {
duration.Stop()
}