diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index 517a9462..3d6f9833 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -2437,22 +2437,6 @@ func PurgeHistoryByIds(ctx context.Context, historyIds []string) ([]*HistoryItem }) } -func CanScreenWebShare(screen *ScreenType) error { - if screen == nil { - return fmt.Errorf("cannot share screen, not found") - } - if screen.ShareMode == ShareModeWeb { - return fmt.Errorf("screen is already shared to web") - } - if screen.ShareMode != ShareModeLocal { - return fmt.Errorf("screen cannot be shared, invalid current share mode %q (must be local)", screen.ShareMode) - } - if screen.Archived { - return fmt.Errorf("screen cannot be shared, must un-archive before sharing") - } - return nil -} - func ScreenWebShareStart(ctx context.Context, screenId string, shareOpts ScreenWebShareOpts) error { return WithTx(ctx, func(tx *TxWrap) error { query := `SELECT screenid FROM screen WHERE screenid = ?` @@ -2466,6 +2450,12 @@ func ScreenWebShareStart(ctx context.Context, screenId string, shareOpts ScreenW if shareMode != ShareModeLocal { return fmt.Errorf("screen cannot be shared, invalid current share mode %q (must be local)", shareMode) } + query = `SELECT count(*) FROM line WHERE screenid = ? AND NOT archived` + lineCount := tx.GetInt(query, screenId) + if lineCount > MaxWebShareLineCount { + return fmt.Errorf("screen cannot be shared, limited to a maximum of %d lines", MaxWebShareLineCount) + go UpdateCurrentActivity(context.Background(), ActivityUpdate{WebShareLimit: 1}) + } query = `UPDATE screen SET sharemode = ?, webshareopts = ? WHERE screenid = ?` tx.Exec(query, ShareModeWeb, quickJson(shareOpts), screenId) insertScreenNewUpdate(tx, screenId) diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index 825ccc15..70df6358 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -33,6 +33,7 @@ const LineTypeText = "text" const LineNoHeight = -1 const DBFileName = "prompt.db" const DBFileNameBackup = "backup.prompt.db" +const MaxWebShareLineCount = 50 const DefaultSessionName = "default" const LocalRemoteAlias = "local" @@ -177,6 +178,7 @@ type ActivityUpdate struct { HistoryView int BookmarksView int NumConns int + WebShareLimit int BuildTime string } @@ -201,6 +203,7 @@ type TelemetryData struct { HistoryView int `json:"historyview,omitempty"` BookmarksView int `json:"bookmarksview,omitempty"` NumConns int `json:"numconns"` + WebShareLimit int `json:"websharelimit,omitempty"` } func (tdata TelemetryData) Value() (driver.Value, error) {