Skip to content

Commit 9bc035c

Browse files
committed
use tus uploader from go-putio pkg
1 parent 245d388 commit 9bc035c

File tree

6 files changed

+8
-187
lines changed

6 files changed

+8
-187
lines changed

cmd/putio-sync/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var (
2828
date = ""
2929
)
3030

31-
// TODO Move Uploader inside go-putio pkg
3231
// TODO Watch fs events for uploading files larger than 4M
3332
// TODO Watch fs events in local root
3433
// TODO Watch remote file events

internal/auth/auth.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ const (
2525

2626
var ErrInvalidCredentials = errors.New("invalid credentials")
2727

28-
func Authenticate(ctx context.Context, httpClient *http.Client, timeout time.Duration, username, password string) (token string, client *putio.Client, err error) {
28+
func Authenticate(ctx context.Context, httpClient *http.Client, timeout time.Duration, username, password string) (client *putio.Client, err error) {
2929
if strings.HasPrefix(password, "token/") {
3030
// User may use a token instead of password.
3131
log.Infof("Validating authentication token")
32-
token = password[6:]
32+
token := password[6:]
3333
client = newClient(ctx, httpClient, token)
3434
authCtx, cancel := context.WithTimeout(ctx, timeout)
3535
defer cancel()
@@ -89,8 +89,7 @@ func Authenticate(ctx context.Context, httpClient *http.Client, timeout time.Dur
8989
return
9090
}
9191

92-
token = tokenResponse.AccessToken
93-
client = newClient(ctx, httpClient, token)
92+
client = newClient(ctx, httpClient, tokenResponse.AccessToken)
9493
return
9594
}
9695

internal/tus/tus.go

Lines changed: 0 additions & 172 deletions
This file was deleted.

job_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (j *deleteStateJob) Run(ctx context.Context) error {
2626
}
2727
}
2828
if j.state.UploadURL != "" {
29-
err := uploader.TerminateUpload(ctx, j.state.UploadURL)
29+
err := client.Upload.TerminateUpload(ctx, j.state.UploadURL)
3030
if err != nil {
3131
log.Errorln("cannot remove upload:", err.Error())
3232
}

job_upload.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (d *uploadJob) tryResume(ctx context.Context) bool {
3737
if d.state.LocalInode != in {
3838
return false
3939
}
40-
offset, err := uploader.GetOffset(ctx, d.state.UploadURL)
40+
offset, err := client.Upload.GetOffset(ctx, d.state.UploadURL)
4141
if err != nil {
4242
return false
4343
}
@@ -57,7 +57,7 @@ func (d *uploadJob) Run(ctx context.Context) error {
5757
if err != nil {
5858
return err
5959
}
60-
location, err := uploader.CreateUpload(ctx, filename, parentID, d.localFile.Info().Size())
60+
location, err := client.Upload.CreateUpload(ctx, filename, parentID, d.localFile.Info().Size())
6161
if err != nil {
6262
return err
6363
}
@@ -84,7 +84,7 @@ func (d *uploadJob) Run(ctx context.Context) error {
8484
}
8585
pr := progress.New(f, d.state.Offset, d.state.Size, d.String())
8686
pr.Start()
87-
fileID, crc32, err := uploader.SendFile(ctx, pr, d.state.UploadURL, d.state.Offset)
87+
fileID, crc32, err := client.Upload.SendFile(ctx, pr, d.state.UploadURL, d.state.Offset)
8888
pr.Stop()
8989
if err != nil {
9090
return err

sync.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/putdotio/putio-sync/v2/internal/auth"
1414
"github.com/putdotio/putio-sync/v2/internal/dircache"
1515
"github.com/putdotio/putio-sync/v2/internal/tmpdir"
16-
"github.com/putdotio/putio-sync/v2/internal/tus"
1716
"github.com/putdotio/putio-sync/v2/internal/walker"
1817
"go.etcd.io/bbolt"
1918
)
@@ -29,13 +28,11 @@ var ErrInvalidCredentials = errors.New("invalid credentials")
2928
var (
3029
cfg Config
3130
db *bbolt.DB
32-
token string
3331
client *putio.Client
3432
localPath string
3533
remoteFolderID int64
3634
dirCache *dircache.DirCache
3735
tempDirPath string
38-
uploader *tus.Uploader
3936
syncing bool
4037
syncStatus = "Starting sync..."
4138
)
@@ -107,7 +104,7 @@ REPEAT_LOOP:
107104

108105
func syncOnce(ctx context.Context) error {
109106
var err error
110-
token, client, err = auth.Authenticate(ctx, httpClient, defaultTimeout, cfg.Username, cfg.Password)
107+
client, err = auth.Authenticate(ctx, httpClient, defaultTimeout, cfg.Username, cfg.Password)
111108
if err != nil {
112109
return err
113110
}
@@ -120,8 +117,6 @@ func syncOnce(ctx context.Context) error {
120117
return err
121118
}
122119
dirCache = dircache.New(client, defaultTimeout, remoteFolderID)
123-
uploader = tus.NewUploader(httpClient, defaultTimeout, token)
124-
125120
return syncRoots(ctx)
126121
}
127122

0 commit comments

Comments
 (0)