Remove use of temporary file
This commit is contained in:
parent
06b7ddf175
commit
2dced8e3ce
2 changed files with 52 additions and 69 deletions
21
app/app.go
21
app/app.go
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -201,15 +200,6 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tf, err := ioutil.TempFile("", "tube-upload-*.mp4")
|
|
||||||
if err != nil {
|
|
||||||
err := fmt.Errorf("error creating tempory file: %w", err)
|
|
||||||
log.Error(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer os.Remove(tf.Name())
|
|
||||||
|
|
||||||
of := filepath.Join(
|
of := filepath.Join(
|
||||||
a.Library.Paths[collection].Path,
|
a.Library.Paths[collection].Path,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
|
@ -229,7 +219,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
"-acodec", "aac",
|
"-acodec", "aac",
|
||||||
"-strict", "-2",
|
"-strict", "-2",
|
||||||
"-loglevel", "quiet",
|
"-loglevel", "quiet",
|
||||||
tf.Name(),
|
of,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
err := fmt.Errorf("error transcoding video: %w", err)
|
err := fmt.Errorf("error transcoding video: %w", err)
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -237,15 +227,8 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Rename(tf.Name(), of); err != nil {
|
|
||||||
err := fmt.Errorf("error renaming temporary file to output file: %w", err)
|
|
||||||
log.Error(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.Remove(fn); err != nil {
|
if err := os.Remove(fn); err != nil {
|
||||||
err := fmt.Errorf("error removing file: %w", err)
|
err := fmt.Errorf("error removing uploaded file: %w", err)
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
100
app/rice-box.go
100
app/rice-box.go
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue