refactor: clean up handlers, add input validation, remove raw SQL from handlers
- Merge fanOut/fanOutDirect into single fanOut method - Move channel lookup to db.GetChannelByName - Add regex validation for nicks and channel names - Split HandleSendCommand into per-command helper methods - Add charset to Content-Type header - Add sentinel error for unauthorized - Cap history limit to 500 - Skip NICK change if new == old - Add empty command check
This commit is contained in:
@@ -77,6 +77,13 @@ func (s *Database) GetUserByNick(ctx context.Context, nick string) (int64, error
|
||||
return id, err
|
||||
}
|
||||
|
||||
// GetChannelByName returns the channel ID for a given name.
|
||||
func (s *Database) GetChannelByName(ctx context.Context, name string) (int64, error) {
|
||||
var id int64
|
||||
err := s.db.QueryRowContext(ctx, "SELECT id FROM channels WHERE name = ?", name).Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
// GetOrCreateChannel returns the channel id, creating it if needed.
|
||||
func (s *Database) GetOrCreateChannel(ctx context.Context, name string) (int64, error) {
|
||||
var id int64
|
||||
|
||||
Reference in New Issue
Block a user