diff --git a/api/handlers/cards.go b/api/handlers/cards.go index 89ad643..cca2905 100644 --- a/api/handlers/cards.go +++ b/api/handlers/cards.go @@ -31,7 +31,7 @@ var ( ) func storeRedirect(stripeURL string) string { - b := make([]byte, 4) + b := make([]byte, 16) rand.Read(b) token := hex.EncodeToString(b) payRedirectsMu.Lock() diff --git a/api/middleware/ratelimit.go b/api/middleware/ratelimit.go index 0adcef9..65659f1 100644 --- a/api/middleware/ratelimit.go +++ b/api/middleware/ratelimit.go @@ -4,6 +4,8 @@ import ( "net/http" "time" + "strconv" + "github.com/go-chi/httprate" "terminalShop/pkg/utils" ) @@ -29,7 +31,7 @@ func RateLimitByUser(limit int, window time.Duration) func(http.Handler) http.Ha // Fall back to IP if no user context (shouldn't happen on protected routes). return httprate.KeyByIP(r) } - return http.CanonicalHeaderKey("user") + ":" + string(rune(userID)), nil + return "user:" + strconv.FormatUint(uint64(userID), 10), nil }), httprate.WithLimitHandler(func(w http.ResponseWriter, r *http.Request) { utils.RespondError(w, http.StatusTooManyRequests, "RATE_LIMITED", "too many requests", nil) diff --git a/pkg/api/client.go b/pkg/api/client.go index 2b440e7..8f6e55f 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -594,7 +594,7 @@ func (c *Client) CollectCard() (string, error) { var collectResp CollectCardResponse if err := json.NewDecoder(resp.Body).Decode(&collectResp); err != nil { - return "", fmt.Errorf("failed to devode collect response: %w", err) + return "", fmt.Errorf("failed to decode collect response: %w", err) } if !collectResp.Success { diff --git a/pkg/tui/model.go b/pkg/tui/model.go index cef88f8..2e6e5b7 100644 --- a/pkg/tui/model.go +++ b/pkg/tui/model.go @@ -29,7 +29,7 @@ const ( large // viewportWidth >= 80 ) -// page represetnts the currently active TUI screen +// page represents the currently active TUI screen type page int const ( @@ -62,7 +62,7 @@ type Model struct { StripePublicKey string // One-shop auth command - capture pubKeyStr in closure, not stored on Model - autchCmd tea.Cmd + authCmd tea.Cmd // Shared data Username string @@ -342,7 +342,7 @@ func (m Model) fetchProductsCmd() tea.Msg { func (m Model) Init() tea.Cmd { return tea.Batch( - m.autchCmd, + m.authCmd, tea.Tick(1500*time.Millisecond, func(t time.Time) tea.Msg { return DelayCompleteMsg{} }), @@ -845,7 +845,7 @@ func NewModelWithAuth(renderer *lipgloss.Renderer, fingerprint string, pubKeyStr m.APIClient = api.NewClient("http://localhost:8000", "") } - m.autchCmd = func() tea.Msg { + m.authCmd = func() tea.Msg { token, user, err := m.APIClient.GetOrCreateToken( fingerprint, pubKeyStr, diff --git a/pkg/tui/splash.go b/pkg/tui/splash.go index 5770bef..00a0441 100644 --- a/pkg/tui/splash.go +++ b/pkg/tui/splash.go @@ -42,7 +42,7 @@ func (m Model) SplashView() string { cursor = " " } - logo := accent.Render("terminal coffe") + cursor + logo := accent.Render("terminal coffee") + cursor content := lipgloss.JoinVertical( lipgloss.Center, diff --git a/pkg/tui/views.go b/pkg/tui/views.go index 2876066..5e2f7c1 100644 --- a/pkg/tui/views.go +++ b/pkg/tui/views.go @@ -129,11 +129,11 @@ func (m Model) View() string { child = lipgloss.JoinVertical(lipgloss.Left, header, content, footer) } } else if breadcrumbs != "" { - ccontentWithPadding := lipgloss.NewStyle().MarginTop(marginTop).MarginBottom(marginBottom).Height(availableContentHeight).Render(content) - child = lipgloss.JoinVertical(lipgloss.Left, header, breadcrumbs, ccontentWithPadding, footer) + contentWithPadding := lipgloss.NewStyle().MarginTop(marginTop).MarginBottom(marginBottom).Height(availableContentHeight).Render(content) + child = lipgloss.JoinVertical(lipgloss.Left, header, breadcrumbs, contentWithPadding, footer) } else { - ccontentWithPadding := lipgloss.NewStyle().MarginTop(marginTop).MarginBottom(marginBottom).Height(availableContentHeight).Render(content) - child = lipgloss.JoinVertical(lipgloss.Left, header, ccontentWithPadding, footer) + contentWithPadding := lipgloss.NewStyle().MarginTop(marginTop).MarginBottom(marginBottom).Height(availableContentHeight).Render(content) + child = lipgloss.JoinVertical(lipgloss.Left, header, contentWithPadding, footer) } // Constrain the assembled layout to the container dimensions