refactor: remove tus out of method names

This commit is contained in:
Derrick Hammer 2024-02-16 22:03:34 -05:00
parent 93e727ab3b
commit c468a81543
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 14 additions and 14 deletions

View File

@ -111,7 +111,7 @@ func (f *S5File) Close() error {
func (f *S5File) init(offset int64) error { func (f *S5File) init(offset int64) error {
if f.reader == nil { if f.reader == nil {
reader, err := f.tus.GetTusUploadReader(f.hash, offset) reader, err := f.tus.GetUploadReader(f.hash, offset)
if err == nil { if err == nil {
f.reader = reader f.reader = reader

View File

@ -232,7 +232,7 @@ func (s S5ProviderStore) CanProvide(hash *encoding.Multihash, kind []types.Stora
case types.StorageLocationTypeArchive, types.StorageLocationTypeFile, types.StorageLocationTypeFull: case types.StorageLocationTypeArchive, types.StorageLocationTypeFile, types.StorageLocationTypeFull:
rawHash := hash.HashBytes() rawHash := hash.HashBytes()
if exists, upload := s.tus.TusUploadExists(rawHash); exists { if exists, upload := s.tus.UploadExists(rawHash); exists {
if upload.Completed { if upload.Completed {
return true return true
} }

View File

@ -102,7 +102,7 @@ func (t *TusHandler) Init() error {
return blankResp, blankChanges, errors.New("file already exists") return blankResp, blankChanges, errors.New("file already exists")
} }
exists, _ := t.TusUploadExists(decodedHash.HashBytes()) exists, _ := t.UploadExists(decodedHash.HashBytes())
if exists { if exists {
return blankResp, blankChanges, errors.New("file is already being uploaded") return blankResp, blankChanges, errors.New("file is already being uploaded")
@ -175,7 +175,7 @@ func (t *TusHandler) Tus() *tusd.Handler {
return t.tus return t.tus
} }
func (t *TusHandler) TusUploadExists(hash []byte) (bool, models.TusUpload) { func (t *TusHandler) UploadExists(hash []byte) (bool, models.TusUpload) {
hashStr := hex.EncodeToString(hash) hashStr := hex.EncodeToString(hash)
var upload models.TusUpload var upload models.TusUpload
@ -184,7 +184,7 @@ func (t *TusHandler) TusUploadExists(hash []byte) (bool, models.TusUpload) {
return result.RowsAffected > 0, upload return result.RowsAffected > 0, upload
} }
func (t *TusHandler) CreateTusUpload(hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) { func (t *TusHandler) CreateUpload(hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) {
hashStr := hex.EncodeToString(hash) hashStr := hex.EncodeToString(hash)
upload := &models.TusUpload{ upload := &models.TusUpload{
@ -204,7 +204,7 @@ func (t *TusHandler) CreateTusUpload(hash []byte, uploadID string, uploaderID ui
return upload, nil return upload, nil
} }
func (t *TusHandler) TusUploadProgress(uploadID string) error { func (t *TusHandler) UploadProgress(uploadID string) error {
find := &models.TusUpload{UploadID: uploadID} find := &models.TusUpload{UploadID: uploadID}
@ -223,7 +223,7 @@ func (t *TusHandler) TusUploadProgress(uploadID string) error {
return nil return nil
} }
func (t *TusHandler) TusUploadCompleted(uploadID string) error { func (t *TusHandler) UploadCompleted(uploadID string) error {
find := &models.TusUpload{UploadID: uploadID} find := &models.TusUpload{UploadID: uploadID}
@ -238,7 +238,7 @@ func (t *TusHandler) TusUploadCompleted(uploadID string) error {
return nil return nil
} }
func (t *TusHandler) DeleteTusUpload(uploadID string) error { func (t *TusHandler) DeleteUpload(uploadID string) error {
result := t.db.Where(&models.TusUpload{UploadID: uploadID}).Delete(&models.TusUpload{}) result := t.db.Where(&models.TusUpload{UploadID: uploadID}).Delete(&models.TusUpload{})
if result.Error != nil { if result.Error != nil {
@ -248,7 +248,7 @@ func (t *TusHandler) DeleteTusUpload(uploadID string) error {
return nil return nil
} }
func (t *TusHandler) ScheduleTusUpload(uploadID string) error { func (t *TusHandler) ScheduleUpload(uploadID string) error {
find := &models.TusUpload{UploadID: uploadID} find := &models.TusUpload{UploadID: uploadID}
var upload models.TusUpload var upload models.TusUpload
@ -260,13 +260,13 @@ func (t *TusHandler) ScheduleTusUpload(uploadID string) error {
task := t.cron.RetryableTask(cron.RetryableTaskParams{ task := t.cron.RetryableTask(cron.RetryableTaskParams{
Name: "tusUpload", Name: "tusUpload",
Function: t.tusUploadTask, Function: t.uploadTask,
Args: []interface{}{&upload}, Args: []interface{}{&upload},
Attempt: 0, Attempt: 0,
Limit: 0, Limit: 0,
After: func(jobID uuid.UUID, jobName string) { After: func(jobID uuid.UUID, jobName string) {
t.logger.Info("Job finished", zap.String("jobName", jobName), zap.String("uploadID", uploadID)) t.logger.Info("Job finished", zap.String("jobName", jobName), zap.String("uploadID", uploadID))
err := t.DeleteTusUpload(uploadID) err := t.DeleteUpload(uploadID)
if err != nil { if err != nil {
t.logger.Error("Error deleting tus upload", zap.Error(err)) t.logger.Error("Error deleting tus upload", zap.Error(err))
} }
@ -281,9 +281,9 @@ func (t *TusHandler) ScheduleTusUpload(uploadID string) error {
return nil return nil
} }
func (t *TusHandler) GetTusUploadReader(hash []byte, start int64) (io.ReadCloser, error) { func (t *TusHandler) GetUploadReader(hash []byte, start int64) (io.ReadCloser, error) {
ctx := context.Background() ctx := context.Background()
exists, upload := t.TusUploadExists(hash) exists, upload := t.UploadExists(hash)
if !exists { if !exists {
return nil, metadata.ErrNotFound return nil, metadata.ErrNotFound
@ -313,7 +313,7 @@ func (t *TusHandler) GetTusUploadReader(hash []byte, start int64) (io.ReadCloser
return reader, nil return reader, nil
} }
func (t *TusHandler) tusUploadTask(upload *models.TusUpload) error { func (t *TusHandler) uploadTask(upload *models.TusUpload) error {
ctx := context.Background() ctx := context.Background()
tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID) tusUpload, err := t.tusStore.GetUpload(ctx, upload.UploadID)
if err != nil { if err != nil {