From 0a90ff6439b7903788d72169212959cc95df1c10 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 17 May 2023 13:34:27 -0400 Subject: [PATCH] refactor: add terminateUpload method --- tus/tus.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tus/tus.go b/tus/tus.go index 7303788..eaca1f5 100644 --- a/tus/tus.go +++ b/tus/tus.go @@ -140,6 +140,10 @@ func tusWorker(upload *tusd.Upload) error { _, err = files.Upload(file.(io.ReadSeeker), info.Size) if err != nil { log.Print(err) + err1 := terminateUpload(*upload) + if err1 != nil { + return err1 + } return err } @@ -147,14 +151,29 @@ func tusWorker(upload *tusd.Upload) error { var tusUpload model.Tus ret := db.Get().Where(&model.Tus{Hash: hash}).First(&tusUpload) + if ret.Error != nil && ret.Error.Error() != "record not found" { log.Print(ret.Error) + err1 := terminateUpload(*upload) + if err1 != nil { + return err1 + } return err } ret = db.Get().Delete(&tusUpload) - err = shared.GetTusComposer().Terminater.AsTerminatableUpload(*upload).Terminate(context.Background()) + err = terminateUpload(*upload) + + if err != nil { + return err + } + + return nil +} + +func terminateUpload(upload tusd.Upload) error { + err := shared.GetTusComposer().Terminater.AsTerminatableUpload(upload).Terminate(context.Background()) if err != nil { log.Print(err)