Skip to content

Commit 09dd270

Browse files
committed
cleanup
1 parent 0141e50 commit 09dd270

2 files changed

Lines changed: 11 additions & 20 deletions

File tree

internal/turso/databases.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"github.com/tursodatabase/turso-cli/internal/prompt"
1616
)
1717

18+
const multipartUploadThresholdBytes = 100 * 1024 * 1024 // 100MB
19+
1820
type Database struct {
1921
ID string `json:"dbId" mapstructure:"dbId"`
2022
Name string
@@ -240,8 +242,13 @@ func (d *DatabasesClient) UploadDatabaseAWS(resp *CreateDatabaseResponse, group
240242
// Upload the database file
241243
spinner.Text(fmt.Sprintf("Uploading database %s in group %s, this may take a while...", internal.Emph(resp.Database.Name), internal.Emph(group)))
242244

243-
uploadFunc := tursoServerClient.UploadFile
244-
if useMultipart {
245+
stat, err := os.Stat(uploadFilepath)
246+
if err != nil {
247+
return nil, fmt.Errorf("failed to stat file %s: %w", uploadFilepath, err)
248+
}
249+
250+
uploadFunc := tursoServerClient.UploadFileSinglePart
251+
if useMultipart || stat.Size() > multipartUploadThresholdBytes {
245252
uploadFunc = tursoServerClient.UploadFileMultipart
246253
}
247254

internal/turso/tursoServer.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,10 @@ func NewTursoServerClient(baseURL *url.URL, token string, cliVersion string, org
5656
}, nil
5757
}
5858

59-
const multipartThresholdBytes = 100 * 1024 * 1024 // 100MB
60-
61-
// UploadFile uploads a file to the turso server
62-
func (i *TursoServerClient) UploadFile(filepath string, onUploadProgress func(progressPct int, uploadedBytes int64, totalBytes int64, elapsedTime time.Duration, done bool)) error {
63-
stat, err := os.Stat(filepath)
64-
if err != nil {
65-
return fmt.Errorf("failed to stat file %s: %w", filepath, err)
66-
}
67-
68-
if stat.Size() > multipartThresholdBytes {
69-
return i.UploadFileMultipart(filepath, onUploadProgress)
70-
}
71-
72-
return i.uploadFileSinglePart(filepath, onUploadProgress)
73-
}
74-
75-
// uploadFileSinglePart uploads a database file to the Turso server using a single request.
59+
// UploadFileSinglePart uploads a database file to the Turso server using a single request.
7660
// it assumes a SQLite file exists at 'filepath'.
7761
// it streams the file to the server, and calls the onProgress callback with the progress of the upload.
78-
func (i *TursoServerClient) uploadFileSinglePart(filepath string, onUploadProgress func(progressPct int, uploadedBytes int64, totalBytes int64, elapsedTime time.Duration, done bool)) error {
62+
func (i *TursoServerClient) UploadFileSinglePart(filepath string, onUploadProgress func(progressPct int, uploadedBytes int64, totalBytes int64, elapsedTime time.Duration, done bool)) error {
7963
file, err := os.Open(filepath)
8064
if err != nil {
8165
return fmt.Errorf("failed to open file %s: %w", filepath, err)

0 commit comments

Comments
 (0)