fix: if we have errors at the CreatedUploads hook, cancel the upload

This commit is contained in:
Derrick Hammer 2024-01-20 06:41:51 -05:00
parent af5b6241bf
commit 0ab70dcaa5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 0 deletions

View File

@ -318,6 +318,7 @@ func (s *StorageServiceImpl) tusWorker() {
select {
case info := <-s.tus.CreatedUploads:
hash, ok := info.Upload.MetaData["hash"]
errorResponse := tusd.HTTPResponse{StatusCode: 400, Header: nil}
if !ok {
s.portal.Logger().Error("Missing hash in metadata")
continue
@ -325,6 +326,8 @@ func (s *StorageServiceImpl) tusWorker() {
uploaderID, ok := info.Context.Value(middleware.S5AuthUserIDKey).(uint)
if !ok {
errorResponse.Body = "Missing user id in context"
info.Upload.StopUpload(errorResponse)
s.portal.Logger().Error("Missing user id in context")
continue
}
@ -334,12 +337,16 @@ func (s *StorageServiceImpl) tusWorker() {
decodedHash, err := encoding.MultihashFromBase64Url(hash)
if err != nil {
errorResponse.Body = "Could not decode hash"
info.Upload.StopUpload(errorResponse)
s.portal.Logger().Error("Could not decode hash", zap.Error(err))
continue
}
_, err = s.CreateTusUpload(decodedHash.HashBytes(), info.Upload.ID, uploaderID, uploaderIP, info.Context.Value("protocol").(string))
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))
continue
}