refactor: move tus record delete logic to terminateUpload and delete by tus upload id

This commit is contained in:
Derrick Hammer 2023-05-22 10:26:48 -04:00
parent 6ddef03790
commit 75e5838b01
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 20 additions and 24 deletions

View File

@ -148,32 +148,12 @@ func tusWorker(upload *tusd.Upload) error {
}
_, err = files.Upload(file.(io.ReadSeeker), info.Size)
if err != nil {
err1 := terminateUpload(*upload)
if err1 != nil {
return err1
}
return err
tErr := terminateUpload(*upload)
if tErr != nil {
return tErr
}
hash := info.MetaData[HASH_META_HEADER]
var tusUpload model.Tus
ret := db.Get().Where(&model.Tus{Hash: hash}).First(&tusUpload)
if ret.Error != nil && ret.Error.Error() != "record not found" {
shared.GetLogger().Error("failed fetching tus entry", zap.Error(err))
err1 := terminateUpload(*upload)
if err1 != nil {
return err1
}
return err
}
_ = db.Get().Delete(&tusUpload)
err = terminateUpload(*upload)
if err != nil {
return err
}
@ -182,10 +162,26 @@ func tusWorker(upload *tusd.Upload) error {
}
func terminateUpload(upload tusd.Upload) error {
info, _ := upload.GetInfo(context.Background())
err := shared.GetTusComposer().Terminater.AsTerminatableUpload(upload).Terminate(context.Background())
if err != nil {
shared.GetLogger().Error("failed deleting tus upload", zap.Error(err))
}
tusUpload := &model.Tus{Id: info.ID}
ret := db.Get().Where(tusUpload).First(&tusUpload)
if ret.Error != nil && ret.Error.Error() != "record not found" {
shared.GetLogger().Error("failed fetching tus entry", zap.Error(err))
err = ret.Error
}
err1 := db.Get().Where(&tusUpload).Delete(&tusUpload)
_ = err1
if err != nil {
return err
}