v0.9.3 db and web fixes for deployment

This commit is contained in:
2026-02-28 01:37:40 -05:00
parent 16fc069a8f
commit f82091a9bd
8 changed files with 72 additions and 41 deletions

View File

@ -1,6 +1,7 @@
package service
import (
"errors"
"fmt"
"strings"
"time"
@ -11,6 +12,12 @@ import (
"github.com/lixenwraith/auth"
)
var (
ErrStorageDisabled = errors.New("storage disabled")
ErrAtCapacity = errors.New("at capacity")
ErrPermanentSlotsFull = errors.New("permanent slots full")
)
// User represents a registered user account
type User struct {
UserID string
@ -24,13 +31,13 @@ type User struct {
// CreateUser creates new user with registration limits enforcement
func (s *Service) CreateUser(username, email, password string, permanent bool) (*User, error) {
if s.store == nil {
return nil, fmt.Errorf("storage disabled")
return nil, ErrStorageDisabled
}
// Check registration limits
total, permCount, _, err := s.store.GetUserCounts()
if err != nil {
return nil, fmt.Errorf("failed to check user limits: %w", err)
return nil, fmt.Errorf("failed to get user count: %w", err)
}
// Determine account type
@ -39,7 +46,7 @@ func (s *Service) CreateUser(username, email, password string, permanent bool) (
if permanent {
if permCount >= PermanentSlots {
return nil, fmt.Errorf("permanent user slots full (%d/%d)", permCount, PermanentSlots)
return nil, fmt.Errorf("%w (%d/%d)", ErrPermanentSlotsFull, permCount, PermanentSlots)
}
accountType = "permanent"
} else {
@ -50,7 +57,7 @@ func (s *Service) CreateUser(username, email, password string, permanent bool) (
// Handle capacity - remove oldest temp user if at max
if total >= MaxUsers {
if err := s.removeOldestTempUser(); err != nil {
return nil, fmt.Errorf("at capacity and cannot make room: %w", err)
return nil, fmt.Errorf("%w: %v", ErrAtCapacity, err)
}
}
@ -275,4 +282,5 @@ func (s *Service) CreateUserSession(userID string) (string, error) {
}
return sessionID, nil
}
}