@@ -26,11 +26,21 @@ import (
2626
2727 "github.com/charmbracelet/bubbles/key"
2828 "github.com/charmbracelet/huh"
29+ "github.com/rusq/osenv/v2"
2930 "github.com/rusq/slackauth"
3031
3132 "github.com/rusq/slackdump/v4/internal/structures"
3233)
3334
35+ const (
36+ defQRCodeSz = 9000 // default limit for encoded image size, seen values 6174, 8462
37+ maxQRCodeSz = 1 << 16 - 1 // maximum allowed QR code image size.
38+ imgPrefix = "data:image/png;base64,"
39+ )
40+
41+ // limQRCodeSz is the size of the input field for QR Code image.
42+ var limQRCodeSz = osenv .Value ("QR_CODE_SIZE" , defQRCodeSz )
43+
3444// Huh is the Auth UI that uses the huh library to provide a terminal UI.
3545type Huh struct {}
3646
@@ -250,21 +260,17 @@ func valSixDigits(s string) error {
250260 return nil
251261}
252262
253- const (
254- maxEncImgSz = 7000
255- imgPrefix = "data:image/png;base64,"
256- )
257-
258263func (* Huh ) RequestQR (ctx context.Context , _ io.Writer ) (string , error ) {
259264 const description = `In logged in Slack Client or Web:
260265 1. click the username in the upper left corner;
261266 2. choose 'Sign in on mobile';
262267 3. right-click the QR code image;
263268 4. choose Copy Image.`
269+
264270 var imageData string
265271 q := huh .NewForm (huh .NewGroup (
266272 huh .NewText ().
267- CharLimit (maxEncImgSz ).
273+ CharLimit (qrCharLimit () ).
268274 Value (& imageData ).
269275 Validate (func (s string ) error {
270276 if ! strings .HasPrefix (s , imgPrefix ) {
@@ -281,3 +287,12 @@ func (*Huh) RequestQR(ctx context.Context, _ io.Writer) (string, error) {
281287 }
282288 return imageData , nil
283289}
290+
291+ // qrCharLimit returns the effective character limit for the QR code input
292+ // field.
293+ func qrCharLimit () int {
294+ if defQRCodeSz <= limQRCodeSz && limQRCodeSz <= maxQRCodeSz {
295+ return limQRCodeSz
296+ }
297+ return defQRCodeSz
298+ }
0 commit comments