summaryrefslogtreecommitdiff
path: root/app/app.go
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2020-03-21 22:58:14 +1000
committerJames Mills <prologic@shortcircuit.net.au>2020-03-21 22:58:14 +1000
commitce3008222e924902352d697b45626aebd8980af1 (patch)
tree7f621a3e8155287ffeab3f240b0b9e810355bda1 /app/app.go
parentcf096b9a1610e1a97075206250537346d5467bfb (diff)
Refactor video uploading in preparation for async transcoding
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/app/app.go b/app/app.go
index 11bfb45..a32b900 100644
--- a/app/app.go
+++ b/app/app.go
@@ -14,6 +14,7 @@ import (
rice "github.com/GeertJohan/go.rice"
"github.com/fsnotify/fsnotify"
"github.com/gorilla/mux"
+ "github.com/renstrom/shortuuid"
log "github.com/sirupsen/logrus"
"github.com/wybiral/tube/media"
)
@@ -161,11 +162,9 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
- // TODO: Allow the user to pick this and don't hard code it.
- collection := "videos"
- fn := filepath.Join(collection, handler.Filename)
+ fn := filepath.Join("uploads", fmt.Sprintf("%s%s", shortuuid.New(), filepath.Ext(handler.Filename)))
- f, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0755)
+ f, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
err := fmt.Errorf("error opening file for writing: %w", err)
log.Error(err)
@@ -184,7 +183,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
a.Library.Add(fn)
- fmt.Fprintf(w, "Successfully uploaded video: %s", handler.Filename)
+ fmt.Fprintf(w, "Video successfully uploaded! It will be available shortly...")
} else {
http.Error(w, "Method Not Allowed", http.StatusMethodNotAllowed)
}