Refactor video uploading in preparation for async transcoding
This commit is contained in:
parent
cf096b9a16
commit
ce3008222e
6 changed files with 18 additions and 6 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,3 +8,6 @@
|
|||
|
||||
videos/*
|
||||
!videos/README.md
|
||||
|
||||
uploads/*
|
||||
!uploads/README.md
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -6,11 +6,14 @@ require (
|
|||
github.com/GeertJohan/go.rice v1.0.0
|
||||
github.com/dhowden/tag v0.0.0-20190519100835-db0c67e351b1
|
||||
github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/gorilla/mux v1.7.2
|
||||
github.com/renstrom/shortuuid v3.0.0+incompatible
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/wybiral/feeds v1.1.1
|
||||
github.com/xfrr/goffmpeg v0.0.0-20191120110122-53b0a69281d4
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7
|
||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
|
||||
|
|
6
go.sum
6
go.sum
|
@ -11,6 +11,8 @@ github.com/dhowden/tag v0.0.0-20190519100835-db0c67e351b1 h1:HR8W6GvuS20j4kNxa/X
|
|||
github.com/dhowden/tag v0.0.0-20190519100835-db0c67e351b1/go.mod h1:SniNVYuaD1jmdEEvi+7ywb1QFR7agjeTdGKyFb0p7Rw=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
|
||||
github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I=
|
||||
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
|
@ -20,6 +22,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
|
|||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
|
||||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/renstrom/shortuuid v3.0.0+incompatible h1:F6T1U7bWlI3FTV+JE8HyeR7bkTeYZJntqQLA9ST4HOQ=
|
||||
github.com/renstrom/shortuuid v3.0.0+incompatible/go.mod h1:n18Ycpn8DijG+h/lLBQVnGKv1BCtTeXo8KKSbBOrQ8c=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
|
@ -34,6 +38,8 @@ github.com/wybiral/feeds v1.1.1 h1:KWE/JxA2XfP0My+C0wymqXrWK5oIyjRVbH5kpclsea0=
|
|||
github.com/wybiral/feeds v1.1.1/go.mod h1:MRSqtY+Oy5HMM51cF212xqU39MYbsYq/AH+PY8IfeM0=
|
||||
github.com/wybiral/torgo v0.0.0-20190413024533-a19a6c8a5048 h1:HQmSLHtGgSARs7VYzAID703qM/5m1il3X7f9AHfg/9c=
|
||||
github.com/wybiral/torgo v0.0.0-20190413024533-a19a6c8a5048/go.mod h1:LAhGyZRjuXZ/+uO4tqc5QV26hkdIo+yGHPfX1aubR0M=
|
||||
github.com/xfrr/goffmpeg v0.0.0-20191120110122-53b0a69281d4 h1:iuT6IHMZMFQ8vZ67/a+v2kZ94PdK3o612FILXtnYBao=
|
||||
github.com/xfrr/goffmpeg v0.0.0-20191120110122-53b0a69281d4/go.mod h1:mL+qPvJWwu9An5a66+HyEJ7X7iEUSI09zX/Xl67XRXs=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
|
|
2
main.go
2
main.go
|
@ -36,7 +36,7 @@ func main() {
|
|||
}
|
||||
|
||||
if version {
|
||||
fmt.Printf("ed version %s", FullVersion())
|
||||
fmt.Printf("tube version %s", FullVersion())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
1
uploads/README.md
Normal file
1
uploads/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Videos uploads go here.
|
Loading…
Reference in a new issue