fix: if we have errors at the CreatedUploads hook, cancel the upload
This commit is contained in:
parent
af5b6241bf
commit
0ab70dcaa5
|
@ -318,6 +318,7 @@ func (s *StorageServiceImpl) tusWorker() {
|
||||||
select {
|
select {
|
||||||
case info := <-s.tus.CreatedUploads:
|
case info := <-s.tus.CreatedUploads:
|
||||||
hash, ok := info.Upload.MetaData["hash"]
|
hash, ok := info.Upload.MetaData["hash"]
|
||||||
|
errorResponse := tusd.HTTPResponse{StatusCode: 400, Header: nil}
|
||||||
if !ok {
|
if !ok {
|
||||||
s.portal.Logger().Error("Missing hash in metadata")
|
s.portal.Logger().Error("Missing hash in metadata")
|
||||||
continue
|
continue
|
||||||
|
@ -325,6 +326,8 @@ func (s *StorageServiceImpl) tusWorker() {
|
||||||
|
|
||||||
uploaderID, ok := info.Context.Value(middleware.S5AuthUserIDKey).(uint)
|
uploaderID, ok := info.Context.Value(middleware.S5AuthUserIDKey).(uint)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
errorResponse.Body = "Missing user id in context"
|
||||||
|
info.Upload.StopUpload(errorResponse)
|
||||||
s.portal.Logger().Error("Missing user id in context")
|
s.portal.Logger().Error("Missing user id in context")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -334,12 +337,16 @@ func (s *StorageServiceImpl) tusWorker() {
|
||||||
decodedHash, err := encoding.MultihashFromBase64Url(hash)
|
decodedHash, err := encoding.MultihashFromBase64Url(hash)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errorResponse.Body = "Could not decode hash"
|
||||||
|
info.Upload.StopUpload(errorResponse)
|
||||||
s.portal.Logger().Error("Could not decode hash", zap.Error(err))
|
s.portal.Logger().Error("Could not decode hash", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.CreateTusUpload(decodedHash.HashBytes(), info.Upload.ID, uploaderID, uploaderIP, info.Context.Value("protocol").(string))
|
_, err = s.CreateTusUpload(decodedHash.HashBytes(), info.Upload.ID, uploaderID, uploaderIP, info.Context.Value("protocol").(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
errorResponse.Body = "Could not create tus upload"
|
||||||
|
info.Upload.StopUpload(errorResponse)
|
||||||
s.portal.Logger().Error("Could not create tus upload", zap.Error(err))
|
s.portal.Logger().Error("Could not create tus upload", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue