@@ -14,6 +14,7 @@ import (
1414
1515 "github.com/Clever/csvlint"
1616 "github.com/spf13/cobra"
17+ "github.com/tursodatabase/turso-cli/internal"
1718 "github.com/tursodatabase/turso-cli/internal/flags"
1819 "github.com/tursodatabase/turso-cli/internal/prompt"
1920 "github.com/tursodatabase/turso-cli/internal/turso"
@@ -191,6 +192,21 @@ func countFlags(flags ...string) (count int) {
191192}
192193
193194const MaxAWSDBSizeBytes = 1024 * 1024 * 1024 * 20 // 20 GB
195+ const OneGBBytes = 1024 * 1024 * 1024 // 1 GB
196+
197+ func humanReadableSize (bytes int64 ) string {
198+ const unit = 1024
199+ if bytes < unit {
200+ return fmt .Sprintf ("%d B" , bytes )
201+ }
202+ div , exp := int64 (unit ), 0
203+ for n := bytes / unit ; n >= unit ; n /= unit {
204+ div *= unit
205+ exp ++
206+ }
207+ return fmt .Sprintf ("%.1f %cB" , float64 (bytes )/ float64 (div ), "KMGTPE" [exp ])
208+ }
209+
194210func checkIfDump (filename string ) (bool , error ) {
195211 file , err := os .Open (filename )
196212 if err != nil {
@@ -278,6 +294,28 @@ func sqliteFileIntegrityChecks(file string, cipher string) error {
278294 return errors .New ("database file size exceeds maximum allowed size of 20 GB" )
279295 }
280296
297+ // Warn users about JWT expiration for large uploads
298+ if fileInfo .Size () > OneGBBytes {
299+ // Check if using JWT (not API token from env var)
300+ if os .Getenv (ENV_ACCESS_TOKEN ) == "" && ! yesFlag {
301+ fmt .Printf ("\n %s\n \n " , internal .Warn ("Warning: Large database upload detected" ))
302+ fmt .Printf ("You are uploading a %s database while authenticated with a JWT token.\n " , humanReadableSize (fileInfo .Size ()))
303+ fmt .Printf ("JWT tokens are short-lived and may expire during long transfers.\n \n " )
304+ fmt .Printf ("For large uploads, it's recommended to use an API token instead:\n " )
305+ fmt .Printf (" 1. Create an API token: %s\n " , internal .Emph ("turso auth api-tokens mint <token-name>" ))
306+ fmt .Printf (" 2. Set it as an environment variable: %s\n \n " , internal .Emph ("export TURSO_API_TOKEN=<your-token>" ))
307+
308+ ok , err := promptConfirmation ("Do you want to continue with the JWT token?" )
309+ if err != nil {
310+ return fmt .Errorf ("could not get confirmation: %w" , err )
311+ }
312+ if ! ok {
313+ return errors .New ("upload cancelled by user" )
314+ }
315+ fmt .Println ()
316+ }
317+ }
318+
281319 if flags .Debug () {
282320 log .Printf ("Checking database settings..." )
283321 }
0 commit comments