Compare commits
16 Commits
develop
...
a513dc2207
| Author | SHA1 | Date | |
|---|---|---|---|
| a513dc2207 | |||
| 6bc35fc0bb | |||
| d3adf07c3f | |||
| 921917a319 | |||
| 9d2dba87b8 | |||
| 95e2a77335 | |||
| 6c824712c9 | |||
| 5c073705d8 | |||
| 243abe55b5 | |||
| c645171671 | |||
| 07745ea4ed | |||
| 22385e8742 | |||
| a77a757317 | |||
| 2d281d1c8c | |||
| 13f484e726 | |||
| ebaf6d39ea |
348
REDESIGN_PLAN.md
348
REDESIGN_PLAN.md
@@ -22,353 +22,7 @@ Success: #22c55e
|
||||
Error: #ef4444
|
||||
Text: #e2e8f0
|
||||
Text Muted: #64748b
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Фаза 1: Базовая инфраструктура
|
||||
|
||||
### 1.1 Обновление Tailwind Config
|
||||
- [ ] Новая цветовая палитра (neon colors)
|
||||
- [ ] Кастомные анимации:
|
||||
- `glitch` - glitch эффект для текста
|
||||
- `glow-pulse` - пульсация свечения
|
||||
- `float` - плавное парение
|
||||
- `slide-in-left/right/up/down` - слайды
|
||||
- `scale-in` - появление с масштабом
|
||||
- `shimmer` - блик на элементах
|
||||
- [ ] Кастомные backdrop-blur классы
|
||||
- [ ] Градиентные утилиты
|
||||
|
||||
### 1.2 Глобальные стили (index.css)
|
||||
- [ ] CSS переменные для цветов
|
||||
- [ ] Glitch keyframes анимация
|
||||
- [ ] Noise/grain overlay
|
||||
- [ ] Glow эффекты (box-shadow неон)
|
||||
- [ ] Custom scrollbar (неоновый)
|
||||
- [ ] Selection стили (выделение текста)
|
||||
|
||||
### 1.3 Новые UI компоненты
|
||||
- [ ] `GlitchText` - текст с glitch эффектом
|
||||
- [ ] `NeonButton` - кнопка с неоновым свечением
|
||||
- [ ] `GlassCard` - карточка с glassmorphism
|
||||
- [ ] `AnimatedCounter` - анимированные числа
|
||||
- [ ] `ProgressBar` - неоновый прогресс бар
|
||||
- [ ] `Badge` - бейджи со свечением
|
||||
- [ ] `Skeleton` - скелетоны загрузки
|
||||
- [ ] `Tooltip` - тултипы
|
||||
- [ ] `Tabs` - табы с анимацией
|
||||
- [ ] `Modal` - переработанная модалка
|
||||
|
||||
---
|
||||
|
||||
## Фаза 2: Layout и навигация
|
||||
|
||||
### 2.1 Новый Header
|
||||
- [ ] Sticky header с blur при скролле
|
||||
- [ ] Логотип с glitch эффектом при hover
|
||||
- [ ] Анимированная навигация (underline slide)
|
||||
- [ ] Notification bell с badge
|
||||
- [ ] User dropdown с аватаром
|
||||
- [ ] Mobile hamburger menu с slide-in
|
||||
|
||||
### 2.2 Sidebar (новый компонент)
|
||||
- [ ] Collapsible sidebar для desktop
|
||||
- [ ] Иконки с tooltip
|
||||
- [ ] Active state с неоновой подсветкой
|
||||
- [ ] Quick stats внизу
|
||||
|
||||
### 2.3 Footer
|
||||
- [ ] Минималистичный footer
|
||||
- [ ] Social links
|
||||
- [ ] Version info
|
||||
|
||||
---
|
||||
|
||||
## Фаза 3: Страницы
|
||||
|
||||
### 3.1 HomePage (полный редизайн)
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ HERO SECTION │
|
||||
│ ┌─────────────────────────────────────┐ │
|
||||
│ │ Animated background (particles/ │ │
|
||||
│ │ geometric shapes) │ │
|
||||
│ │ │ │
|
||||
│ │ GAME <glitch>MARATHON</glitch> │ │
|
||||
│ │ │ │
|
||||
│ │ Tagline with typing effect │ │
|
||||
│ │ │ │
|
||||
│ │ [Start Playing] [Watch Demo] │ │
|
||||
│ └─────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ FEATURES SECTION (3 glass cards) │
|
||||
│ ┌───────┐ ┌───────┐ ┌───────┐ │
|
||||
│ │ Icon │ │ Icon │ │ Icon │ hover: │
|
||||
│ │ Title │ │ Title │ │ Title │ lift + │
|
||||
│ │ Desc │ │ Desc │ │ Desc │ glow │
|
||||
│ └───────┘ └───────┘ └───────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ HOW IT WORKS (timeline style) │
|
||||
│ ○───────○───────○───────○ │
|
||||
│ 1 2 3 4 │
|
||||
│ Create Add Spin Win │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ LIVE STATS (animated counters) │
|
||||
│ [ 1,234 Marathons ] [ 5,678 Challenges ] │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ CTA SECTION │
|
||||
│ Ready to compete? [Join Now] │
|
||||
└─────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 3.2 Login/Register Pages
|
||||
- [ ] Centered card с glassmorphism
|
||||
- [ ] Animated background (subtle)
|
||||
- [ ] Form inputs с glow при focus
|
||||
- [ ] Password strength indicator
|
||||
- [ ] Social login buttons (future)
|
||||
- [ ] Smooth transitions между login/register
|
||||
|
||||
### 3.3 MarathonsPage (Dashboard)
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Header: "My Marathons" + Create button │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Quick Stats Bar │
|
||||
│ [Active: 2] [Completed: 5] [Total Wins: 3]│
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Filters/Tabs: All | Active | Completed │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Marathon Cards Grid (2-3 columns) │
|
||||
│ ┌──────────────────┐ ┌──────────────────┐ │
|
||||
│ │ Cover image/ │ │ │ │
|
||||
│ │ gradient │ │ │ │
|
||||
│ │ ──────────── │ │ │ │
|
||||
│ │ Title │ │ │ │
|
||||
│ │ Status badge │ │ │ │
|
||||
│ │ Participants │ │ │ │
|
||||
│ │ Progress bar │ │ │ │
|
||||
│ └──────────────────┘ └──────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Join by Code (expandable section) │
|
||||
└─────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 3.4 MarathonPage (Detail)
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Hero Banner │
|
||||
│ ┌─────────────────────────────────────┐ │
|
||||
│ │ Background gradient + pattern │ │
|
||||
│ │ Marathon Title (large) │ │
|
||||
│ │ Status | Dates | Participants │ │
|
||||
│ │ [Play] [Leaderboard] [Settings] │ │
|
||||
│ └─────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Event Banner (if active) - animated │
|
||||
├────────────────────┬────────────────────────┤
|
||||
│ Main Content │ Sidebar │
|
||||
│ ┌──────────────┐ │ ┌──────────────────┐ │
|
||||
│ │ Your Stats │ │ │ Activity Feed │ │
|
||||
│ │ Points/Streak│ │ │ (scrollable) │ │
|
||||
│ └──────────────┘ │ │ │ │
|
||||
│ ┌──────────────┐ │ │ │ │
|
||||
│ │ Quick Actions│ │ │ │ │
|
||||
│ └──────────────┘ │ │ │ │
|
||||
│ ┌──────────────┐ │ │ │ │
|
||||
│ │ Games List │ │ │ │ │
|
||||
│ │ (collapsible)│ │ │ │ │
|
||||
│ └──────────────┘ │ └──────────────────┘ │
|
||||
└────────────────────┴────────────────────────┘
|
||||
```
|
||||
|
||||
### 3.5 PlayPage (Game Screen) - ГЛАВНАЯ СТРАНИЦА
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Top Bar: Points | Streak | Event Timer │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ ┌─────────────────────────────────────┐ │
|
||||
│ │ SPIN WHEEL │ │
|
||||
│ │ (redesigned, neon style) │ │
|
||||
│ │ ┌─────────┐ │ │
|
||||
│ │ │ WHEEL │ │ │
|
||||
│ │ │ │ │ │
|
||||
│ │ └─────────┘ │ │
|
||||
│ │ [SPIN BUTTON] │ │
|
||||
│ └─────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Active Challenge Card (если есть) │
|
||||
│ ┌─────────────────────────────────────┐ │
|
||||
│ │ Game: [Title] | Difficulty: [★★★] │ │
|
||||
│ │ ─────────────────────────────────── │ │
|
||||
│ │ Challenge Title │ │
|
||||
│ │ Description... │ │
|
||||
│ │ ─────────────────────────────────── │ │
|
||||
│ │ Points: 100 | Time: ~2h │ │
|
||||
│ │ ─────────────────────────────────── │ │
|
||||
│ │ Proof Upload Area │ │
|
||||
│ │ [File] [URL] [Comment] │ │
|
||||
│ │ ─────────────────────────────────── │ │
|
||||
│ │ [Complete ✓] [Skip ✗] │ │
|
||||
│ └─────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Mini Leaderboard (top 3 + you) │
|
||||
└─────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 3.6 LeaderboardPage
|
||||
- [ ] Animated podium для top 3
|
||||
- [ ] Table с hover эффектами
|
||||
- [ ] Highlight для текущего пользователя
|
||||
- [ ] Streak fire animation
|
||||
- [ ] Sorting/filtering
|
||||
|
||||
### 3.7 ProfilePage
|
||||
```
|
||||
┌─────────────────────────────────────────────┐
|
||||
│ Profile Header │
|
||||
│ ┌─────────────────────────────────────┐ │
|
||||
│ │ Avatar (large, glow border) │ │
|
||||
│ │ Nickname [Edit] │ │
|
||||
│ │ Member since: Date │ │
|
||||
│ └─────────────────────────────────────┘ │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Stats Cards (animated counters) │
|
||||
│ [Marathons] [Wins] [Challenges] [Points] │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Achievements Section (future) │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Telegram Connection Card │
|
||||
├─────────────────────────────────────────────┤
|
||||
│ Security Section (password change) │
|
||||
└─────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### 3.8 LobbyPage
|
||||
- [ ] Step-by-step wizard UI
|
||||
- [ ] Game cards grid с preview
|
||||
- [ ] Challenge preview с difficulty badges
|
||||
- [ ] AI generation progress animation
|
||||
- [ ] Launch countdown
|
||||
|
||||
---
|
||||
|
||||
## Фаза 4: Специальные компоненты
|
||||
|
||||
### 4.1 SpinWheel (полный редизайн)
|
||||
- [ ] 3D perspective эффект
|
||||
- [ ] Неоновые сегменты с названиями игр
|
||||
- [ ] Particle effects при кручении
|
||||
- [ ] Glow trail за указателем
|
||||
- [ ] Sound effects (optional)
|
||||
- [ ] Confetti при выигрыше
|
||||
|
||||
### 4.2 EventBanner (переработка)
|
||||
- [ ] Pulsating glow border
|
||||
- [ ] Countdown timer с flip animation
|
||||
- [ ] Event-specific icons/colors
|
||||
- [ ] Dismiss animation
|
||||
|
||||
### 4.3 ActivityFeed (переработка)
|
||||
- [ ] Timeline style
|
||||
- [ ] Avatar circles
|
||||
- [ ] Type-specific icons
|
||||
- [ ] Hover для деталей
|
||||
- [ ] New items animation (slide-in)
|
||||
|
||||
### 4.4 Challenge Cards
|
||||
- [ ] Difficulty stars/badges
|
||||
- [ ] Progress indicator
|
||||
- [ ] Expandable details
|
||||
- [ ] Proof preview thumbnail
|
||||
|
||||
---
|
||||
|
||||
## Фаза 5: Анимации и эффекты
|
||||
|
||||
### 5.1 Page Transitions
|
||||
- [ ] Framer Motion page transitions
|
||||
- [ ] Fade + slide between routes
|
||||
- [ ] Loading skeleton screens
|
||||
|
||||
### 5.2 Micro-interactions
|
||||
- [ ] Button press effects
|
||||
- [ ] Input focus glow
|
||||
- [ ] Success checkmark animation
|
||||
- [ ] Error shake animation
|
||||
- [ ] Loading spinners (custom)
|
||||
|
||||
### 5.3 Background Effects
|
||||
- [ ] Animated gradient mesh
|
||||
- [ ] Floating particles (optional)
|
||||
- [ ] Grid pattern overlay
|
||||
- [ ] Noise texture
|
||||
|
||||
### 5.4 Special Effects
|
||||
- [ ] Glitch text на заголовках
|
||||
- [ ] Neon glow на важных элементах
|
||||
- [ ] Shimmer effect на loading
|
||||
- [ ] Confetti на achievements
|
||||
|
||||
---
|
||||
|
||||
## Фаза 6: Responsive и Polish
|
||||
|
||||
### 6.1 Mobile Optimization
|
||||
- [ ] Touch-friendly targets
|
||||
- [ ] Swipe gestures
|
||||
- [ ] Bottom navigation (mobile)
|
||||
- [ ] Collapsible sections
|
||||
|
||||
### 6.2 Accessibility
|
||||
- [ ] Keyboard navigation
|
||||
- [ ] Focus indicators
|
||||
- [ ] Screen reader support
|
||||
- [ ] Reduced motion option
|
||||
|
||||
### 6.3 Performance
|
||||
- [ ] Lazy loading images
|
||||
- [ ] Code splitting
|
||||
- [ ] Animation optimization
|
||||
- [ ] Bundle size check
|
||||
|
||||
---
|
||||
|
||||
## Порядок реализации
|
||||
|
||||
### Sprint 1: Фундамент (2-3 дня)
|
||||
1. Tailwind config + colors
|
||||
2. Global CSS + animations
|
||||
3. Base UI components (Button, Card, Input)
|
||||
4. GlitchText component
|
||||
5. Updated Layout/Header
|
||||
|
||||
### Sprint 2: Core Pages (3-4 дня)
|
||||
1. HomePage с hero
|
||||
2. Login/Register
|
||||
3. MarathonsPage dashboard
|
||||
4. Profile page
|
||||
|
||||
### Sprint 3: Game Flow (3-4 дня)
|
||||
1. MarathonPage detail
|
||||
2. SpinWheel redesign
|
||||
3. PlayPage
|
||||
4. LeaderboardPage
|
||||
|
||||
### Sprint 4: Polish (2-3 дня)
|
||||
1. LobbyPage
|
||||
2. Event components
|
||||
3. Activity feed
|
||||
4. Animations & transitions
|
||||
|
||||
### Sprint 5: Finalization (1-2 дня)
|
||||
1. Mobile testing
|
||||
2. Performance optimization
|
||||
3. Bug fixes
|
||||
4. Final polish
|
||||
|
||||
---
|
||||
```А ты
|
||||
|
||||
## Референсы для вдохновления
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '001_add_roles'
|
||||
@@ -17,17 +18,35 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def constraint_exists(table_name: str, constraint_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
fks = inspector.get_foreign_keys(table_name)
|
||||
return any(fk['name'] == constraint_name for fk in fks)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add role column to users table
|
||||
op.add_column('users', sa.Column('role', sa.String(20), nullable=False, server_default='user'))
|
||||
if not column_exists('users', 'role'):
|
||||
op.add_column('users', sa.Column('role', sa.String(20), nullable=False, server_default='user'))
|
||||
|
||||
# Add role column to participants table
|
||||
op.add_column('participants', sa.Column('role', sa.String(20), nullable=False, server_default='participant'))
|
||||
if not column_exists('participants', 'role'):
|
||||
op.add_column('participants', sa.Column('role', sa.String(20), nullable=False, server_default='participant'))
|
||||
|
||||
# Rename organizer_id to creator_id in marathons table
|
||||
op.alter_column('marathons', 'organizer_id', new_column_name='creator_id')
|
||||
if column_exists('marathons', 'organizer_id') and not column_exists('marathons', 'creator_id'):
|
||||
op.alter_column('marathons', 'organizer_id', new_column_name='creator_id')
|
||||
|
||||
# Update existing participants: set role='organizer' for marathon creators
|
||||
# This is idempotent - running multiple times is safe
|
||||
op.execute("""
|
||||
UPDATE participants p
|
||||
SET role = 'organizer'
|
||||
@@ -36,37 +55,48 @@ def upgrade() -> None:
|
||||
""")
|
||||
|
||||
# Add status column to games table
|
||||
op.add_column('games', sa.Column('status', sa.String(20), nullable=False, server_default='approved'))
|
||||
if not column_exists('games', 'status'):
|
||||
op.add_column('games', sa.Column('status', sa.String(20), nullable=False, server_default='approved'))
|
||||
|
||||
# Rename added_by_id to proposed_by_id in games table
|
||||
op.alter_column('games', 'added_by_id', new_column_name='proposed_by_id')
|
||||
if column_exists('games', 'added_by_id') and not column_exists('games', 'proposed_by_id'):
|
||||
op.alter_column('games', 'added_by_id', new_column_name='proposed_by_id')
|
||||
|
||||
# Add approved_by_id column to games table
|
||||
op.add_column('games', sa.Column('approved_by_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(
|
||||
'fk_games_approved_by_id',
|
||||
'games', 'users',
|
||||
['approved_by_id'], ['id'],
|
||||
ondelete='SET NULL'
|
||||
)
|
||||
if not column_exists('games', 'approved_by_id'):
|
||||
op.add_column('games', sa.Column('approved_by_id', sa.Integer(), nullable=True))
|
||||
if not constraint_exists('games', 'fk_games_approved_by_id'):
|
||||
op.create_foreign_key(
|
||||
'fk_games_approved_by_id',
|
||||
'games', 'users',
|
||||
['approved_by_id'], ['id'],
|
||||
ondelete='SET NULL'
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Remove approved_by_id from games
|
||||
op.drop_constraint('fk_games_approved_by_id', 'games', type_='foreignkey')
|
||||
op.drop_column('games', 'approved_by_id')
|
||||
if constraint_exists('games', 'fk_games_approved_by_id'):
|
||||
op.drop_constraint('fk_games_approved_by_id', 'games', type_='foreignkey')
|
||||
if column_exists('games', 'approved_by_id'):
|
||||
op.drop_column('games', 'approved_by_id')
|
||||
|
||||
# Rename proposed_by_id back to added_by_id
|
||||
op.alter_column('games', 'proposed_by_id', new_column_name='added_by_id')
|
||||
if column_exists('games', 'proposed_by_id'):
|
||||
op.alter_column('games', 'proposed_by_id', new_column_name='added_by_id')
|
||||
|
||||
# Remove status from games
|
||||
op.drop_column('games', 'status')
|
||||
if column_exists('games', 'status'):
|
||||
op.drop_column('games', 'status')
|
||||
|
||||
# Rename creator_id back to organizer_id
|
||||
op.alter_column('marathons', 'creator_id', new_column_name='organizer_id')
|
||||
if column_exists('marathons', 'creator_id'):
|
||||
op.alter_column('marathons', 'creator_id', new_column_name='organizer_id')
|
||||
|
||||
# Remove role from participants
|
||||
op.drop_column('participants', 'role')
|
||||
if column_exists('participants', 'role'):
|
||||
op.drop_column('participants', 'role')
|
||||
|
||||
# Remove role from users
|
||||
op.drop_column('users', 'role')
|
||||
if column_exists('users', 'role'):
|
||||
op.drop_column('users', 'role')
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '002_marathon_settings'
|
||||
@@ -17,16 +18,27 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Add is_public column to marathons table (default False = private)
|
||||
op.add_column('marathons', sa.Column('is_public', sa.Boolean(), nullable=False, server_default='false'))
|
||||
if not column_exists('marathons', 'is_public'):
|
||||
op.add_column('marathons', sa.Column('is_public', sa.Boolean(), nullable=False, server_default='false'))
|
||||
|
||||
# Add game_proposal_mode column to marathons table
|
||||
# 'all_participants' - anyone can propose games (with moderation)
|
||||
# 'organizer_only' - only organizers can add games
|
||||
op.add_column('marathons', sa.Column('game_proposal_mode', sa.String(20), nullable=False, server_default='all_participants'))
|
||||
if not column_exists('marathons', 'game_proposal_mode'):
|
||||
op.add_column('marathons', sa.Column('game_proposal_mode', sa.String(20), nullable=False, server_default='all_participants'))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('marathons', 'game_proposal_mode')
|
||||
op.drop_column('marathons', 'is_public')
|
||||
if column_exists('marathons', 'game_proposal_mode'):
|
||||
op.drop_column('marathons', 'game_proposal_mode')
|
||||
if column_exists('marathons', 'is_public'):
|
||||
op.drop_column('marathons', 'is_public')
|
||||
|
||||
@@ -17,15 +17,17 @@ depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
# Update event type from 'rematch' to 'game_choice' in events table
|
||||
# These UPDATE statements are idempotent - safe to run multiple times
|
||||
op.execute("UPDATE events SET type = 'game_choice' WHERE type = 'rematch'")
|
||||
|
||||
# Update event_type in assignments table
|
||||
op.execute("UPDATE assignments SET event_type = 'game_choice' WHERE event_type = 'rematch'")
|
||||
|
||||
# Update activity data that references rematch event
|
||||
# Cast JSON to JSONB, apply jsonb_set, then cast back to JSON
|
||||
op.execute("""
|
||||
UPDATE activities
|
||||
SET data = jsonb_set(data, '{event_type}', '"game_choice"')
|
||||
SET data = jsonb_set(data::jsonb, '{event_type}', '"game_choice"')::json
|
||||
WHERE data->>'event_type' = 'rematch'
|
||||
""")
|
||||
|
||||
@@ -36,6 +38,6 @@ def downgrade() -> None:
|
||||
op.execute("UPDATE assignments SET event_type = 'rematch' WHERE event_type = 'game_choice'")
|
||||
op.execute("""
|
||||
UPDATE activities
|
||||
SET data = jsonb_set(data, '{event_type}', '"rematch"')
|
||||
SET data = jsonb_set(data::jsonb, '{event_type}', '"rematch"')::json
|
||||
WHERE data->>'event_type' = 'game_choice'
|
||||
""")
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@@ -18,13 +19,26 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column('users', sa.Column('telegram_first_name', sa.String(100), nullable=True))
|
||||
op.add_column('users', sa.Column('telegram_last_name', sa.String(100), nullable=True))
|
||||
op.add_column('users', sa.Column('telegram_avatar_url', sa.String(500), nullable=True))
|
||||
if not column_exists('users', 'telegram_first_name'):
|
||||
op.add_column('users', sa.Column('telegram_first_name', sa.String(100), nullable=True))
|
||||
if not column_exists('users', 'telegram_last_name'):
|
||||
op.add_column('users', sa.Column('telegram_last_name', sa.String(100), nullable=True))
|
||||
if not column_exists('users', 'telegram_avatar_url'):
|
||||
op.add_column('users', sa.Column('telegram_avatar_url', sa.String(500), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('users', 'telegram_avatar_url')
|
||||
op.drop_column('users', 'telegram_last_name')
|
||||
op.drop_column('users', 'telegram_first_name')
|
||||
if column_exists('users', 'telegram_avatar_url'):
|
||||
op.drop_column('users', 'telegram_avatar_url')
|
||||
if column_exists('users', 'telegram_last_name'):
|
||||
op.drop_column('users', 'telegram_last_name')
|
||||
if column_exists('users', 'telegram_first_name'):
|
||||
op.drop_column('users', 'telegram_first_name')
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@@ -18,11 +19,22 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column('challenges', sa.Column('proposed_by_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=True))
|
||||
op.add_column('challenges', sa.Column('status', sa.String(20), server_default='approved', nullable=False))
|
||||
if not column_exists('challenges', 'proposed_by_id'):
|
||||
op.add_column('challenges', sa.Column('proposed_by_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=True))
|
||||
if not column_exists('challenges', 'status'):
|
||||
op.add_column('challenges', sa.Column('status', sa.String(20), server_default='approved', nullable=False))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('challenges', 'status')
|
||||
op.drop_column('challenges', 'proposed_by_id')
|
||||
if column_exists('challenges', 'status'):
|
||||
op.drop_column('challenges', 'status')
|
||||
if column_exists('challenges', 'proposed_by_id'):
|
||||
op.drop_column('challenges', 'proposed_by_id')
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@@ -18,15 +19,30 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column('users', sa.Column('is_banned', sa.Boolean(), server_default='false', nullable=False))
|
||||
op.add_column('users', sa.Column('banned_at', sa.DateTime(), nullable=True))
|
||||
op.add_column('users', sa.Column('banned_by_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=True))
|
||||
op.add_column('users', sa.Column('ban_reason', sa.String(500), nullable=True))
|
||||
if not column_exists('users', 'is_banned'):
|
||||
op.add_column('users', sa.Column('is_banned', sa.Boolean(), server_default='false', nullable=False))
|
||||
if not column_exists('users', 'banned_at'):
|
||||
op.add_column('users', sa.Column('banned_at', sa.DateTime(), nullable=True))
|
||||
if not column_exists('users', 'banned_by_id'):
|
||||
op.add_column('users', sa.Column('banned_by_id', sa.Integer(), sa.ForeignKey('users.id'), nullable=True))
|
||||
if not column_exists('users', 'ban_reason'):
|
||||
op.add_column('users', sa.Column('ban_reason', sa.String(500), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('users', 'ban_reason')
|
||||
op.drop_column('users', 'banned_by_id')
|
||||
op.drop_column('users', 'banned_at')
|
||||
op.drop_column('users', 'is_banned')
|
||||
if column_exists('users', 'ban_reason'):
|
||||
op.drop_column('users', 'ban_reason')
|
||||
if column_exists('users', 'banned_by_id'):
|
||||
op.drop_column('users', 'banned_by_id')
|
||||
if column_exists('users', 'banned_at'):
|
||||
op.drop_column('users', 'banned_at')
|
||||
if column_exists('users', 'is_banned'):
|
||||
op.drop_column('users', 'is_banned')
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
@@ -18,15 +19,29 @@ branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def is_column_nullable(table_name: str, column_name: str) -> bool:
|
||||
"""Check if a column is nullable."""
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = inspector.get_columns(table_name)
|
||||
for col in columns:
|
||||
if col['name'] == column_name:
|
||||
return col.get('nullable', True)
|
||||
return True
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Make admin_id nullable for system actions (like auto-unban)
|
||||
op.alter_column('admin_logs', 'admin_id',
|
||||
existing_type=sa.Integer(),
|
||||
nullable=True)
|
||||
# Only alter if currently not nullable
|
||||
if not is_column_nullable('admin_logs', 'admin_id'):
|
||||
op.alter_column('admin_logs', 'admin_id',
|
||||
existing_type=sa.Integer(),
|
||||
nullable=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Revert to not nullable (will fail if there are NULL values)
|
||||
op.alter_column('admin_logs', 'admin_id',
|
||||
existing_type=sa.Integer(),
|
||||
nullable=False)
|
||||
if is_column_nullable('admin_logs', 'admin_id'):
|
||||
op.alter_column('admin_logs', 'admin_id',
|
||||
existing_type=sa.Integer(),
|
||||
nullable=False)
|
||||
|
||||
346
backend/alembic/versions/018_seed_static_content.py
Normal file
346
backend/alembic/versions/018_seed_static_content.py
Normal file
@@ -0,0 +1,346 @@
|
||||
"""Seed static content
|
||||
|
||||
Revision ID: 018_seed_static_content
|
||||
Revises: 017_admin_logs_nullable_admin_id
|
||||
Create Date: 2024-12-20
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '018_seed_static_content'
|
||||
down_revision: Union[str, None] = '017_admin_logs_nullable_admin_id'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
STATIC_CONTENT_DATA = [
|
||||
{
|
||||
'key': 'terms_of_service',
|
||||
'title': 'Пользовательское соглашение',
|
||||
'content': '''<p class="text-gray-400 mb-6">Настоящее Пользовательское соглашение (далее — «Соглашение») регулирует отношения между администрацией интернет-сервиса «Игровой Марафон» (далее — «Сервис», «Платформа», «Мы») и физическим лицом, использующим Сервис (далее — «Пользователь», «Вы»).</p>
|
||||
|
||||
<p class="text-gray-400 mb-6"><strong class="text-white">Дата вступления в силу:</strong> с момента регистрации на Платформе.<br/>
|
||||
Используя Сервис, Вы подтверждаете, что полностью ознакомились с условиями настоящего Соглашения и принимаете их в полном объёме.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>1. Общие положения</h2>
|
||||
|
||||
<p>1.1. Сервис «Игровой Марафон» представляет собой онлайн-платформу для организации и проведения игровых марафонов — соревнований, в рамках которых участники выполняют игровые задания (челленджи) и получают очки за их успешное выполнение.</p>
|
||||
|
||||
<p>1.2. Сервис предоставляет Пользователям следующие возможности:</p>
|
||||
<ul>
|
||||
<li>Создание и участие в игровых марафонах</li>
|
||||
<li>Получение случайных игровых заданий различной сложности</li>
|
||||
<li>Отслеживание прогресса и статистики участников</li>
|
||||
<li>Участие в специальных игровых событиях</li>
|
||||
<li>Получение уведомлений через интеграцию с Telegram</li>
|
||||
</ul>
|
||||
|
||||
<p>1.3. Сервис предоставляется на условиях «как есть» (as is). Администрация не гарантирует, что Сервис будет соответствовать ожиданиям Пользователя или работать бесперебойно.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>2. Регистрация и учётная запись</h2>
|
||||
|
||||
<p>2.1. Для доступа к функционалу Сервиса необходима регистрация учётной записи. При регистрации Пользователь обязуется предоставить достоверные данные.</p>
|
||||
|
||||
<p>2.2. Пользователь несёт полную ответственность за:</p>
|
||||
<ul>
|
||||
<li>Сохранность своих учётных данных (логина и пароля)</li>
|
||||
<li>Все действия, совершённые с использованием его учётной записи</li>
|
||||
<li>Своевременное уведомление Администрации о несанкционированном доступе к аккаунту</li>
|
||||
</ul>
|
||||
|
||||
<p>2.3. Каждый Пользователь имеет право на одну учётную запись. Создание дополнительных аккаунтов (мультиаккаунтинг) запрещено и влечёт блокировку всех связанных учётных записей.</p>
|
||||
|
||||
<p>2.4. Пользователь вправе в любой момент удалить свою учётную запись, обратившись к Администрации. При удалении аккаунта все связанные данные будут безвозвратно удалены.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>3. Правила использования Сервиса</h2>
|
||||
|
||||
<p>3.1. <strong class="text-white">При использовании Сервиса запрещается:</strong></p>
|
||||
<ul>
|
||||
<li>Использовать читы, эксплойты, модификации и любое стороннее программное обеспечение, дающее нечестное преимущество при выполнении игровых заданий</li>
|
||||
<li>Предоставлять ложные доказательства выполнения заданий (поддельные скриншоты, видео, достижения)</li>
|
||||
<li>Передавать доступ к учётной записи третьим лицам</li>
|
||||
<li>Оскорблять, унижать или преследовать других участников</li>
|
||||
<li>Распространять спам, рекламу или вредоносный контент</li>
|
||||
<li>Нарушать работу Сервиса техническими средствами</li>
|
||||
<li>Использовать Сервис для деятельности, нарушающей законодательство</li>
|
||||
</ul>
|
||||
|
||||
<p>3.2. <strong class="text-white">Правила проведения марафонов:</strong></p>
|
||||
<ul>
|
||||
<li>Участники обязаны честно выполнять полученные задания</li>
|
||||
<li>Доказательства выполнения должны быть подлинными и соответствовать требованиям задания</li>
|
||||
<li>Отказ от задания (дроп) влечёт штрафные санкции согласно правилам конкретного марафона</li>
|
||||
<li>Споры по заданиям разрешаются через систему диспутов с участием других участников марафона</li>
|
||||
</ul>
|
||||
|
||||
<p>3.3. Организаторы марафонов несут ответственность за соблюдение правил в рамках своих мероприятий и имеют право устанавливать дополнительные правила, не противоречащие настоящему Соглашению.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>4. Система очков и рейтинг</h2>
|
||||
|
||||
<p>4.1. За выполнение заданий Пользователи получают очки, количество которых зависит от сложности задания и активных игровых событий.</p>
|
||||
|
||||
<p>4.2. Очки используются исключительно для формирования рейтинга участников в рамках марафонов и не имеют денежного эквивалента.</p>
|
||||
|
||||
<p>4.3. Администрация оставляет за собой право корректировать начисленные очки в случае выявления нарушений или технических ошибок.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>5. Ответственность сторон</h2>
|
||||
|
||||
<p>5.1. <strong class="text-white">Администрация не несёт ответственности за:</strong></p>
|
||||
<ul>
|
||||
<li>Временную недоступность Сервиса по техническим причинам</li>
|
||||
<li>Потерю данных вследствие технических сбоев</li>
|
||||
<li>Действия третьих лиц, получивших доступ к учётной записи Пользователя</li>
|
||||
<li>Контент, размещаемый Пользователями</li>
|
||||
<li>Качество интернет-соединения Пользователя</li>
|
||||
</ul>
|
||||
|
||||
<p>5.2. Пользователь несёт ответственность за соблюдение условий настоящего Соглашения и применимого законодательства.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>6. Санкции за нарушения</h2>
|
||||
|
||||
<p>6.1. За нарушение условий настоящего Соглашения Администрация вправе применить следующие санкции:</p>
|
||||
<ul>
|
||||
<li><strong class="text-yellow-400">Предупреждение</strong> — за незначительные нарушения</li>
|
||||
<li><strong class="text-orange-400">Временная блокировка</strong> — ограничение доступа к Сервису на определённый срок</li>
|
||||
<li><strong class="text-red-400">Постоянная блокировка</strong> — бессрочное ограничение доступа за грубые или повторные нарушения</li>
|
||||
</ul>
|
||||
|
||||
<p>6.2. Решение о применении санкций принимается Администрацией единолично и является окончательным. Администрация не обязана объяснять причины принятого решения.</p>
|
||||
|
||||
<p>6.3. Обход блокировки путём создания новых учётных записей влечёт блокировку всех выявленных аккаунтов.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>7. Интеллектуальная собственность</h2>
|
||||
|
||||
<p>7.1. Все элементы Сервиса (дизайн, код, тексты, логотипы) являются объектами интеллектуальной собственности Администрации и защищены применимым законодательством.</p>
|
||||
|
||||
<p>7.2. Использование материалов Сервиса без письменного разрешения Администрации запрещено.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>8. Изменение условий Соглашения</h2>
|
||||
|
||||
<p>8.1. Администрация вправе в одностороннем порядке изменять условия настоящего Соглашения.</p>
|
||||
|
||||
<p>8.2. Актуальная редакция Соглашения размещается на данной странице с указанием даты последнего обновления.</p>
|
||||
|
||||
<p>8.3. Продолжение использования Сервиса после внесения изменений означает согласие Пользователя с новой редакцией Соглашения.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>9. Заключительные положения</h2>
|
||||
|
||||
<p>9.1. Настоящее Соглашение регулируется законодательством Российской Федерации.</p>
|
||||
|
||||
<p>9.2. Все споры, возникающие в связи с использованием Сервиса, подлежат разрешению путём переговоров. При недостижении согласия споры разрешаются в судебном порядке по месту нахождения Администрации.</p>
|
||||
|
||||
<p>9.3. Признание судом недействительности какого-либо положения настоящего Соглашения не влечёт недействительности остальных положений.</p>
|
||||
|
||||
<p>9.4. По всем вопросам, связанным с использованием Сервиса, Вы можете обратиться к Администрации через Telegram-бота или иные доступные каналы связи.</p>'''
|
||||
},
|
||||
{
|
||||
'key': 'privacy_policy',
|
||||
'title': 'Политика конфиденциальности',
|
||||
'content': '''<p class="text-gray-400 mb-6">Настоящая Политика конфиденциальности (далее — «Политика») описывает, как интернет-сервис «Игровой Марафон» (далее — «Сервис», «Мы») собирает, использует, хранит и защищает персональные данные пользователей (далее — «Пользователь», «Вы»).</p>
|
||||
|
||||
<p class="text-gray-400 mb-6">Используя Сервис, Вы даёте согласие на обработку Ваших персональных данных в соответствии с условиями настоящей Политики.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>1. Собираемые данные</h2>
|
||||
|
||||
<p>1.1. <strong class="text-white">Данные, предоставляемые Пользователем:</strong></p>
|
||||
<ul>
|
||||
<li><strong>Регистрационные данные:</strong> логин, пароль (в зашифрованном виде), никнейм</li>
|
||||
<li><strong>Данные профиля:</strong> аватар (при загрузке)</li>
|
||||
<li><strong>Данные интеграции Telegram:</strong> Telegram ID, имя пользователя, имя и фамилия (при привязке бота)</li>
|
||||
</ul>
|
||||
|
||||
<p>1.2. <strong class="text-white">Данные, собираемые автоматически:</strong></p>
|
||||
<ul>
|
||||
<li><strong>Данные об активности:</strong> участие в марафонах, выполненные задания, заработанные очки, статистика</li>
|
||||
<li><strong>Технические данные:</strong> IP-адрес, тип браузера, время доступа (для обеспечения безопасности)</li>
|
||||
<li><strong>Данные сессии:</strong> информация для поддержания авторизации</li>
|
||||
</ul>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>2. Цели обработки данных</h2>
|
||||
|
||||
<p>2.1. Мы обрабатываем Ваши персональные данные для следующих целей:</p>
|
||||
|
||||
<p><strong class="text-neon-400">Предоставление услуг:</strong></p>
|
||||
<ul>
|
||||
<li>Идентификация и аутентификация Пользователя</li>
|
||||
<li>Обеспечение участия в марафонах и игровых событиях</li>
|
||||
<li>Ведение статистики и формирование рейтингов</li>
|
||||
<li>Отображение профиля Пользователя другим участникам</li>
|
||||
</ul>
|
||||
|
||||
<p><strong class="text-neon-400">Коммуникация:</strong></p>
|
||||
<ul>
|
||||
<li>Отправка уведомлений о событиях марафонов через Telegram-бота</li>
|
||||
<li>Информирование о новых заданиях и результатах</li>
|
||||
<li>Ответы на обращения Пользователей</li>
|
||||
</ul>
|
||||
|
||||
<p><strong class="text-neon-400">Безопасность:</strong></p>
|
||||
<ul>
|
||||
<li>Защита от несанкционированного доступа</li>
|
||||
<li>Выявление и предотвращение нарушений</li>
|
||||
<li>Ведение журнала административных действий</li>
|
||||
</ul>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>3. Правовые основания обработки</h2>
|
||||
|
||||
<p>3.1. Обработка персональных данных осуществляется на следующих основаниях:</p>
|
||||
<ul>
|
||||
<li><strong>Согласие Пользователя</strong> — при регистрации и использовании Сервиса</li>
|
||||
<li><strong>Исполнение договора</strong> — Пользовательского соглашения</li>
|
||||
<li><strong>Законный интерес</strong> — обеспечение безопасности Сервиса</li>
|
||||
</ul>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>4. Хранение и защита данных</h2>
|
||||
|
||||
<p>4.1. <strong class="text-white">Меры безопасности:</strong></p>
|
||||
<ul>
|
||||
<li>Пароли хранятся в зашифрованном виде с использованием алгоритма bcrypt</li>
|
||||
<li>Передача данных осуществляется по защищённому протоколу HTTPS</li>
|
||||
<li>Доступ к базе данных ограничен и контролируется</li>
|
||||
<li>Административные действия логируются и требуют двухфакторной аутентификации</li>
|
||||
</ul>
|
||||
|
||||
<p>4.2. <strong class="text-white">Срок хранения:</strong></p>
|
||||
<ul>
|
||||
<li>Данные учётной записи хранятся до момента её удаления Пользователем</li>
|
||||
<li>Данные об активности в марафонах хранятся бессрочно для ведения статистики</li>
|
||||
<li>Технические логи хранятся в течение 12 месяцев</li>
|
||||
</ul>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>5. Передача данных третьим лицам</h2>
|
||||
|
||||
<p>5.1. Мы не продаём, не сдаём в аренду и не передаём Ваши персональные данные третьим лицам в коммерческих целях.</p>
|
||||
|
||||
<p>5.2. <strong class="text-white">Данные могут быть переданы:</strong></p>
|
||||
<ul>
|
||||
<li>Telegram — для обеспечения работы уведомлений (только Telegram ID)</li>
|
||||
<li>Правоохранительным органам — по законному запросу в соответствии с применимым законодательством</li>
|
||||
</ul>
|
||||
|
||||
<p>5.3. <strong class="text-white">Публично доступная информация:</strong></p>
|
||||
<p>Следующие данные видны другим Пользователям Сервиса:</p>
|
||||
<ul>
|
||||
<li>Никнейм</li>
|
||||
<li>Аватар</li>
|
||||
<li>Статистика участия в марафонах</li>
|
||||
<li>Позиция в рейтингах</li>
|
||||
</ul>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>6. Права Пользователя</h2>
|
||||
|
||||
<p>6.1. Вы имеете право:</p>
|
||||
<ul>
|
||||
<li><strong>Получить доступ</strong> к своим персональным данным</li>
|
||||
<li><strong>Исправить</strong> неточные или неполные данные в настройках профиля</li>
|
||||
<li><strong>Удалить</strong> свою учётную запись и связанные данные</li>
|
||||
<li><strong>Отозвать согласие</strong> на обработку данных (путём удаления аккаунта)</li>
|
||||
<li><strong>Отключить</strong> интеграцию с Telegram в любой момент</li>
|
||||
</ul>
|
||||
|
||||
<p>6.2. Для реализации своих прав обратитесь к Администрации через доступные каналы связи.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>7. Файлы cookie и локальное хранилище</h2>
|
||||
|
||||
<p>7.1. Сервис использует локальное хранилище браузера (localStorage, sessionStorage) для:</p>
|
||||
<ul>
|
||||
<li>Хранения токена авторизации</li>
|
||||
<li>Сохранения пользовательских настроек интерфейса</li>
|
||||
<li>Запоминания закрытых информационных баннеров</li>
|
||||
</ul>
|
||||
|
||||
<p>7.2. Вы можете очистить локальное хранилище в настройках браузера, однако это приведёт к выходу из учётной записи.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>8. Обработка данных несовершеннолетних</h2>
|
||||
|
||||
<p>8.1. Сервис не предназначен для лиц младше 14 лет. Мы сознательно не собираем персональные данные детей.</p>
|
||||
|
||||
<p>8.2. Если Вам стало известно, что ребёнок предоставил нам персональные данные, пожалуйста, свяжитесь с Администрацией для их удаления.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>9. Изменение Политики</h2>
|
||||
|
||||
<p>9.1. Мы оставляем за собой право изменять настоящую Политику. Актуальная редакция всегда доступна на данной странице.</p>
|
||||
|
||||
<p>9.2. О существенных изменениях мы уведомим Пользователей через Telegram-бота или баннер на сайте.</p>
|
||||
|
||||
<p>9.3. Продолжение использования Сервиса после внесения изменений означает согласие с обновлённой Политикой.</p>
|
||||
|
||||
<hr class="my-8 border-dark-600" />
|
||||
|
||||
<h2>10. Контактная информация</h2>
|
||||
|
||||
<p>10.1. По вопросам, связанным с обработкой персональных данных, Вы можете обратиться к Администрации через:</p>
|
||||
<ul>
|
||||
<li>Telegram-бота Сервиса</li>
|
||||
<li>Форму обратной связи (при наличии)</li>
|
||||
</ul>
|
||||
|
||||
<p>10.2. Мы обязуемся рассмотреть Ваше обращение в разумные сроки и предоставить ответ.</p>'''
|
||||
},
|
||||
{
|
||||
'key': 'telegram_bot_info',
|
||||
'title': 'Привяжите Telegram-бота',
|
||||
'content': 'Получайте уведомления о событиях марафона, новых заданиях и результатах прямо в Telegram'
|
||||
},
|
||||
{
|
||||
'key': 'announcement',
|
||||
'title': 'Добро пожаловать!',
|
||||
'content': 'Мы рады приветствовать вас в «Игровом Марафоне»! Создайте свой первый марафон или присоединитесь к существующему по коду приглашения.'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
for item in STATIC_CONTENT_DATA:
|
||||
# Use ON CONFLICT to avoid duplicates
|
||||
op.execute(f"""
|
||||
INSERT INTO static_content (key, title, content, created_at, updated_at)
|
||||
VALUES ('{item['key']}', '{item['title'].replace("'", "''")}', '{item['content'].replace("'", "''")}', NOW(), NOW())
|
||||
ON CONFLICT (key) DO NOTHING
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
keys = [f"'{item['key']}'" for item in STATIC_CONTENT_DATA]
|
||||
op.execute(f"DELETE FROM static_content WHERE key IN ({', '.join(keys)})")
|
||||
36
backend/alembic/versions/019_add_marathon_cover.py
Normal file
36
backend/alembic/versions/019_add_marathon_cover.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Add marathon cover_url field
|
||||
|
||||
Revision ID: 019_add_marathon_cover
|
||||
Revises: 018_seed_static_content
|
||||
Create Date: 2024-12-21
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '019_add_marathon_cover'
|
||||
down_revision: Union[str, None] = '018_seed_static_content'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def column_exists(table_name: str, column_name: str) -> bool:
|
||||
bind = op.get_bind()
|
||||
inspector = inspect(bind)
|
||||
columns = [col['name'] for col in inspector.get_columns(table_name)]
|
||||
return column_name in columns
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not column_exists('marathons', 'cover_url'):
|
||||
op.add_column('marathons', sa.Column('cover_url', sa.String(500), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if column_exists('marathons', 'cover_url'):
|
||||
op.drop_column('marathons', 'cover_url')
|
||||
@@ -8,10 +8,11 @@ from app.api.deps import DbSession, CurrentUser, require_admin_with_2fa
|
||||
from app.models import User, UserRole, Marathon, MarathonStatus, Participant, Game, AdminLog, AdminActionType, StaticContent
|
||||
from app.schemas import (
|
||||
UserPublic, MessageResponse,
|
||||
AdminUserResponse, BanUserRequest, AdminLogResponse, AdminLogsListResponse,
|
||||
AdminUserResponse, BanUserRequest, AdminResetPasswordRequest, AdminLogResponse, AdminLogsListResponse,
|
||||
BroadcastRequest, BroadcastResponse, StaticContentResponse, StaticContentUpdate,
|
||||
StaticContentCreate, DashboardStats
|
||||
)
|
||||
from app.core.security import get_password_hash
|
||||
from app.services.telegram_notifier import telegram_notifier
|
||||
from app.core.rate_limit import limiter
|
||||
|
||||
@@ -431,6 +432,66 @@ async def unban_user(
|
||||
)
|
||||
|
||||
|
||||
# ============ Reset Password ============
|
||||
@router.post("/users/{user_id}/reset-password", response_model=AdminUserResponse)
|
||||
async def reset_user_password(
|
||||
request: Request,
|
||||
user_id: int,
|
||||
data: AdminResetPasswordRequest,
|
||||
current_user: CurrentUser,
|
||||
db: DbSession,
|
||||
):
|
||||
"""Reset user password. Admin only."""
|
||||
require_admin_with_2fa(current_user)
|
||||
|
||||
result = await db.execute(select(User).where(User.id == user_id))
|
||||
user = result.scalar_one_or_none()
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
# Hash and save new password
|
||||
user.password_hash = get_password_hash(data.new_password)
|
||||
await db.commit()
|
||||
await db.refresh(user)
|
||||
|
||||
# Log action
|
||||
await log_admin_action(
|
||||
db, current_user.id, AdminActionType.USER_PASSWORD_RESET.value,
|
||||
"user", user_id,
|
||||
{"nickname": user.nickname},
|
||||
request.client.host if request.client else None
|
||||
)
|
||||
|
||||
# Notify user via Telegram if linked
|
||||
if user.telegram_id:
|
||||
await telegram_notifier.send_message(
|
||||
user.telegram_id,
|
||||
"🔐 <b>Ваш пароль был сброшен</b>\n\n"
|
||||
"Администратор установил вам новый пароль. "
|
||||
"Если это были не вы, свяжитесь с поддержкой."
|
||||
)
|
||||
|
||||
marathons_count = await db.scalar(
|
||||
select(func.count()).select_from(Participant).where(Participant.user_id == user.id)
|
||||
)
|
||||
|
||||
return AdminUserResponse(
|
||||
id=user.id,
|
||||
login=user.login,
|
||||
nickname=user.nickname,
|
||||
role=user.role,
|
||||
avatar_url=user.avatar_url,
|
||||
telegram_id=user.telegram_id,
|
||||
telegram_username=user.telegram_username,
|
||||
marathons_count=marathons_count,
|
||||
created_at=user.created_at.isoformat(),
|
||||
is_banned=user.is_banned,
|
||||
banned_at=user.banned_at.isoformat() if user.banned_at else None,
|
||||
banned_until=user.banned_until.isoformat() if user.banned_until else None,
|
||||
ban_reason=user.ban_reason,
|
||||
)
|
||||
|
||||
|
||||
# ============ Force Finish Marathon ============
|
||||
@router.post("/marathons/{marathon_id}/force-finish", response_model=MessageResponse)
|
||||
async def force_finish_marathon(
|
||||
@@ -697,6 +758,37 @@ async def create_content(
|
||||
return content
|
||||
|
||||
|
||||
@router.delete("/content/{key}", response_model=MessageResponse)
|
||||
async def delete_content(
|
||||
key: str,
|
||||
request: Request,
|
||||
current_user: CurrentUser,
|
||||
db: DbSession,
|
||||
):
|
||||
"""Delete static content. Admin only."""
|
||||
require_admin_with_2fa(current_user)
|
||||
|
||||
result = await db.execute(
|
||||
select(StaticContent).where(StaticContent.key == key)
|
||||
)
|
||||
content = result.scalar_one_or_none()
|
||||
if not content:
|
||||
raise HTTPException(status_code=404, detail="Content not found")
|
||||
|
||||
await db.delete(content)
|
||||
await db.commit()
|
||||
|
||||
# Log action
|
||||
await log_admin_action(
|
||||
db, current_user.id, AdminActionType.CONTENT_UPDATE.value,
|
||||
"static_content", content.id,
|
||||
{"action": "delete", "key": key},
|
||||
request.client.host if request.client else None
|
||||
)
|
||||
|
||||
return {"message": f"Content '{key}' deleted successfully"}
|
||||
|
||||
|
||||
# ============ Dashboard ============
|
||||
@router.get("/dashboard", response_model=DashboardStats)
|
||||
async def get_dashboard(current_user: CurrentUser, db: DbSession):
|
||||
|
||||
@@ -59,9 +59,15 @@ async def login(request: Request, data: UserLogin, db: DbSession):
|
||||
|
||||
# Check if user is banned
|
||||
if user.is_banned:
|
||||
# Return full ban info like in deps.py
|
||||
ban_info = {
|
||||
"banned_at": user.banned_at.isoformat() if user.banned_at else None,
|
||||
"banned_until": user.banned_until.isoformat() if user.banned_until else None,
|
||||
"reason": user.ban_reason,
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Your account has been banned",
|
||||
detail=ban_info,
|
||||
)
|
||||
|
||||
# If admin with Telegram linked, require 2FA
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import timedelta
|
||||
import secrets
|
||||
import string
|
||||
from fastapi import APIRouter, HTTPException, status, Depends
|
||||
from fastapi import APIRouter, HTTPException, status, Depends, UploadFile, File, Response
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from sqlalchemy import select, func
|
||||
from sqlalchemy.orm import selectinload
|
||||
@@ -11,7 +11,9 @@ from app.api.deps import (
|
||||
require_participant, require_organizer, require_creator,
|
||||
get_participant,
|
||||
)
|
||||
from app.core.config import settings
|
||||
from app.core.security import decode_access_token
|
||||
from app.services.storage import storage_service
|
||||
|
||||
# Optional auth for endpoints that need it conditionally
|
||||
optional_auth = HTTPBearer(auto_error=False)
|
||||
@@ -62,6 +64,7 @@ async def get_marathon_by_code(invite_code: str, db: DbSession):
|
||||
title=marathon.title,
|
||||
description=marathon.description,
|
||||
status=marathon.status,
|
||||
cover_url=marathon.cover_url,
|
||||
participants_count=participants_count,
|
||||
creator_nickname=marathon.creator.nickname,
|
||||
)
|
||||
@@ -128,6 +131,7 @@ async def list_marathons(current_user: CurrentUser, db: DbSession):
|
||||
title=marathon.title,
|
||||
status=marathon.status,
|
||||
is_public=marathon.is_public,
|
||||
cover_url=marathon.cover_url,
|
||||
participants_count=row[1],
|
||||
start_date=marathon.start_date,
|
||||
end_date=marathon.end_date,
|
||||
@@ -180,6 +184,7 @@ async def create_marathon(
|
||||
is_public=marathon.is_public,
|
||||
game_proposal_mode=marathon.game_proposal_mode,
|
||||
auto_events_enabled=marathon.auto_events_enabled,
|
||||
cover_url=marathon.cover_url,
|
||||
start_date=marathon.start_date,
|
||||
end_date=marathon.end_date,
|
||||
participants_count=1,
|
||||
@@ -226,6 +231,7 @@ async def get_marathon(marathon_id: int, current_user: CurrentUser, db: DbSessio
|
||||
is_public=marathon.is_public,
|
||||
game_proposal_mode=marathon.game_proposal_mode,
|
||||
auto_events_enabled=marathon.auto_events_enabled,
|
||||
cover_url=marathon.cover_url,
|
||||
start_date=marathon.start_date,
|
||||
end_date=marathon.end_date,
|
||||
participants_count=participants_count,
|
||||
@@ -591,3 +597,109 @@ async def get_leaderboard(
|
||||
))
|
||||
|
||||
return leaderboard
|
||||
|
||||
|
||||
@router.get("/{marathon_id}/cover")
|
||||
async def get_marathon_cover(marathon_id: int, db: DbSession):
|
||||
"""Get marathon cover image"""
|
||||
marathon = await get_marathon_or_404(db, marathon_id)
|
||||
|
||||
if not marathon.cover_path:
|
||||
raise HTTPException(status_code=404, detail="Marathon has no cover")
|
||||
|
||||
file_data = await storage_service.get_file(marathon.cover_path, "covers")
|
||||
if not file_data:
|
||||
raise HTTPException(status_code=404, detail="Cover not found in storage")
|
||||
|
||||
content, content_type = file_data
|
||||
|
||||
return Response(
|
||||
content=content,
|
||||
media_type=content_type,
|
||||
headers={
|
||||
"Cache-Control": "public, max-age=3600",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@router.post("/{marathon_id}/cover", response_model=MarathonResponse)
|
||||
async def upload_marathon_cover(
|
||||
marathon_id: int,
|
||||
current_user: CurrentUser,
|
||||
db: DbSession,
|
||||
file: UploadFile = File(...),
|
||||
):
|
||||
"""Upload marathon cover image (organizers only, preparing status)"""
|
||||
await require_organizer(db, current_user, marathon_id)
|
||||
marathon = await get_marathon_or_404(db, marathon_id)
|
||||
|
||||
if marathon.status != MarathonStatus.PREPARING.value:
|
||||
raise HTTPException(status_code=400, detail="Cannot update cover of active or finished marathon")
|
||||
|
||||
# Validate file
|
||||
if not file.content_type or not file.content_type.startswith("image/"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="File must be an image",
|
||||
)
|
||||
|
||||
contents = await file.read()
|
||||
if len(contents) > settings.MAX_UPLOAD_SIZE:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"File too large. Maximum size is {settings.MAX_UPLOAD_SIZE // 1024 // 1024} MB",
|
||||
)
|
||||
|
||||
# Get file extension
|
||||
ext = file.filename.split(".")[-1].lower() if file.filename else "jpg"
|
||||
if ext not in settings.ALLOWED_IMAGE_EXTENSIONS:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Invalid file type. Allowed: {settings.ALLOWED_IMAGE_EXTENSIONS}",
|
||||
)
|
||||
|
||||
# Delete old cover if exists
|
||||
if marathon.cover_path:
|
||||
await storage_service.delete_file(marathon.cover_path)
|
||||
|
||||
# Upload file
|
||||
filename = storage_service.generate_filename(marathon_id, file.filename)
|
||||
file_path = await storage_service.upload_file(
|
||||
content=contents,
|
||||
folder="covers",
|
||||
filename=filename,
|
||||
content_type=file.content_type or "image/jpeg",
|
||||
)
|
||||
|
||||
# Update marathon with cover path and URL
|
||||
marathon.cover_path = file_path
|
||||
marathon.cover_url = f"/api/v1/marathons/{marathon_id}/cover"
|
||||
await db.commit()
|
||||
|
||||
return await get_marathon(marathon_id, current_user, db)
|
||||
|
||||
|
||||
@router.delete("/{marathon_id}/cover", response_model=MarathonResponse)
|
||||
async def delete_marathon_cover(
|
||||
marathon_id: int,
|
||||
current_user: CurrentUser,
|
||||
db: DbSession,
|
||||
):
|
||||
"""Delete marathon cover image (organizers only, preparing status)"""
|
||||
await require_organizer(db, current_user, marathon_id)
|
||||
marathon = await get_marathon_or_404(db, marathon_id)
|
||||
|
||||
if marathon.status != MarathonStatus.PREPARING.value:
|
||||
raise HTTPException(status_code=400, detail="Cannot update cover of active or finished marathon")
|
||||
|
||||
if not marathon.cover_path:
|
||||
raise HTTPException(status_code=400, detail="Marathon has no cover")
|
||||
|
||||
# Delete file from storage
|
||||
await storage_service.delete_file(marathon.cover_path)
|
||||
|
||||
marathon.cover_path = None
|
||||
marathon.cover_url = None
|
||||
await db.commit()
|
||||
|
||||
return await get_marathon(marathon_id, current_user, db)
|
||||
|
||||
@@ -12,6 +12,7 @@ class AdminActionType(str, Enum):
|
||||
USER_UNBAN = "user_unban"
|
||||
USER_AUTO_UNBAN = "user_auto_unban" # System automatic unban
|
||||
USER_ROLE_CHANGE = "user_role_change"
|
||||
USER_PASSWORD_RESET = "user_password_reset"
|
||||
|
||||
# Marathon actions
|
||||
MARATHON_FORCE_FINISH = "marathon_force_finish"
|
||||
|
||||
@@ -31,6 +31,8 @@ class Marathon(Base):
|
||||
start_date: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
end_date: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
auto_events_enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
cover_path: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
cover_url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
|
||||
@@ -83,6 +83,7 @@ from app.schemas.dispute import (
|
||||
)
|
||||
from app.schemas.admin import (
|
||||
BanUserRequest,
|
||||
AdminResetPasswordRequest,
|
||||
AdminUserResponse,
|
||||
AdminLogResponse,
|
||||
AdminLogsListResponse,
|
||||
@@ -175,6 +176,7 @@ __all__ = [
|
||||
"ReturnedAssignmentResponse",
|
||||
# Admin
|
||||
"BanUserRequest",
|
||||
"AdminResetPasswordRequest",
|
||||
"AdminUserResponse",
|
||||
"AdminLogResponse",
|
||||
"AdminLogsListResponse",
|
||||
|
||||
@@ -9,6 +9,10 @@ class BanUserRequest(BaseModel):
|
||||
banned_until: datetime | None = None # None = permanent ban
|
||||
|
||||
|
||||
class AdminResetPasswordRequest(BaseModel):
|
||||
new_password: str = Field(..., min_length=6, max_length=100)
|
||||
|
||||
|
||||
class AdminUserResponse(BaseModel):
|
||||
id: int
|
||||
login: str
|
||||
|
||||
@@ -49,6 +49,7 @@ class MarathonResponse(MarathonBase):
|
||||
is_public: bool
|
||||
game_proposal_mode: str
|
||||
auto_events_enabled: bool
|
||||
cover_url: str | None
|
||||
start_date: datetime | None
|
||||
end_date: datetime | None
|
||||
participants_count: int
|
||||
@@ -69,6 +70,7 @@ class MarathonListItem(BaseModel):
|
||||
title: str
|
||||
status: str
|
||||
is_public: bool
|
||||
cover_url: str | None
|
||||
participants_count: int
|
||||
start_date: datetime | None
|
||||
end_date: datetime | None
|
||||
@@ -87,6 +89,7 @@ class MarathonPublicInfo(BaseModel):
|
||||
title: str
|
||||
description: str | None
|
||||
status: str
|
||||
cover_url: str | None
|
||||
participants_count: int
|
||||
creator_nickname: str
|
||||
|
||||
|
||||
@@ -79,6 +79,8 @@ def create_backup() -> tuple[str, bytes]:
|
||||
config.DB_NAME,
|
||||
"--no-owner",
|
||||
"--no-acl",
|
||||
"--clean", # Add DROP commands before CREATE
|
||||
"--if-exists", # Use IF EXISTS with DROP commands
|
||||
"-F",
|
||||
"p", # plain SQL format
|
||||
]
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
Restore PostgreSQL database from S3 backup.
|
||||
|
||||
Usage:
|
||||
python restore.py - List available backups
|
||||
python restore.py <filename> - Restore from specific backup
|
||||
python restore.py - List available backups
|
||||
python restore.py <filename> - Restore from backup (cleans DB first)
|
||||
python restore.py <filename> --no-clean - Restore without cleaning DB first
|
||||
"""
|
||||
import gzip
|
||||
import os
|
||||
@@ -62,7 +63,48 @@ def list_backups(s3_client) -> list[tuple[str, float, str]]:
|
||||
return []
|
||||
|
||||
|
||||
def restore_backup(s3_client, filename: str) -> None:
|
||||
def clean_database() -> None:
|
||||
"""Drop and recreate public schema to clean the database."""
|
||||
print("Cleaning database (dropping and recreating public schema)...")
|
||||
|
||||
env = os.environ.copy()
|
||||
env["PGPASSWORD"] = config.DB_PASSWORD
|
||||
|
||||
# Drop and recreate public schema
|
||||
clean_sql = b"""
|
||||
DROP SCHEMA public CASCADE;
|
||||
CREATE SCHEMA public;
|
||||
GRANT ALL ON SCHEMA public TO public;
|
||||
"""
|
||||
|
||||
cmd = [
|
||||
"psql",
|
||||
"-h",
|
||||
config.DB_HOST,
|
||||
"-p",
|
||||
config.DB_PORT,
|
||||
"-U",
|
||||
config.DB_USER,
|
||||
"-d",
|
||||
config.DB_NAME,
|
||||
]
|
||||
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
env=env,
|
||||
input=clean_sql,
|
||||
capture_output=True,
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
stderr = result.stderr.decode()
|
||||
if "ERROR" in stderr:
|
||||
raise Exception(f"Database cleanup failed: {stderr}")
|
||||
|
||||
print("Database cleaned successfully!")
|
||||
|
||||
|
||||
def restore_backup(s3_client, filename: str, clean_first: bool = True) -> None:
|
||||
"""Download and restore backup."""
|
||||
key = f"{config.S3_BACKUP_PREFIX}{filename}"
|
||||
|
||||
@@ -79,6 +121,10 @@ def restore_backup(s3_client, filename: str) -> None:
|
||||
print("Decompressing...")
|
||||
sql_data = gzip.decompress(compressed_data)
|
||||
|
||||
# Clean database before restore if requested
|
||||
if clean_first:
|
||||
clean_database()
|
||||
|
||||
print(f"Restoring to database {config.DB_NAME}...")
|
||||
|
||||
# Build psql command
|
||||
@@ -124,20 +170,32 @@ def main() -> int:
|
||||
|
||||
s3_client = create_s3_client()
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
# Parse arguments
|
||||
args = sys.argv[1:]
|
||||
clean_first = True
|
||||
|
||||
if "--no-clean" in args:
|
||||
clean_first = False
|
||||
args.remove("--no-clean")
|
||||
|
||||
if len(args) < 1:
|
||||
# List available backups
|
||||
backups = list_backups(s3_client)
|
||||
if backups:
|
||||
print(f"\nTo restore, run: python restore.py <filename>")
|
||||
print("Add --no-clean to skip database cleanup before restore")
|
||||
else:
|
||||
print("No backups found.")
|
||||
return 0
|
||||
|
||||
filename = sys.argv[1]
|
||||
filename = args[0]
|
||||
|
||||
# Confirm restore
|
||||
print(f"WARNING: This will restore database from {filename}")
|
||||
print("This may overwrite existing data!")
|
||||
if clean_first:
|
||||
print("Database will be CLEANED (all existing data will be DELETED)!")
|
||||
else:
|
||||
print("Database will NOT be cleaned (may cause conflicts with existing data)")
|
||||
print()
|
||||
|
||||
confirm = input("Type 'yes' to continue: ")
|
||||
@@ -147,7 +205,7 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
try:
|
||||
restore_backup(s3_client, filename)
|
||||
restore_backup(s3_client, filename, clean_first=clean_first)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(f"Restore failed: {e}")
|
||||
|
||||
BIN
frontend/public/telegram_banner.png
Normal file
BIN
frontend/public/telegram_banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
BIN
frontend/public/telegram_bot_banner.png
Normal file
BIN
frontend/public/telegram_bot_banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
@@ -1,3 +1,4 @@
|
||||
import { useEffect } from 'react'
|
||||
import { Routes, Route, Navigate } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { ToastContainer, ConfirmModal } from '@/components/ui'
|
||||
@@ -20,6 +21,7 @@ import { InvitePage } from '@/pages/InvitePage'
|
||||
import { AssignmentDetailPage } from '@/pages/AssignmentDetailPage'
|
||||
import { ProfilePage } from '@/pages/ProfilePage'
|
||||
import { UserProfilePage } from '@/pages/UserProfilePage'
|
||||
import { StaticContentPage } from '@/pages/StaticContentPage'
|
||||
import { NotFoundPage } from '@/pages/NotFoundPage'
|
||||
import { TeapotPage } from '@/pages/TeapotPage'
|
||||
import { ServerErrorPage } from '@/pages/ServerErrorPage'
|
||||
@@ -59,10 +61,15 @@ function PublicRoute({ children }: { children: React.ReactNode }) {
|
||||
|
||||
function App() {
|
||||
const banInfo = useAuthStore((state) => state.banInfo)
|
||||
const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
|
||||
const syncUser = useAuthStore((state) => state.syncUser)
|
||||
|
||||
// Show banned screen if user is authenticated and banned
|
||||
if (isAuthenticated && banInfo) {
|
||||
// Sync user data with server on app load
|
||||
useEffect(() => {
|
||||
syncUser()
|
||||
}, [syncUser])
|
||||
|
||||
// Show banned screen if user is banned (either authenticated or during login attempt)
|
||||
if (banInfo) {
|
||||
return (
|
||||
<>
|
||||
<ToastContainer />
|
||||
@@ -82,6 +89,11 @@ function App() {
|
||||
{/* Public invite page */}
|
||||
<Route path="invite/:code" element={<InvitePage />} />
|
||||
|
||||
{/* Public static content pages */}
|
||||
<Route path="terms" element={<StaticContentPage />} />
|
||||
<Route path="privacy" element={<StaticContentPage />} />
|
||||
<Route path="page/:key" element={<StaticContentPage />} />
|
||||
|
||||
<Route
|
||||
path="login"
|
||||
element={
|
||||
|
||||
@@ -52,6 +52,13 @@ export const adminApi = {
|
||||
return response.data
|
||||
},
|
||||
|
||||
resetUserPassword: async (id: number, newPassword: string): Promise<AdminUser> => {
|
||||
const response = await client.post<AdminUser>(`/admin/users/${id}/reset-password`, {
|
||||
new_password: newPassword,
|
||||
})
|
||||
return response.data
|
||||
},
|
||||
|
||||
// Marathons
|
||||
listMarathons: async (skip = 0, limit = 50, search?: string): Promise<AdminMarathon[]> => {
|
||||
const params: Record<string, unknown> = { skip, limit }
|
||||
@@ -114,6 +121,10 @@ export const adminApi = {
|
||||
const response = await client.post<StaticContent>('/admin/content', { key, title, content })
|
||||
return response.data
|
||||
},
|
||||
|
||||
deleteContent: async (key: string): Promise<void> => {
|
||||
await client.delete(`/admin/content/${key}`)
|
||||
},
|
||||
}
|
||||
|
||||
// Public content API (no auth required)
|
||||
|
||||
@@ -33,11 +33,16 @@ function isBanInfo(detail: unknown): detail is BanInfo {
|
||||
client.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: AxiosError<{ detail: string | BanInfo }>) => {
|
||||
// Unauthorized - redirect to login
|
||||
// Unauthorized - redirect to login (but not for auth endpoints)
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
window.location.href = '/login'
|
||||
const url = error.config?.url || ''
|
||||
const isAuthEndpoint = url.includes('/auth/login') || url.includes('/auth/register') || url.includes('/auth/2fa')
|
||||
|
||||
if (!isAuthEndpoint) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
window.location.href = '/login'
|
||||
}
|
||||
}
|
||||
|
||||
// Forbidden - check if user is banned
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import client from './client'
|
||||
import type { Marathon, MarathonListItem, MarathonPublicInfo, LeaderboardEntry, ParticipantWithUser, ParticipantRole, GameProposalMode } from '@/types'
|
||||
import type { Marathon, MarathonListItem, MarathonPublicInfo, MarathonUpdate, LeaderboardEntry, ParticipantWithUser, ParticipantRole, GameProposalMode } from '@/types'
|
||||
|
||||
export interface CreateMarathonData {
|
||||
title: string
|
||||
@@ -10,6 +10,8 @@ export interface CreateMarathonData {
|
||||
game_proposal_mode?: GameProposalMode
|
||||
}
|
||||
|
||||
export type { MarathonUpdate }
|
||||
|
||||
export const marathonsApi = {
|
||||
list: async (): Promise<MarathonListItem[]> => {
|
||||
const response = await client.get<MarathonListItem[]>('/marathons')
|
||||
@@ -32,7 +34,7 @@ export const marathonsApi = {
|
||||
return response.data
|
||||
},
|
||||
|
||||
update: async (id: number, data: Partial<CreateMarathonData>): Promise<Marathon> => {
|
||||
update: async (id: number, data: MarathonUpdate): Promise<Marathon> => {
|
||||
const response = await client.patch<Marathon>(`/marathons/${id}`, data)
|
||||
return response.data
|
||||
},
|
||||
@@ -78,4 +80,20 @@ export const marathonsApi = {
|
||||
const response = await client.get<LeaderboardEntry[]>(`/marathons/${id}/leaderboard`)
|
||||
return response.data
|
||||
},
|
||||
|
||||
uploadCover: async (id: number, file: File): Promise<Marathon> => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const response = await client.post<Marathon>(`/marathons/${id}/cover`, formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
})
|
||||
return response.data
|
||||
},
|
||||
|
||||
deleteCover: async (id: number): Promise<Marathon> => {
|
||||
const response = await client.delete<Marathon>(`/marathons/${id}/cover`)
|
||||
return response.data
|
||||
},
|
||||
}
|
||||
|
||||
78
frontend/src/components/AnnouncementBanner.tsx
Normal file
78
frontend/src/components/AnnouncementBanner.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { contentApi } from '@/api/admin'
|
||||
import { Megaphone, X } from 'lucide-react'
|
||||
|
||||
const STORAGE_KEY = 'announcement_dismissed'
|
||||
|
||||
export function AnnouncementBanner() {
|
||||
const [content, setContent] = useState<string | null>(null)
|
||||
const [title, setTitle] = useState<string | null>(null)
|
||||
const [updatedAt, setUpdatedAt] = useState<string | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const loadAnnouncement = async () => {
|
||||
try {
|
||||
const data = await contentApi.getPublicContent('announcement')
|
||||
// Check if this announcement was already dismissed (by updated_at)
|
||||
const dismissedAt = localStorage.getItem(STORAGE_KEY)
|
||||
if (dismissedAt === data.updated_at) {
|
||||
setContent(null)
|
||||
} else {
|
||||
setContent(data.content)
|
||||
setTitle(data.title)
|
||||
setUpdatedAt(data.updated_at)
|
||||
}
|
||||
} catch {
|
||||
// No announcement or error - don't show
|
||||
setContent(null)
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
loadAnnouncement()
|
||||
}, [])
|
||||
|
||||
const handleDismiss = () => {
|
||||
if (updatedAt) {
|
||||
// Store the updated_at to know which announcement was dismissed
|
||||
// When admin updates announcement, updated_at changes and banner shows again
|
||||
localStorage.setItem(STORAGE_KEY, updatedAt)
|
||||
setContent(null)
|
||||
}
|
||||
}
|
||||
|
||||
if (isLoading || !content) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative rounded-xl overflow-hidden bg-gradient-to-r from-accent-500/20 via-purple-500/20 to-pink-500/20 border border-accent-500/30">
|
||||
{/* Close button */}
|
||||
<button
|
||||
onClick={handleDismiss}
|
||||
className="absolute top-3 right-3 p-1.5 text-white bg-dark-700/70 hover:bg-dark-600 rounded-lg transition-colors z-10"
|
||||
title="Скрыть"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
{/* Content */}
|
||||
<div className="p-4 pr-12 flex items-start gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-accent-500/20 border border-accent-500/30 flex items-center justify-center flex-shrink-0">
|
||||
<Megaphone className="w-5 h-5 text-accent-400" />
|
||||
</div>
|
||||
<div>
|
||||
{title && (
|
||||
<h3 className="font-semibold text-white mb-1">{title}</h3>
|
||||
)}
|
||||
<div
|
||||
className="text-sm text-gray-300"
|
||||
dangerouslySetInnerHTML={{ __html: content }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ interface BanInfo {
|
||||
|
||||
interface BannedScreenProps {
|
||||
banInfo: BanInfo
|
||||
onLogout?: () => void
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string | null) {
|
||||
@@ -24,8 +25,9 @@ function formatDate(dateStr: string | null) {
|
||||
}) + ' (МСК)'
|
||||
}
|
||||
|
||||
export function BannedScreen({ banInfo }: BannedScreenProps) {
|
||||
const logout = useAuthStore((state) => state.logout)
|
||||
export function BannedScreen({ banInfo, onLogout }: BannedScreenProps) {
|
||||
const storeLogout = useAuthStore((state) => state.logout)
|
||||
const handleLogout = onLogout || storeLogout
|
||||
|
||||
const bannedAtFormatted = formatDate(banInfo.banned_at)
|
||||
const bannedUntilFormatted = formatDate(banInfo.banned_until)
|
||||
@@ -112,7 +114,7 @@ export function BannedScreen({ banInfo }: BannedScreenProps) {
|
||||
<NeonButton
|
||||
variant="secondary"
|
||||
size="lg"
|
||||
onClick={logout}
|
||||
onClick={handleLogout}
|
||||
icon={<LogOut className="w-5 h-5" />}
|
||||
>
|
||||
Выйти из аккаунта
|
||||
|
||||
501
frontend/src/components/MarathonSettingsModal.tsx
Normal file
501
frontend/src/components/MarathonSettingsModal.tsx
Normal file
@@ -0,0 +1,501 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { marathonsApi } from '@/api'
|
||||
import type { Marathon, GameProposalMode } from '@/types'
|
||||
import { NeonButton, Input } from '@/components/ui'
|
||||
import { useToast } from '@/store/toast'
|
||||
import {
|
||||
X, Camera, Trash2, Loader2, Save, Globe, Lock, Users, UserCog, Sparkles, Zap
|
||||
} from 'lucide-react'
|
||||
|
||||
const settingsSchema = z.object({
|
||||
title: z.string().min(1, 'Название обязательно').max(100, 'Максимум 100 символов'),
|
||||
description: z.string().optional(),
|
||||
start_date: z.string().min(1, 'Дата начала обязательна'),
|
||||
is_public: z.boolean(),
|
||||
game_proposal_mode: z.enum(['all_participants', 'organizer_only']),
|
||||
auto_events_enabled: z.boolean(),
|
||||
})
|
||||
|
||||
type SettingsForm = z.infer<typeof settingsSchema>
|
||||
|
||||
interface MarathonSettingsModalProps {
|
||||
marathon: Marathon
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onUpdate: (marathon: Marathon) => void
|
||||
}
|
||||
|
||||
export function MarathonSettingsModal({
|
||||
marathon,
|
||||
isOpen,
|
||||
onClose,
|
||||
onUpdate,
|
||||
}: MarathonSettingsModalProps) {
|
||||
const toast = useToast()
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const [isUploading, setIsUploading] = useState(false)
|
||||
const [isDeleting, setIsDeleting] = useState(false)
|
||||
const [coverPreview, setCoverPreview] = useState<string | null>(null)
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
reset,
|
||||
formState: { errors, isSubmitting, isDirty },
|
||||
} = useForm<SettingsForm>({
|
||||
resolver: zodResolver(settingsSchema),
|
||||
defaultValues: {
|
||||
title: marathon.title,
|
||||
description: marathon.description || '',
|
||||
start_date: marathon.start_date
|
||||
? new Date(marathon.start_date).toISOString().slice(0, 16)
|
||||
: '',
|
||||
is_public: marathon.is_public,
|
||||
game_proposal_mode: marathon.game_proposal_mode as GameProposalMode,
|
||||
auto_events_enabled: marathon.auto_events_enabled,
|
||||
},
|
||||
})
|
||||
|
||||
const isPublic = watch('is_public')
|
||||
const gameProposalMode = watch('game_proposal_mode')
|
||||
const autoEventsEnabled = watch('auto_events_enabled')
|
||||
|
||||
// Reset form when marathon changes
|
||||
useEffect(() => {
|
||||
reset({
|
||||
title: marathon.title,
|
||||
description: marathon.description || '',
|
||||
start_date: marathon.start_date
|
||||
? new Date(marathon.start_date).toISOString().slice(0, 16)
|
||||
: '',
|
||||
is_public: marathon.is_public,
|
||||
game_proposal_mode: marathon.game_proposal_mode as GameProposalMode,
|
||||
auto_events_enabled: marathon.auto_events_enabled,
|
||||
})
|
||||
setCoverPreview(null)
|
||||
}, [marathon, reset])
|
||||
|
||||
// Handle escape key
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && isOpen) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [isOpen, onClose])
|
||||
|
||||
// Prevent body scroll when modal is open
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
document.body.style.overflow = 'hidden'
|
||||
} else {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
return () => {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
const onSubmit = async (data: SettingsForm) => {
|
||||
try {
|
||||
const updated = await marathonsApi.update(marathon.id, {
|
||||
title: data.title,
|
||||
description: data.description || undefined,
|
||||
start_date: new Date(data.start_date).toISOString(),
|
||||
is_public: data.is_public,
|
||||
game_proposal_mode: data.game_proposal_mode,
|
||||
auto_events_enabled: data.auto_events_enabled,
|
||||
})
|
||||
onUpdate(updated)
|
||||
toast.success('Настройки сохранены')
|
||||
onClose()
|
||||
} catch (err: unknown) {
|
||||
const error = err as { response?: { data?: { detail?: string } } }
|
||||
toast.error(error.response?.data?.detail || 'Не удалось сохранить настройки')
|
||||
}
|
||||
}
|
||||
|
||||
const handleCoverClick = () => {
|
||||
fileInputRef.current?.click()
|
||||
}
|
||||
|
||||
const handleCoverChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (!file) return
|
||||
|
||||
if (!file.type.startsWith('image/')) {
|
||||
toast.error('Файл должен быть изображением')
|
||||
return
|
||||
}
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
toast.error('Максимальный размер файла 5 МБ')
|
||||
return
|
||||
}
|
||||
|
||||
// Show preview immediately
|
||||
const previewUrl = URL.createObjectURL(file)
|
||||
setCoverPreview(previewUrl)
|
||||
|
||||
setIsUploading(true)
|
||||
try {
|
||||
const updated = await marathonsApi.uploadCover(marathon.id, file)
|
||||
onUpdate(updated)
|
||||
toast.success('Обложка загружена')
|
||||
} catch (err: unknown) {
|
||||
const error = err as { response?: { data?: { detail?: string } } }
|
||||
toast.error(error.response?.data?.detail || 'Не удалось загрузить обложку')
|
||||
setCoverPreview(null)
|
||||
} finally {
|
||||
setIsUploading(false)
|
||||
// Reset input
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteCover = async () => {
|
||||
setIsDeleting(true)
|
||||
try {
|
||||
const updated = await marathonsApi.deleteCover(marathon.id)
|
||||
onUpdate(updated)
|
||||
setCoverPreview(null)
|
||||
toast.success('Обложка удалена')
|
||||
} catch (err: unknown) {
|
||||
const error = err as { response?: { data?: { detail?: string } } }
|
||||
toast.error(error.response?.data?.detail || 'Не удалось удалить обложку')
|
||||
} finally {
|
||||
setIsDeleting(false)
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const displayCover = coverPreview || marathon.cover_url
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
{/* Backdrop */}
|
||||
<div
|
||||
className="absolute inset-0 bg-black/70 backdrop-blur-sm animate-in fade-in duration-200"
|
||||
onClick={onClose}
|
||||
/>
|
||||
|
||||
{/* Modal */}
|
||||
<div className="relative glass rounded-xl shadow-2xl max-w-2xl w-full max-h-[90vh] overflow-y-auto animate-in zoom-in-95 fade-in duration-200 border border-dark-600 custom-scrollbar">
|
||||
{/* Header */}
|
||||
<div className="sticky top-0 z-10 bg-dark-800/95 backdrop-blur-sm border-b border-dark-600 px-6 py-4 flex items-center justify-between">
|
||||
<h2 className="text-xl font-bold text-white">Настройки марафона</h2>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="text-gray-400 hover:text-white transition-colors p-1"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="p-6 space-y-6">
|
||||
{/* Cover Image */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-3">
|
||||
Обложка марафона
|
||||
</label>
|
||||
<div className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCoverClick}
|
||||
disabled={isUploading || isDeleting}
|
||||
className="relative w-full h-48 rounded-xl overflow-hidden bg-dark-700 border-2 border-dashed border-dark-500 hover:border-neon-500/50 transition-all"
|
||||
>
|
||||
{displayCover ? (
|
||||
<img
|
||||
src={displayCover}
|
||||
alt="Обложка марафона"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex flex-col items-center justify-center text-gray-500">
|
||||
<Camera className="w-10 h-10 mb-2" />
|
||||
<span className="text-sm">Нажмите для загрузки</span>
|
||||
<span className="text-xs text-gray-600 mt-1">JPG, PNG до 5 МБ</span>
|
||||
</div>
|
||||
)}
|
||||
{(isUploading || isDeleting) && (
|
||||
<div className="absolute inset-0 bg-dark-900/80 flex items-center justify-center">
|
||||
<Loader2 className="w-8 h-8 text-neon-500 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
{displayCover && !isUploading && !isDeleting && (
|
||||
<div className="absolute inset-0 bg-dark-900/70 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Camera className="w-8 h-8 text-neon-500" />
|
||||
<span className="ml-2 text-white">Изменить</span>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
{displayCover && !isUploading && !isDeleting && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleDeleteCover}
|
||||
className="absolute top-2 right-2 p-2 rounded-lg bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleCoverChange}
|
||||
className="hidden"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6">
|
||||
{/* Title */}
|
||||
<Input
|
||||
label="Название"
|
||||
placeholder="Введите название марафона"
|
||||
error={errors.title?.message}
|
||||
{...register('title')}
|
||||
/>
|
||||
|
||||
{/* Description */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Описание (необязательно)
|
||||
</label>
|
||||
<textarea
|
||||
className="input min-h-[100px] resize-none w-full"
|
||||
placeholder="Расскажите о вашем марафоне..."
|
||||
{...register('description')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Start date */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Дата начала
|
||||
</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
className="input w-full"
|
||||
{...register('start_date')}
|
||||
/>
|
||||
{errors.start_date && (
|
||||
<p className="text-red-400 text-xs mt-1">{errors.start_date.message}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Marathon type */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-3">
|
||||
Тип марафона
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setValue('is_public', false, { shouldDirty: true })}
|
||||
className={`
|
||||
relative p-4 rounded-xl border-2 transition-all duration-300 text-left group
|
||||
${!isPublic
|
||||
? 'border-neon-500/50 bg-neon-500/10 shadow-[0_0_14px_rgba(34,211,238,0.08)]'
|
||||
: 'border-dark-600 bg-dark-700/50 hover:border-dark-500'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className={`
|
||||
w-10 h-10 rounded-xl mb-3 flex items-center justify-center transition-colors
|
||||
${!isPublic ? 'bg-neon-500/20' : 'bg-dark-600'}
|
||||
`}>
|
||||
<Lock className={`w-5 h-5 ${!isPublic ? 'text-neon-400' : 'text-gray-400'}`} />
|
||||
</div>
|
||||
<div className={`font-semibold mb-1 ${!isPublic ? 'text-white' : 'text-gray-300'}`}>
|
||||
Закрытый
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
Вход только по коду приглашения
|
||||
</div>
|
||||
{!isPublic && (
|
||||
<div className="absolute top-3 right-3">
|
||||
<Sparkles className="w-4 h-4 text-neon-400" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setValue('is_public', true, { shouldDirty: true })}
|
||||
className={`
|
||||
relative p-4 rounded-xl border-2 transition-all duration-300 text-left group
|
||||
${isPublic
|
||||
? 'border-accent-500/50 bg-accent-500/10 shadow-[0_0_14px_rgba(139,92,246,0.08)]'
|
||||
: 'border-dark-600 bg-dark-700/50 hover:border-dark-500'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className={`
|
||||
w-10 h-10 rounded-xl mb-3 flex items-center justify-center transition-colors
|
||||
${isPublic ? 'bg-accent-500/20' : 'bg-dark-600'}
|
||||
`}>
|
||||
<Globe className={`w-5 h-5 ${isPublic ? 'text-accent-400' : 'text-gray-400'}`} />
|
||||
</div>
|
||||
<div className={`font-semibold mb-1 ${isPublic ? 'text-white' : 'text-gray-300'}`}>
|
||||
Открытый
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
Виден всем пользователям
|
||||
</div>
|
||||
{isPublic && (
|
||||
<div className="absolute top-3 right-3">
|
||||
<Sparkles className="w-4 h-4 text-accent-400" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Game proposal mode */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-3">
|
||||
Кто может предлагать игры
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setValue('game_proposal_mode', 'all_participants', { shouldDirty: true })}
|
||||
className={`
|
||||
relative p-4 rounded-xl border-2 transition-all duration-300 text-left
|
||||
${gameProposalMode === 'all_participants'
|
||||
? 'border-neon-500/50 bg-neon-500/10 shadow-[0_0_14px_rgba(34,211,238,0.08)]'
|
||||
: 'border-dark-600 bg-dark-700/50 hover:border-dark-500'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className={`
|
||||
w-10 h-10 rounded-xl mb-3 flex items-center justify-center transition-colors
|
||||
${gameProposalMode === 'all_participants' ? 'bg-neon-500/20' : 'bg-dark-600'}
|
||||
`}>
|
||||
<Users className={`w-5 h-5 ${gameProposalMode === 'all_participants' ? 'text-neon-400' : 'text-gray-400'}`} />
|
||||
</div>
|
||||
<div className={`font-semibold mb-1 ${gameProposalMode === 'all_participants' ? 'text-white' : 'text-gray-300'}`}>
|
||||
Все участники
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
С модерацией организатором
|
||||
</div>
|
||||
{gameProposalMode === 'all_participants' && (
|
||||
<div className="absolute top-3 right-3">
|
||||
<Sparkles className="w-4 h-4 text-neon-400" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setValue('game_proposal_mode', 'organizer_only', { shouldDirty: true })}
|
||||
className={`
|
||||
relative p-4 rounded-xl border-2 transition-all duration-300 text-left
|
||||
${gameProposalMode === 'organizer_only'
|
||||
? 'border-accent-500/50 bg-accent-500/10 shadow-[0_0_14px_rgba(139,92,246,0.08)]'
|
||||
: 'border-dark-600 bg-dark-700/50 hover:border-dark-500'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className={`
|
||||
w-10 h-10 rounded-xl mb-3 flex items-center justify-center transition-colors
|
||||
${gameProposalMode === 'organizer_only' ? 'bg-accent-500/20' : 'bg-dark-600'}
|
||||
`}>
|
||||
<UserCog className={`w-5 h-5 ${gameProposalMode === 'organizer_only' ? 'text-accent-400' : 'text-gray-400'}`} />
|
||||
</div>
|
||||
<div className={`font-semibold mb-1 ${gameProposalMode === 'organizer_only' ? 'text-white' : 'text-gray-300'}`}>
|
||||
Только организатор
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
Без модерации
|
||||
</div>
|
||||
{gameProposalMode === 'organizer_only' && (
|
||||
<div className="absolute top-3 right-3">
|
||||
<Sparkles className="w-4 h-4 text-accent-400" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Auto events toggle */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-3">
|
||||
Автоматические события
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setValue('auto_events_enabled', !autoEventsEnabled, { shouldDirty: true })}
|
||||
className={`
|
||||
w-full p-4 rounded-xl border-2 transition-all duration-300 text-left flex items-center gap-4
|
||||
${autoEventsEnabled
|
||||
? 'border-yellow-500/50 bg-yellow-500/10'
|
||||
: 'border-dark-600 bg-dark-700/50 hover:border-dark-500'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<div className={`
|
||||
w-10 h-10 rounded-xl flex items-center justify-center transition-colors flex-shrink-0
|
||||
${autoEventsEnabled ? 'bg-yellow-500/20' : 'bg-dark-600'}
|
||||
`}>
|
||||
<Zap className={`w-5 h-5 ${autoEventsEnabled ? 'text-yellow-400' : 'text-gray-400'}`} />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<div className={`font-semibold ${autoEventsEnabled ? 'text-white' : 'text-gray-300'}`}>
|
||||
{autoEventsEnabled ? 'Включены' : 'Выключены'}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
Случайные бонусные события во время марафона
|
||||
</div>
|
||||
</div>
|
||||
<div className={`
|
||||
w-12 h-7 rounded-full transition-colors relative flex-shrink-0
|
||||
${autoEventsEnabled ? 'bg-yellow-500' : 'bg-dark-600'}
|
||||
`}>
|
||||
<div className={`
|
||||
absolute top-1 w-5 h-5 rounded-full bg-white shadow transition-transform
|
||||
${autoEventsEnabled ? 'left-6' : 'left-1'}
|
||||
`} />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-3 pt-4 border-t border-dark-600">
|
||||
<NeonButton
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="flex-1"
|
||||
onClick={onClose}
|
||||
>
|
||||
Отмена
|
||||
</NeonButton>
|
||||
<NeonButton
|
||||
type="submit"
|
||||
className="flex-1"
|
||||
isLoading={isSubmitting}
|
||||
disabled={!isDirty}
|
||||
icon={<Save className="w-4 h-4" />}
|
||||
>
|
||||
Сохранить
|
||||
</NeonButton>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useCallback, useMemo } from 'react'
|
||||
import { useState, useCallback, useMemo, useEffect } from 'react'
|
||||
import type { Game } from '@/types'
|
||||
import { Gamepad2, Loader2 } from 'lucide-react'
|
||||
|
||||
@@ -9,27 +9,43 @@ interface SpinWheelProps {
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
const SPIN_DURATION = 5000 // ms
|
||||
const EXTRA_ROTATIONS = 5
|
||||
const SPIN_DURATION = 6000 // ms - увеличено для более плавного замедления
|
||||
const EXTRA_ROTATIONS = 7 // больше оборотов для эффекта инерции
|
||||
|
||||
// Цветовая палитра секторов
|
||||
// Пороги для адаптивного отображения
|
||||
const TEXT_THRESHOLD = 16 // До 16 игр - показываем текст
|
||||
const LINES_THRESHOLD = 40 // До 40 игр - показываем разделители
|
||||
|
||||
// Цветовая палитра секторов (расширенная для большего количества)
|
||||
const SECTOR_COLORS = [
|
||||
{ bg: '#0d9488', border: '#14b8a6' }, // teal
|
||||
{ bg: '#7c3aed', border: '#8b5cf6' }, // violet
|
||||
{ bg: '#0891b2', border: '#06b6d4' }, // cyan
|
||||
{ bg: '#c026d3', border: '#d946ef' }, // fuchsia
|
||||
{ bg: '#059669', border: '#10b981' }, // emerald
|
||||
{ bg: '#7c2d12', border: '#ea580c' }, // orange
|
||||
{ bg: '#ea580c', border: '#f97316' }, // orange
|
||||
{ bg: '#1d4ed8', border: '#3b82f6' }, // blue
|
||||
{ bg: '#be123c', border: '#e11d48' }, // rose
|
||||
{ bg: '#4f46e5', border: '#6366f1' }, // indigo
|
||||
{ bg: '#0284c7', border: '#0ea5e9' }, // sky
|
||||
{ bg: '#9333ea', border: '#a855f7' }, // purple
|
||||
{ bg: '#16a34a', border: '#22c55e' }, // green
|
||||
]
|
||||
|
||||
export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheelProps) {
|
||||
const [isSpinning, setIsSpinning] = useState(false)
|
||||
const [rotation, setRotation] = useState(0)
|
||||
const [displayedGame, setDisplayedGame] = useState<Game | null>(null)
|
||||
const [spinStartTime, setSpinStartTime] = useState<number | null>(null)
|
||||
const [startRotation, setStartRotation] = useState(0)
|
||||
const [targetRotation, setTargetRotation] = useState(0)
|
||||
|
||||
// Размеры колеса
|
||||
const wheelSize = 400
|
||||
// Определяем режим отображения
|
||||
const showText = games.length <= TEXT_THRESHOLD
|
||||
const showLines = games.length <= LINES_THRESHOLD
|
||||
|
||||
// Размеры колеса - увеличиваем для большого количества игр
|
||||
const wheelSize = games.length > 50 ? 450 : games.length > 30 ? 420 : 400
|
||||
const centerX = wheelSize / 2
|
||||
const centerY = wheelSize / 2
|
||||
const radius = wheelSize / 2 - 10
|
||||
@@ -102,11 +118,16 @@ export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheel
|
||||
const fullRotations = EXTRA_ROTATIONS * 360
|
||||
const finalAngle = fullRotations + (360 - targetSectorMidAngle) + baseRotation
|
||||
|
||||
setRotation(rotation + finalAngle)
|
||||
const newRotation = rotation + finalAngle
|
||||
setStartRotation(rotation)
|
||||
setTargetRotation(newRotation)
|
||||
setSpinStartTime(Date.now())
|
||||
setRotation(newRotation)
|
||||
|
||||
// Ждём окончания анимации
|
||||
setTimeout(() => {
|
||||
setIsSpinning(false)
|
||||
setSpinStartTime(null)
|
||||
onSpinComplete(resultGame)
|
||||
}, SPIN_DURATION)
|
||||
}, [isSpinning, disabled, games, rotation, sectorAngle, onSpin, onSpinComplete])
|
||||
@@ -117,13 +138,67 @@ export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheel
|
||||
return text.slice(0, maxLength - 2) + '...'
|
||||
}
|
||||
|
||||
// Функция для вычисления игры под указателем по углу
|
||||
const getGameAtAngle = useCallback((currentRotation: number) => {
|
||||
if (games.length === 0) return null
|
||||
const normalizedRotation = ((currentRotation % 360) + 360) % 360
|
||||
const angleUnderPointer = (360 - normalizedRotation + 360) % 360
|
||||
const sectorIndex = Math.floor(angleUnderPointer / sectorAngle) % games.length
|
||||
return games[sectorIndex] || null
|
||||
}, [games, sectorAngle])
|
||||
|
||||
// Вычисляем игру под указателем (статическое состояние)
|
||||
const currentGameUnderPointer = useMemo(() => {
|
||||
return getGameAtAngle(rotation)
|
||||
}, [rotation, getGameAtAngle])
|
||||
|
||||
// Easing функция для имитации инерции - быстрый старт, долгое замедление
|
||||
// Аппроксимирует CSS cubic-bezier(0.12, 0.9, 0.15, 1)
|
||||
const easeOutExpo = useCallback((t: number): number => {
|
||||
// Экспоненциальное замедление - очень быстро в начале, очень медленно в конце
|
||||
return t === 1 ? 1 : 1 - Math.pow(2, -12 * t)
|
||||
}, [])
|
||||
|
||||
// Отслеживаем позицию во время вращения
|
||||
useEffect(() => {
|
||||
if (!isSpinning || spinStartTime === null) {
|
||||
// Когда не крутится - показываем текущую игру под указателем
|
||||
if (currentGameUnderPointer) {
|
||||
setDisplayedGame(currentGameUnderPointer)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const totalDelta = targetRotation - startRotation
|
||||
|
||||
const updateDisplayedGame = () => {
|
||||
const elapsed = Date.now() - spinStartTime
|
||||
const progress = Math.min(elapsed / SPIN_DURATION, 1)
|
||||
const easedProgress = easeOutExpo(progress)
|
||||
|
||||
// Вычисляем текущий угол на основе прогресса анимации
|
||||
const currentAngle = startRotation + (totalDelta * easedProgress)
|
||||
const game = getGameAtAngle(currentAngle)
|
||||
|
||||
if (game) {
|
||||
setDisplayedGame(game)
|
||||
}
|
||||
}
|
||||
|
||||
// Обновляем каждые 30мс для плавности
|
||||
const interval = setInterval(updateDisplayedGame, 30)
|
||||
updateDisplayedGame() // Сразу обновляем
|
||||
|
||||
return () => clearInterval(interval)
|
||||
}, [isSpinning, spinStartTime, startRotation, targetRotation, getGameAtAngle, currentGameUnderPointer, easeOutExpo])
|
||||
|
||||
// Мемоизируем секторы для производительности
|
||||
const sectors = useMemo(() => {
|
||||
return games.map((game, index) => {
|
||||
const color = SECTOR_COLORS[index % SECTOR_COLORS.length]
|
||||
const path = createSectorPath(index, games.length)
|
||||
const textPos = getTextPosition(index, games.length)
|
||||
const maxTextLength = games.length > 8 ? 10 : games.length > 5 ? 14 : 18
|
||||
const maxTextLength = games.length > 12 ? 8 : games.length > 8 ? 10 : games.length > 5 ? 14 : 18
|
||||
|
||||
return { game, color, path, textPos, maxTextLength }
|
||||
})
|
||||
@@ -213,7 +288,8 @@ export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheel
|
||||
transform: `rotate(${rotation}deg)`,
|
||||
transitionProperty: isSpinning ? 'transform' : 'none',
|
||||
transitionDuration: isSpinning ? `${SPIN_DURATION}ms` : '0ms',
|
||||
transitionTimingFunction: 'cubic-bezier(0.17, 0.67, 0.12, 0.99)',
|
||||
// Инерционное вращение: быстрый старт, долгое плавное замедление
|
||||
transitionTimingFunction: 'cubic-bezier(0.12, 0.9, 0.15, 1)',
|
||||
}}
|
||||
>
|
||||
<defs>
|
||||
@@ -230,38 +306,42 @@ export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheel
|
||||
<path
|
||||
d={path}
|
||||
fill={color.bg}
|
||||
stroke={color.border}
|
||||
strokeWidth="2"
|
||||
stroke={showLines ? color.border : 'transparent'}
|
||||
strokeWidth={showLines ? "1" : "0"}
|
||||
filter="url(#sectorShadow)"
|
||||
/>
|
||||
|
||||
{/* Текст названия игры */}
|
||||
<text
|
||||
x={textPos.x}
|
||||
y={textPos.y}
|
||||
transform={`rotate(${textPos.rotation}, ${textPos.x}, ${textPos.y})`}
|
||||
textAnchor="middle"
|
||||
dominantBaseline="middle"
|
||||
fill="white"
|
||||
fontSize={games.length > 10 ? "10" : games.length > 6 ? "11" : "13"}
|
||||
fontWeight="bold"
|
||||
style={{
|
||||
textShadow: '0 1px 3px rgba(0,0,0,0.8)',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
{truncateText(game.title, maxTextLength)}
|
||||
</text>
|
||||
{/* Текст названия игры - только для небольшого количества */}
|
||||
{showText && (
|
||||
<text
|
||||
x={textPos.x}
|
||||
y={textPos.y}
|
||||
transform={`rotate(${textPos.rotation}, ${textPos.x}, ${textPos.y})`}
|
||||
textAnchor="middle"
|
||||
dominantBaseline="middle"
|
||||
fill="white"
|
||||
fontSize={games.length > 12 ? "9" : games.length > 8 ? "10" : games.length > 6 ? "11" : "13"}
|
||||
fontWeight="bold"
|
||||
style={{
|
||||
textShadow: '0 1px 3px rgba(0,0,0,0.8)',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
>
|
||||
{truncateText(game.title, maxTextLength)}
|
||||
</text>
|
||||
)}
|
||||
|
||||
{/* Разделительная линия */}
|
||||
<line
|
||||
x1={centerX}
|
||||
y1={centerY}
|
||||
x2={centerX + radius * Math.cos((index * sectorAngle - 90) * Math.PI / 180)}
|
||||
y2={centerY + radius * Math.sin((index * sectorAngle - 90) * Math.PI / 180)}
|
||||
stroke="rgba(255,255,255,0.3)"
|
||||
strokeWidth="1"
|
||||
/>
|
||||
{/* Разделительная линия - только для среднего количества */}
|
||||
{showLines && (
|
||||
<line
|
||||
x1={centerX}
|
||||
y1={centerY}
|
||||
x2={centerX + radius * Math.cos((index * sectorAngle - 90) * Math.PI / 180)}
|
||||
y2={centerY + radius * Math.sin((index * sectorAngle - 90) * Math.PI / 180)}
|
||||
stroke="rgba(255,255,255,0.2)"
|
||||
strokeWidth="1"
|
||||
/>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
@@ -322,6 +402,21 @@ export function SpinWheel({ games, onSpin, onSpinComplete, disabled }: SpinWheel
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Название текущей игры (для большого количества) */}
|
||||
{!showText && (
|
||||
<div className="glass rounded-xl px-6 py-3 min-w-[280px] text-center">
|
||||
<p className="text-xs text-gray-500 mb-1">
|
||||
{games.length} игр в колесе
|
||||
</p>
|
||||
<p className={`
|
||||
font-semibold transition-all duration-100 truncate max-w-[280px]
|
||||
${isSpinning ? 'text-neon-400 animate-pulse' : 'text-white'}
|
||||
`}>
|
||||
{displayedGame?.title || 'Крутите колесо!'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Подсказка */}
|
||||
<p className={`
|
||||
text-sm transition-all duration-300
|
||||
|
||||
100
frontend/src/components/TelegramBotBanner.tsx
Normal file
100
frontend/src/components/TelegramBotBanner.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { contentApi } from '@/api/admin'
|
||||
import { NeonButton } from '@/components/ui'
|
||||
import { Bot, Bell, X } from 'lucide-react'
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
const STORAGE_KEY = 'telegram_banner_dismissed'
|
||||
|
||||
// Default content if not configured in admin
|
||||
const DEFAULT_TITLE = 'Привяжите Telegram-бота'
|
||||
const DEFAULT_DESCRIPTION = 'Получайте уведомления о событиях марафона, новых заданиях и результатах прямо в Telegram'
|
||||
|
||||
export function TelegramBotBanner() {
|
||||
const user = useAuthStore((state) => state.user)
|
||||
const [dismissed, setDismissed] = useState(() => {
|
||||
return sessionStorage.getItem(STORAGE_KEY) === 'true'
|
||||
})
|
||||
const [title, setTitle] = useState(DEFAULT_TITLE)
|
||||
const [description, setDescription] = useState(DEFAULT_DESCRIPTION)
|
||||
|
||||
useEffect(() => {
|
||||
const loadContent = async () => {
|
||||
try {
|
||||
const data = await contentApi.getPublicContent('telegram_bot_info')
|
||||
if (data.title) setTitle(data.title)
|
||||
if (data.content) setDescription(data.content)
|
||||
} catch {
|
||||
// Use defaults if content not found
|
||||
}
|
||||
}
|
||||
loadContent()
|
||||
}, [])
|
||||
|
||||
const handleDismiss = () => {
|
||||
sessionStorage.setItem(STORAGE_KEY, 'true')
|
||||
setDismissed(true)
|
||||
}
|
||||
|
||||
// Don't show if user already has Telegram linked or dismissed
|
||||
if (user?.telegram_id || dismissed) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative rounded-2xl overflow-hidden">
|
||||
{/* Background image */}
|
||||
<div
|
||||
className="absolute inset-0 bg-cover bg-center"
|
||||
style={{ backgroundImage: 'url(/telegram_bot_banner.png)' }}
|
||||
/>
|
||||
{/* Overlay */}
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-dark-900/95 via-dark-900/80 to-dark-900/60" />
|
||||
|
||||
{/* Close button */}
|
||||
<button
|
||||
onClick={handleDismiss}
|
||||
className="absolute top-3 right-3 p-1.5 text-white bg-dark-700/70 hover:bg-dark-600 rounded-lg transition-colors z-10"
|
||||
title="Скрыть"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
{/* Content */}
|
||||
<div className="relative p-6 pr-12 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="w-12 h-12 rounded-xl bg-[#2AABEE]/20 border border-[#2AABEE]/30 flex items-center justify-center flex-shrink-0">
|
||||
<Bot className="w-6 h-6 text-[#2AABEE]" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-white mb-1">
|
||||
{title}
|
||||
</h3>
|
||||
<p className="text-gray-400 text-sm max-w-md">
|
||||
{description}
|
||||
</p>
|
||||
<div className="flex items-center gap-4 mt-2 text-xs text-gray-500">
|
||||
<span className="flex items-center gap-1">
|
||||
<Bell className="w-3 h-3" />
|
||||
Мгновенные уведомления
|
||||
</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<Bot className="w-3 h-3" />
|
||||
Удобное управление
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="ml-16 sm:ml-0">
|
||||
<Link to="/profile">
|
||||
<NeonButton color="neon" size="sm">
|
||||
Привязать
|
||||
</NeonButton>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -234,7 +234,13 @@ export function Layout() {
|
||||
Игровой Марафон © {new Date().getFullYear()}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-sm text-gray-500">
|
||||
<div className="flex items-center gap-6 text-sm">
|
||||
<Link to="/terms" className="text-gray-500 hover:text-gray-300 transition-colors">
|
||||
Правила
|
||||
</Link>
|
||||
<Link to="/privacy" className="text-gray-500 hover:text-gray-300 transition-colors">
|
||||
Конфиденциальность
|
||||
</Link>
|
||||
<span className="text-neon-500/50">v1.0</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -67,18 +67,28 @@ export const NeonButton = forwardRef<HTMLButtonElement, NeonButtonProps>(
|
||||
},
|
||||
}
|
||||
|
||||
const sizeClasses = {
|
||||
sm: 'px-3 py-1.5 text-sm gap-1.5',
|
||||
md: 'px-4 py-2.5 text-base gap-2',
|
||||
lg: 'px-6 py-3 text-lg gap-2.5',
|
||||
}
|
||||
|
||||
const iconSizes = {
|
||||
sm: 'w-4 h-4',
|
||||
md: 'w-5 h-5',
|
||||
lg: 'w-6 h-6',
|
||||
}
|
||||
|
||||
const isIconOnly = icon && !children
|
||||
|
||||
const sizeClassesWithText = {
|
||||
sm: 'px-3 py-1.5 text-sm gap-1.5',
|
||||
md: 'px-4 py-2.5 text-base gap-2',
|
||||
lg: 'px-6 py-3 text-lg gap-2.5',
|
||||
}
|
||||
|
||||
const sizeClassesIconOnly = {
|
||||
sm: 'p-2 text-sm',
|
||||
md: 'p-2.5 text-base',
|
||||
lg: 'p-3 text-lg',
|
||||
}
|
||||
|
||||
const sizeClasses = isIconOnly ? sizeClassesIconOnly : sizeClassesWithText
|
||||
|
||||
const colors = colorMap[color]
|
||||
|
||||
return (
|
||||
@@ -118,13 +128,9 @@ export const NeonButton = forwardRef<HTMLButtonElement, NeonButtonProps>(
|
||||
{...props}
|
||||
>
|
||||
{isLoading && <Loader2 className={clsx(iconSizes[size], 'animate-spin')} />}
|
||||
{!isLoading && icon && iconPosition === 'left' && (
|
||||
<span className={iconSizes[size]}>{icon}</span>
|
||||
)}
|
||||
{!isLoading && icon && iconPosition === 'left' && icon}
|
||||
{children}
|
||||
{!isLoading && icon && iconPosition === 'right' && (
|
||||
<span className={iconSizes[size]}>{icon}</span>
|
||||
)}
|
||||
{!isLoading && icon && iconPosition === 'right' && icon}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { useState } from 'react'
|
||||
import { useState, useRef } from 'react'
|
||||
import { useNavigate, Link } from 'react-router-dom'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import { marathonsApi } from '@/api'
|
||||
import { NeonButton, Input, GlassCard } from '@/components/ui'
|
||||
import { Globe, Lock, Users, UserCog, ArrowLeft, Gamepad2, AlertCircle, Sparkles, Calendar, Clock } from 'lucide-react'
|
||||
import { Globe, Lock, Users, UserCog, ArrowLeft, Gamepad2, AlertCircle, Sparkles, Calendar, Clock, Camera, Trash2 } from 'lucide-react'
|
||||
import type { GameProposalMode } from '@/types'
|
||||
import { useToast } from '@/store/toast'
|
||||
|
||||
const createSchema = z.object({
|
||||
title: z.string().min(1, 'Название обязательно').max(100),
|
||||
@@ -21,8 +22,12 @@ type CreateForm = z.infer<typeof createSchema>
|
||||
|
||||
export function CreateMarathonPage() {
|
||||
const navigate = useNavigate()
|
||||
const toast = useToast()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [coverFile, setCoverFile] = useState<File | null>(null)
|
||||
const [coverPreview, setCoverPreview] = useState<string | null>(null)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -42,6 +47,38 @@ export function CreateMarathonPage() {
|
||||
const isPublic = watch('is_public')
|
||||
const gameProposalMode = watch('game_proposal_mode')
|
||||
|
||||
const handleCoverClick = () => {
|
||||
fileInputRef.current?.click()
|
||||
}
|
||||
|
||||
const handleCoverChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0]
|
||||
if (!file) return
|
||||
|
||||
if (!file.type.startsWith('image/')) {
|
||||
toast.error('Файл должен быть изображением')
|
||||
return
|
||||
}
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
toast.error('Максимальный размер файла 5 МБ')
|
||||
return
|
||||
}
|
||||
|
||||
setCoverFile(file)
|
||||
setCoverPreview(URL.createObjectURL(file))
|
||||
}
|
||||
|
||||
const handleRemoveCover = () => {
|
||||
setCoverFile(null)
|
||||
if (coverPreview) {
|
||||
URL.revokeObjectURL(coverPreview)
|
||||
}
|
||||
setCoverPreview(null)
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmit = async (data: CreateForm) => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
@@ -54,6 +91,16 @@ export function CreateMarathonPage() {
|
||||
is_public: data.is_public,
|
||||
game_proposal_mode: data.game_proposal_mode as GameProposalMode,
|
||||
})
|
||||
|
||||
// Upload cover if selected
|
||||
if (coverFile) {
|
||||
try {
|
||||
await marathonsApi.uploadCover(marathon.id, coverFile)
|
||||
} catch {
|
||||
toast.warning('Марафон создан, но не удалось загрузить обложку')
|
||||
}
|
||||
}
|
||||
|
||||
navigate(`/marathons/${marathon.id}/lobby`)
|
||||
} catch (err: unknown) {
|
||||
const apiError = err as { response?: { data?: { detail?: string } } }
|
||||
@@ -94,6 +141,57 @@ export function CreateMarathonPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Cover Image */}
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-300 mb-3">
|
||||
Обложка (необязательно)
|
||||
</label>
|
||||
<div className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleCoverClick}
|
||||
disabled={isLoading}
|
||||
className="relative w-full h-40 rounded-xl overflow-hidden bg-dark-700 border-2 border-dashed border-dark-500 hover:border-neon-500/50 transition-all"
|
||||
>
|
||||
{coverPreview ? (
|
||||
<img
|
||||
src={coverPreview}
|
||||
alt="Обложка марафона"
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex flex-col items-center justify-center text-gray-500">
|
||||
<Camera className="w-8 h-8 mb-2" />
|
||||
<span className="text-sm">Нажмите для загрузки</span>
|
||||
<span className="text-xs text-gray-600 mt-1">JPG, PNG до 5 МБ</span>
|
||||
</div>
|
||||
)}
|
||||
{coverPreview && (
|
||||
<div className="absolute inset-0 bg-dark-900/70 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Camera className="w-6 h-6 text-neon-500" />
|
||||
<span className="ml-2 text-white text-sm">Изменить</span>
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
{coverPreview && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleRemoveCover}
|
||||
className="absolute top-2 right-2 p-2 rounded-lg bg-red-500/20 text-red-400 hover:bg-red-500/30 transition-colors"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleCoverChange}
|
||||
className="hidden"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Basic info */}
|
||||
<div className="space-y-4">
|
||||
<Input
|
||||
|
||||
@@ -6,10 +6,12 @@ import { NeonButton, Input, GlassCard, StatsCard } from '@/components/ui'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useToast } from '@/store/toast'
|
||||
import { useConfirm } from '@/store/confirm'
|
||||
import { fuzzyFilter } from '@/utils/fuzzySearch'
|
||||
import {
|
||||
Plus, Trash2, Sparkles, Play, Loader2, Gamepad2, X, Save, Eye,
|
||||
ChevronDown, ChevronUp, Edit2, Check, CheckCircle, XCircle, Clock, User, ArrowLeft, Zap
|
||||
ChevronDown, ChevronUp, Edit2, Check, CheckCircle, XCircle, Clock, User, ArrowLeft, Zap, Search, Settings
|
||||
} from 'lucide-react'
|
||||
import { MarathonSettingsModal } from '@/components/MarathonSettingsModal'
|
||||
|
||||
export function LobbyPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
@@ -27,9 +29,43 @@ export function LobbyPage() {
|
||||
const [showAddGame, setShowAddGame] = useState(false)
|
||||
const [gameTitle, setGameTitle] = useState('')
|
||||
const [gameUrl, setGameUrl] = useState('')
|
||||
const [gameUrlError, setGameUrlError] = useState<string | null>(null)
|
||||
const [gameGenre, setGameGenre] = useState('')
|
||||
const [isAddingGame, setIsAddingGame] = useState(false)
|
||||
|
||||
const validateUrl = (url: string): boolean => {
|
||||
if (!url.trim()) return true // Empty is ok, will be caught by required check
|
||||
try {
|
||||
const parsed = new URL(url.trim())
|
||||
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
||||
return false
|
||||
}
|
||||
// Check that hostname has at least one dot (domain.tld)
|
||||
const hostname = parsed.hostname
|
||||
if (!hostname || !hostname.includes('.')) {
|
||||
return false
|
||||
}
|
||||
// Check that TLD is valid (2-6 letters only, like com, ru, org, online)
|
||||
const parts = hostname.split('.')
|
||||
const tld = parts[parts.length - 1].toLowerCase()
|
||||
if (tld.length < 2 || tld.length > 6 || !/^[a-z]+$/.test(tld)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const handleGameUrlChange = (value: string) => {
|
||||
setGameUrl(value)
|
||||
if (value.trim() && !validateUrl(value)) {
|
||||
setGameUrlError('Введите корректную ссылку (например: https://store.steampowered.com/...)')
|
||||
} else {
|
||||
setGameUrlError(null)
|
||||
}
|
||||
}
|
||||
|
||||
// Moderation
|
||||
const [moderatingGameId, setModeratingGameId] = useState<number | null>(null)
|
||||
|
||||
@@ -85,6 +121,21 @@ export function LobbyPage() {
|
||||
// Start marathon
|
||||
const [isStarting, setIsStarting] = useState(false)
|
||||
|
||||
// Search
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [generateSearchQuery, setGenerateSearchQuery] = useState('')
|
||||
|
||||
// Games list filters
|
||||
const [filterProposer, setFilterProposer] = useState<number | 'all'>('all')
|
||||
const [filterChallenges, setFilterChallenges] = useState<'all' | 'with' | 'without'>('all')
|
||||
|
||||
// Generation filters
|
||||
const [generateFilterProposer, setGenerateFilterProposer] = useState<number | 'all'>('all')
|
||||
const [generateFilterChallenges, setGenerateFilterChallenges] = useState<'all' | 'with' | 'without'>('all')
|
||||
|
||||
// Settings modal
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
loadData()
|
||||
}, [id])
|
||||
@@ -132,7 +183,7 @@ export function LobbyPage() {
|
||||
}
|
||||
|
||||
const handleAddGame = async () => {
|
||||
if (!id || !gameTitle.trim() || !gameUrl.trim()) return
|
||||
if (!id || !gameTitle.trim() || !gameUrl.trim() || !validateUrl(gameUrl)) return
|
||||
|
||||
setIsAddingGame(true)
|
||||
try {
|
||||
@@ -143,6 +194,7 @@ export function LobbyPage() {
|
||||
})
|
||||
setGameTitle('')
|
||||
setGameUrl('')
|
||||
setGameUrlError(null)
|
||||
setGameGenre('')
|
||||
setShowAddGame(false)
|
||||
await loadData()
|
||||
@@ -501,6 +553,7 @@ export function LobbyPage() {
|
||||
} else {
|
||||
setPreviewChallenges(result.challenges)
|
||||
setShowGenerateSelection(false)
|
||||
setGenerateSearchQuery('')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to generate challenges:', error)
|
||||
@@ -518,10 +571,6 @@ export function LobbyPage() {
|
||||
)
|
||||
}
|
||||
|
||||
const selectAllGamesForGeneration = () => {
|
||||
setSelectedGamesForGeneration(approvedGames.map(g => g.id))
|
||||
}
|
||||
|
||||
const clearGameSelection = () => {
|
||||
setSelectedGamesForGeneration([])
|
||||
}
|
||||
@@ -599,6 +648,22 @@ export function LobbyPage() {
|
||||
const approvedGames = games.filter(g => g.status === 'approved')
|
||||
const totalChallenges = approvedGames.reduce((sum, g) => sum + g.challenges_count, 0)
|
||||
|
||||
// Get unique proposers for generation filter (from approved games)
|
||||
const uniqueProposers = approvedGames.reduce((acc, game) => {
|
||||
if (game.proposed_by && !acc.some(u => u.id === game.proposed_by?.id)) {
|
||||
acc.push(game.proposed_by)
|
||||
}
|
||||
return acc
|
||||
}, [] as { id: number; nickname: string }[])
|
||||
|
||||
// Get unique proposers for games list filter (from all games)
|
||||
const allGamesProposers = games.reduce((acc, game) => {
|
||||
if (game.proposed_by && !acc.some(u => u.id === game.proposed_by?.id)) {
|
||||
acc.push(game.proposed_by)
|
||||
}
|
||||
return acc
|
||||
}, [] as { id: number; nickname: string }[])
|
||||
|
||||
const getStatusBadge = (status: string) => {
|
||||
switch (status) {
|
||||
case 'approved':
|
||||
@@ -798,6 +863,14 @@ export function LobbyPage() {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-gray-400 mb-1 block">Подсказка для пруфа</label>
|
||||
<Input
|
||||
placeholder="Что именно должно быть на скриншоте/видео"
|
||||
value={editChallenge.proof_hint}
|
||||
onChange={(e) => setEditChallenge(prev => ({ ...prev, proof_hint: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<NeonButton
|
||||
size="sm"
|
||||
@@ -846,6 +919,9 @@ export function LobbyPage() {
|
||||
</div>
|
||||
<h5 className="text-sm font-medium text-white">{challenge.title}</h5>
|
||||
<p className="text-xs text-gray-400 mt-1">{challenge.description}</p>
|
||||
{challenge.proof_hint && (
|
||||
<p className="text-xs text-gray-500 mt-1">Пруф: {challenge.proof_hint}</p>
|
||||
)}
|
||||
</div>
|
||||
{isOrganizer && (
|
||||
<div className="flex gap-1 shrink-0">
|
||||
@@ -1045,14 +1121,22 @@ export function LobbyPage() {
|
||||
</div>
|
||||
|
||||
{isOrganizer && (
|
||||
<NeonButton
|
||||
onClick={handleStartMarathon}
|
||||
isLoading={isStarting}
|
||||
disabled={approvedGames.length === 0}
|
||||
icon={<Play className="w-4 h-4" />}
|
||||
>
|
||||
Запустить марафон
|
||||
</NeonButton>
|
||||
<div className="flex gap-2">
|
||||
<NeonButton
|
||||
variant="ghost"
|
||||
onClick={() => setShowSettings(true)}
|
||||
className="!text-gray-400 hover:!bg-dark-600"
|
||||
icon={<Settings className="w-4 h-4" />}
|
||||
/>
|
||||
<NeonButton
|
||||
onClick={handleStartMarathon}
|
||||
isLoading={isStarting}
|
||||
disabled={approvedGames.length === 0}
|
||||
icon={<Play className="w-4 h-4" />}
|
||||
>
|
||||
Запустить марафон
|
||||
</NeonButton>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1181,6 +1265,14 @@ export function LobbyPage() {
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs text-gray-400 mb-1 block">Подсказка для пруфа</label>
|
||||
<Input
|
||||
placeholder="Что именно должно быть на скриншоте/видео"
|
||||
value={editChallenge.proof_hint}
|
||||
onChange={(e) => setEditChallenge(prev => ({ ...prev, proof_hint: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<NeonButton
|
||||
size="sm"
|
||||
@@ -1226,6 +1318,9 @@ export function LobbyPage() {
|
||||
</div>
|
||||
<h4 className="font-medium text-white mb-1">{challenge.title}</h4>
|
||||
<p className="text-sm text-gray-400 mb-2">{challenge.description}</p>
|
||||
{challenge.proof_hint && (
|
||||
<p className="text-xs text-gray-500 mb-2">Пруф: {challenge.proof_hint}</p>
|
||||
)}
|
||||
{challenge.proposed_by && (
|
||||
<p className="text-xs text-gray-500 flex items-center gap-1">
|
||||
<User className="w-3 h-3" /> Предложил: {challenge.proposed_by.nickname}
|
||||
@@ -1304,6 +1399,9 @@ export function LobbyPage() {
|
||||
</div>
|
||||
<h4 className="font-medium text-white mb-1">{challenge.title}</h4>
|
||||
<p className="text-sm text-gray-400">{challenge.description}</p>
|
||||
{challenge.proof_hint && (
|
||||
<p className="text-xs text-gray-500 mt-1">Пруф: {challenge.proof_hint}</p>
|
||||
)}
|
||||
</div>
|
||||
{challenge.status === 'pending' && (
|
||||
<button
|
||||
@@ -1343,6 +1441,9 @@ export function LobbyPage() {
|
||||
onClick={() => {
|
||||
setShowGenerateSelection(false)
|
||||
clearGameSelection()
|
||||
setGenerateSearchQuery('')
|
||||
setGenerateFilterProposer('all')
|
||||
setGenerateFilterChallenges('all')
|
||||
}}
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
@@ -1376,51 +1477,135 @@ export function LobbyPage() {
|
||||
{/* Game selection */}
|
||||
{showGenerateSelection && (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<button
|
||||
onClick={selectAllGamesForGeneration}
|
||||
className="text-neon-400 hover:text-neon-300 transition-colors"
|
||||
>
|
||||
Выбрать все
|
||||
</button>
|
||||
<button
|
||||
onClick={clearGameSelection}
|
||||
className="text-gray-400 hover:text-gray-300 transition-colors"
|
||||
>
|
||||
Снять выбор
|
||||
</button>
|
||||
{/* Search */}
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Поиск игры..."
|
||||
value={generateSearchQuery}
|
||||
onChange={(e) => setGenerateSearchQuery(e.target.value)}
|
||||
className="input w-full pl-10 pr-10 py-2 text-sm"
|
||||
/>
|
||||
{generateSearchQuery && (
|
||||
<button
|
||||
onClick={() => setGenerateSearchQuery('')}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300 transition-colors"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
{approvedGames.map((game) => {
|
||||
const isSelected = selectedGamesForGeneration.includes(game.id)
|
||||
const challengeCount = gameChallenges[game.id]?.length ?? game.challenges_count
|
||||
return (
|
||||
<button
|
||||
key={game.id}
|
||||
onClick={() => toggleGameSelection(game.id)}
|
||||
className={`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${
|
||||
isSelected
|
||||
? 'bg-accent-500/20 border-accent-500/50'
|
||||
: 'bg-dark-700/50 border-dark-600 hover:border-dark-500'
|
||||
}`}
|
||||
>
|
||||
<div className={`w-5 h-5 rounded flex items-center justify-center border-2 transition-colors ${
|
||||
isSelected
|
||||
? 'bg-accent-500 border-accent-500'
|
||||
: 'border-gray-500'
|
||||
}`}>
|
||||
{isSelected && <Check className="w-3 h-3 text-white" />}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-white font-medium truncate">{game.title}</p>
|
||||
<p className="text-xs text-gray-400">
|
||||
{challengeCount > 0 ? `${challengeCount} заданий` : 'Нет заданий'}
|
||||
{/* Filters */}
|
||||
<div className="flex gap-2">
|
||||
<select
|
||||
value={generateFilterProposer === 'all' ? 'all' : generateFilterProposer}
|
||||
onChange={(e) => setGenerateFilterProposer(e.target.value === 'all' ? 'all' : parseInt(e.target.value))}
|
||||
className="input py-2 text-sm flex-1"
|
||||
>
|
||||
<option value="all">Все участники</option>
|
||||
{uniqueProposers.map(u => (
|
||||
<option key={u.id} value={u.id}>{u.nickname}</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={generateFilterChallenges}
|
||||
onChange={(e) => setGenerateFilterChallenges(e.target.value as 'all' | 'with' | 'without')}
|
||||
className="input py-2 text-sm flex-1"
|
||||
>
|
||||
<option value="all">Все игры</option>
|
||||
<option value="with">С заданиями</option>
|
||||
<option value="without">Без заданий</option>
|
||||
</select>
|
||||
</div>
|
||||
{(() => {
|
||||
// Compute filtered games
|
||||
let filteredGames = approvedGames
|
||||
|
||||
// Apply proposer filter
|
||||
if (generateFilterProposer !== 'all') {
|
||||
filteredGames = filteredGames.filter(g => g.proposed_by?.id === generateFilterProposer)
|
||||
}
|
||||
|
||||
// Apply challenges filter
|
||||
if (generateFilterChallenges === 'with') {
|
||||
filteredGames = filteredGames.filter(g => {
|
||||
const count = gameChallenges[g.id]?.length ?? g.challenges_count
|
||||
return count > 0
|
||||
})
|
||||
} else if (generateFilterChallenges === 'without') {
|
||||
filteredGames = filteredGames.filter(g => {
|
||||
const count = gameChallenges[g.id]?.length ?? g.challenges_count
|
||||
return count === 0
|
||||
})
|
||||
}
|
||||
|
||||
// Apply search filter
|
||||
if (generateSearchQuery) {
|
||||
filteredGames = fuzzyFilter(filteredGames, generateSearchQuery, (g) => g.title + ' ' + (g.genre || ''))
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<button
|
||||
onClick={() => setSelectedGamesForGeneration(filteredGames.map(g => g.id))}
|
||||
className="text-neon-400 hover:text-neon-300 transition-colors"
|
||||
>
|
||||
Выбрать все ({filteredGames.length})
|
||||
</button>
|
||||
<button
|
||||
onClick={clearGameSelection}
|
||||
className="text-gray-400 hover:text-gray-300 transition-colors"
|
||||
>
|
||||
Снять выбор
|
||||
</button>
|
||||
</div>
|
||||
<div className="grid gap-2 max-h-64 overflow-y-auto custom-scrollbar">
|
||||
{filteredGames.length === 0 ? (
|
||||
<p className="text-center text-gray-500 py-4 text-sm">
|
||||
Ничего не найдено
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
filteredGames.map((game) => {
|
||||
const isSelected = selectedGamesForGeneration.includes(game.id)
|
||||
const challengeCount = gameChallenges[game.id]?.length ?? game.challenges_count
|
||||
return (
|
||||
<button
|
||||
key={game.id}
|
||||
onClick={() => toggleGameSelection(game.id)}
|
||||
className={`flex items-center gap-3 p-3 rounded-lg border transition-all text-left ${
|
||||
isSelected
|
||||
? 'bg-accent-500/20 border-accent-500/50'
|
||||
: 'bg-dark-700/50 border-dark-600 hover:border-dark-500'
|
||||
}`}
|
||||
>
|
||||
<div className={`w-5 h-5 rounded flex items-center justify-center border-2 transition-colors ${
|
||||
isSelected
|
||||
? 'bg-accent-500 border-accent-500'
|
||||
: 'border-gray-500'
|
||||
}`}>
|
||||
{isSelected && <Check className="w-3 h-3 text-white" />}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-white font-medium truncate">{game.title}</p>
|
||||
{game.proposed_by && (
|
||||
<span className="text-xs text-gray-500 shrink-0">от {game.proposed_by.nickname}</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-gray-400">
|
||||
{challengeCount > 0 ? `${challengeCount} заданий` : 'Нет заданий'}
|
||||
</p>
|
||||
</div>
|
||||
</button>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1574,7 +1759,7 @@ export function LobbyPage() {
|
||||
|
||||
{/* Games list */}
|
||||
<GlassCard>
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-xl bg-neon-500/20 flex items-center justify-center">
|
||||
<Gamepad2 className="w-5 h-5 text-neon-400" />
|
||||
@@ -1592,6 +1777,49 @@ export function LobbyPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Search and filters */}
|
||||
<div className="space-y-3 mb-6">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Поиск игры..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="input w-full pl-10 pr-10"
|
||||
/>
|
||||
{searchQuery && (
|
||||
<button
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300 transition-colors"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<select
|
||||
value={filterProposer === 'all' ? 'all' : filterProposer}
|
||||
onChange={(e) => setFilterProposer(e.target.value === 'all' ? 'all' : parseInt(e.target.value))}
|
||||
className="input py-2 text-sm flex-1"
|
||||
>
|
||||
<option value="all">Все участники</option>
|
||||
{allGamesProposers.map(u => (
|
||||
<option key={u.id} value={u.id}>{u.nickname}</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={filterChallenges}
|
||||
onChange={(e) => setFilterChallenges(e.target.value as 'all' | 'with' | 'without')}
|
||||
className="input py-2 text-sm flex-1"
|
||||
>
|
||||
<option value="all">Все игры</option>
|
||||
<option value="with">С заданиями</option>
|
||||
<option value="without">Без заданий</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Add game form */}
|
||||
{showAddGame && (
|
||||
<div className="mb-6 p-4 glass rounded-xl space-y-3 border border-neon-500/20">
|
||||
@@ -1601,9 +1829,10 @@ export function LobbyPage() {
|
||||
onChange={(e) => setGameTitle(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
placeholder="Ссылка для скачивания"
|
||||
placeholder="Ссылка для скачивания (https://...)"
|
||||
value={gameUrl}
|
||||
onChange={(e) => setGameUrl(e.target.value)}
|
||||
onChange={(e) => handleGameUrlChange(e.target.value)}
|
||||
error={gameUrlError || undefined}
|
||||
/>
|
||||
<Input
|
||||
placeholder="Жанр (необязательно)"
|
||||
@@ -1614,11 +1843,11 @@ export function LobbyPage() {
|
||||
<NeonButton
|
||||
onClick={handleAddGame}
|
||||
isLoading={isAddingGame}
|
||||
disabled={!gameTitle || !gameUrl}
|
||||
disabled={!gameTitle || !gameUrl || !!gameUrlError}
|
||||
>
|
||||
{isOrganizer ? 'Добавить' : 'Предложить'}
|
||||
</NeonButton>
|
||||
<NeonButton variant="outline" onClick={() => setShowAddGame(false)}>
|
||||
<NeonButton variant="outline" onClick={() => { setShowAddGame(false); setGameUrlError(null) }}>
|
||||
Отмена
|
||||
</NeonButton>
|
||||
</div>
|
||||
@@ -1632,26 +1861,69 @@ export function LobbyPage() {
|
||||
|
||||
{/* Games */}
|
||||
{(() => {
|
||||
const visibleGames = isOrganizer
|
||||
let filteredGames = isOrganizer
|
||||
? games.filter(g => g.status !== 'pending')
|
||||
: games.filter(g => g.status === 'approved' || (g.status === 'pending' && g.proposed_by?.id === user?.id))
|
||||
|
||||
return visibleGames.length === 0 ? (
|
||||
// Apply proposer filter
|
||||
if (filterProposer !== 'all') {
|
||||
filteredGames = filteredGames.filter(g => g.proposed_by?.id === filterProposer)
|
||||
}
|
||||
|
||||
// Apply challenges filter
|
||||
if (filterChallenges === 'with') {
|
||||
filteredGames = filteredGames.filter(g => {
|
||||
const count = gameChallenges[g.id]?.length ?? g.challenges_count
|
||||
return count > 0
|
||||
})
|
||||
} else if (filterChallenges === 'without') {
|
||||
filteredGames = filteredGames.filter(g => {
|
||||
const count = gameChallenges[g.id]?.length ?? g.challenges_count
|
||||
return count === 0
|
||||
})
|
||||
}
|
||||
|
||||
// Apply search filter
|
||||
if (searchQuery) {
|
||||
filteredGames = fuzzyFilter(filteredGames, searchQuery, (g) => g.title + ' ' + (g.genre || ''))
|
||||
}
|
||||
|
||||
const hasFilters = searchQuery || filterProposer !== 'all' || filterChallenges !== 'all'
|
||||
|
||||
return filteredGames.length === 0 ? (
|
||||
<div className="text-center py-12">
|
||||
<div className="w-16 h-16 mx-auto mb-4 rounded-2xl bg-dark-700 flex items-center justify-center">
|
||||
<Gamepad2 className="w-8 h-8 text-gray-600" />
|
||||
{hasFilters ? (
|
||||
<Search className="w-8 h-8 text-gray-600" />
|
||||
) : (
|
||||
<Gamepad2 className="w-8 h-8 text-gray-600" />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-gray-400">
|
||||
{isOrganizer ? 'Пока нет игр. Добавьте игры, чтобы начать!' : 'Пока нет одобренных игр. Предложите свою!'}
|
||||
{hasFilters
|
||||
? 'Ничего не найдено по заданным фильтрам'
|
||||
: isOrganizer
|
||||
? 'Пока нет игр. Добавьте игры, чтобы начать!'
|
||||
: 'Пока нет одобренных игр. Предложите свою!'}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{visibleGames.map((game) => renderGameCard(game, false))}
|
||||
{filteredGames.map((game) => renderGameCard(game, false))}
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
</GlassCard>
|
||||
|
||||
{/* Settings Modal */}
|
||||
{marathon && (
|
||||
<MarathonSettingsModal
|
||||
marathon={marathon}
|
||||
isOpen={showSettings}
|
||||
onClose={() => setShowSettings(false)}
|
||||
onUpdate={setMarathon}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ export function LoginPage() {
|
||||
|
||||
navigate('/marathons')
|
||||
} catch {
|
||||
setSubmitError(error || 'Ошибка входа')
|
||||
// Error is already set in store by login function
|
||||
// Ban case is handled separately via banInfo state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useConfirm } from '@/store/confirm'
|
||||
import { EventBanner } from '@/components/EventBanner'
|
||||
import { EventControl } from '@/components/EventControl'
|
||||
import { ActivityFeed, type ActivityFeedRef } from '@/components/ActivityFeed'
|
||||
import { MarathonSettingsModal } from '@/components/MarathonSettingsModal'
|
||||
import {
|
||||
Users, Calendar, Trophy, Play, Settings, Copy, Check, Loader2, Trash2,
|
||||
Globe, Lock, CalendarCheck, UserPlus, Gamepad2, ArrowLeft, Zap, Flag,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
} from 'lucide-react'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import { TelegramBotBanner } from '@/components/TelegramBotBanner'
|
||||
|
||||
export function MarathonPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
@@ -34,6 +36,7 @@ export function MarathonPage() {
|
||||
const [showEventControl, setShowEventControl] = useState(false)
|
||||
const [showChallenges, setShowChallenges] = useState(false)
|
||||
const [expandedGameId, setExpandedGameId] = useState<number | null>(null)
|
||||
const [showSettings, setShowSettings] = useState(false)
|
||||
const activityFeedRef = useRef<ActivityFeedRef>(null)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -189,8 +192,22 @@ export function MarathonPage() {
|
||||
{/* Hero Banner */}
|
||||
<div className="relative rounded-2xl overflow-hidden mb-8">
|
||||
{/* Background */}
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-neon-500/10 via-dark-800 to-accent-500/10" />
|
||||
<div className="absolute inset-0 bg-[linear-gradient(rgba(34,211,238,0.02)_1px,transparent_1px),linear-gradient(90deg,rgba(34,211,238,0.02)_1px,transparent_1px)] bg-[size:50px_50px]" />
|
||||
{marathon.cover_url ? (
|
||||
<>
|
||||
<img
|
||||
src={marathon.cover_url}
|
||||
alt=""
|
||||
className="absolute inset-0 w-full h-full object-cover"
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-r from-dark-900/95 via-dark-900/80 to-dark-900/60" />
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-dark-900/90 to-transparent" />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-neon-500/10 via-dark-800 to-accent-500/10" />
|
||||
<div className="absolute inset-0 bg-[linear-gradient(rgba(34,211,238,0.02)_1px,transparent_1px),linear-gradient(90deg,rgba(34,211,238,0.02)_1px,transparent_1px)] bg-[size:50px_50px]" />
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="relative p-8">
|
||||
<div className="flex flex-col md:flex-row justify-between items-start gap-6">
|
||||
@@ -226,8 +243,8 @@ export function MarathonPage() {
|
||||
|
||||
{marathon.status === 'preparing' && isOrganizer && (
|
||||
<Link to={`/marathons/${id}/lobby`}>
|
||||
<NeonButton variant="secondary" icon={<Settings className="w-4 h-4" />}>
|
||||
Настройка
|
||||
<NeonButton variant="secondary" icon={<Gamepad2 className="w-4 h-4" />}>
|
||||
Игры
|
||||
</NeonButton>
|
||||
</Link>
|
||||
)}
|
||||
@@ -265,6 +282,15 @@ export function MarathonPage() {
|
||||
</button>
|
||||
)}
|
||||
|
||||
{marathon.status === 'preparing' && isOrganizer && (
|
||||
<NeonButton
|
||||
variant="ghost"
|
||||
onClick={() => setShowSettings(true)}
|
||||
className="!text-gray-400 hover:!bg-dark-600"
|
||||
icon={<Settings className="w-4 h-4" />}
|
||||
/>
|
||||
)}
|
||||
|
||||
{canDelete && (
|
||||
<NeonButton
|
||||
variant="ghost"
|
||||
@@ -316,6 +342,9 @@ export function MarathonPage() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Telegram Bot Banner */}
|
||||
<TelegramBotBanner />
|
||||
|
||||
{/* Active event banner */}
|
||||
{marathon.status === 'active' && activeEvent?.event && (
|
||||
<EventBanner activeEvent={activeEvent} onRefresh={refreshEvent} />
|
||||
@@ -529,6 +558,14 @@ export function MarathonPage() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Settings Modal */}
|
||||
<MarathonSettingsModal
|
||||
marathon={marathon}
|
||||
isOpen={showSettings}
|
||||
onClose={() => setShowSettings(false)}
|
||||
onUpdate={setMarathon}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { marathonsApi } from '@/api'
|
||||
import type { MarathonListItem } from '@/types'
|
||||
import { NeonButton, GlassCard, StatsCard } from '@/components/ui'
|
||||
import { Plus, Users, Calendar, Loader2, Trophy, Gamepad2, ChevronRight, Hash, Sparkles } from 'lucide-react'
|
||||
import { TelegramBotBanner } from '@/components/TelegramBotBanner'
|
||||
import { AnnouncementBanner } from '@/components/AnnouncementBanner'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
|
||||
@@ -145,6 +147,16 @@ export function MarathonsPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Announcement Banner */}
|
||||
<div className="mb-4">
|
||||
<AnnouncementBanner />
|
||||
</div>
|
||||
|
||||
{/* Telegram Bot Banner */}
|
||||
<div className="mb-8">
|
||||
<TelegramBotBanner />
|
||||
</div>
|
||||
|
||||
{/* Join marathon */}
|
||||
{showJoinSection && (
|
||||
<GlassCard className="mb-8 animate-slide-in-down" variant="neon">
|
||||
@@ -221,10 +233,20 @@ export function MarathonsPage() {
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-4">
|
||||
{/* Icon */}
|
||||
<div className="w-14 h-14 rounded-xl bg-gradient-to-br from-neon-500/20 to-accent-500/20 flex items-center justify-center border border-neon-500/20 group-hover:border-neon-500/40 transition-colors">
|
||||
<Gamepad2 className="w-7 h-7 text-neon-400" />
|
||||
</div>
|
||||
{/* Cover or Icon */}
|
||||
{marathon.cover_url ? (
|
||||
<div className="w-14 h-14 rounded-xl overflow-hidden border border-dark-500 group-hover:border-neon-500/40 transition-colors flex-shrink-0">
|
||||
<img
|
||||
src={marathon.cover_url}
|
||||
alt={marathon.title}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-14 h-14 rounded-xl bg-gradient-to-br from-neon-500/20 to-accent-500/20 flex items-center justify-center border border-neon-500/20 group-hover:border-neon-500/40 transition-colors flex-shrink-0">
|
||||
<Gamepad2 className="w-7 h-7 text-neon-400" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Info */}
|
||||
<div>
|
||||
|
||||
107
frontend/src/pages/StaticContentPage.tsx
Normal file
107
frontend/src/pages/StaticContentPage.tsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useParams, useLocation, Link } from 'react-router-dom'
|
||||
import { contentApi } from '@/api/admin'
|
||||
import type { StaticContent } from '@/types'
|
||||
import { GlassCard } from '@/components/ui'
|
||||
import { ArrowLeft, Loader2, FileText } from 'lucide-react'
|
||||
|
||||
// Map routes to content keys
|
||||
const ROUTE_KEY_MAP: Record<string, string> = {
|
||||
'/terms': 'terms_of_service',
|
||||
'/privacy': 'privacy_policy',
|
||||
}
|
||||
|
||||
export function StaticContentPage() {
|
||||
const { key: paramKey } = useParams<{ key: string }>()
|
||||
const location = useLocation()
|
||||
const [content, setContent] = useState<StaticContent | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
// Determine content key from route or param
|
||||
const contentKey = ROUTE_KEY_MAP[location.pathname] || paramKey
|
||||
|
||||
useEffect(() => {
|
||||
if (!contentKey) return
|
||||
|
||||
const loadContent = async () => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const data = await contentApi.getPublicContent(contentKey)
|
||||
setContent(data)
|
||||
} catch {
|
||||
setError('Контент не найден')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
loadContent()
|
||||
}, [contentKey])
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-24">
|
||||
<Loader2 className="w-12 h-12 animate-spin text-neon-500 mb-4" />
|
||||
<p className="text-gray-400">Загрузка...</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (error || !content) {
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto">
|
||||
<GlassCard className="text-center py-16">
|
||||
<div className="w-20 h-20 mx-auto mb-6 rounded-2xl bg-dark-700 flex items-center justify-center">
|
||||
<FileText className="w-10 h-10 text-gray-600" />
|
||||
</div>
|
||||
<h3 className="text-xl font-semibold text-white mb-2">Страница не найдена</h3>
|
||||
<p className="text-gray-400 mb-6">Запрашиваемый контент не существует</p>
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex items-center gap-2 text-neon-400 hover:text-neon-300 transition-colors"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4" />
|
||||
На главную
|
||||
</Link>
|
||||
</GlassCard>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-3xl mx-auto">
|
||||
<Link
|
||||
to="/"
|
||||
className="inline-flex items-center gap-2 text-gray-400 hover:text-neon-400 mb-6 transition-colors group"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4 group-hover:-translate-x-1 transition-transform" />
|
||||
На главную
|
||||
</Link>
|
||||
|
||||
<GlassCard>
|
||||
<h1 className="text-2xl md:text-3xl font-bold text-white mb-6">{content.title}</h1>
|
||||
<div
|
||||
className="prose prose-invert prose-gray max-w-none
|
||||
prose-headings:text-white prose-headings:font-semibold
|
||||
prose-p:text-gray-300 prose-p:leading-relaxed
|
||||
prose-a:text-neon-400 prose-a:no-underline hover:prose-a:text-neon-300
|
||||
prose-strong:text-white
|
||||
prose-ul:text-gray-300 prose-ol:text-gray-300
|
||||
prose-li:marker:text-gray-500
|
||||
prose-hr:border-dark-600 prose-hr:my-6
|
||||
prose-img:rounded-xl prose-img:shadow-lg"
|
||||
dangerouslySetInnerHTML={{ __html: content.content }}
|
||||
/>
|
||||
<div className="mt-8 pt-6 border-t border-dark-600 text-sm text-gray-500">
|
||||
Последнее обновление: {new Date(content.updated_at).toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
})}
|
||||
</div>
|
||||
</GlassCard>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,7 +3,8 @@ import { adminApi } from '@/api'
|
||||
import type { StaticContent } from '@/types'
|
||||
import { useToast } from '@/store/toast'
|
||||
import { NeonButton } from '@/components/ui'
|
||||
import { FileText, Plus, Pencil, X, Save, Code } from 'lucide-react'
|
||||
import { FileText, Plus, Pencil, X, Save, Code, Trash2 } from 'lucide-react'
|
||||
import { useConfirm } from '@/store/confirm'
|
||||
|
||||
function formatDate(dateStr: string) {
|
||||
return new Date(dateStr).toLocaleString('ru-RU', {
|
||||
@@ -28,6 +29,7 @@ export function AdminContentPage() {
|
||||
const [formContent, setFormContent] = useState('')
|
||||
|
||||
const toast = useToast()
|
||||
const confirm = useConfirm()
|
||||
|
||||
useEffect(() => {
|
||||
loadContents()
|
||||
@@ -101,6 +103,30 @@ export function AdminContentPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (content: StaticContent) => {
|
||||
const confirmed = await confirm({
|
||||
title: 'Удалить контент?',
|
||||
message: `Вы уверены, что хотите удалить "${content.title}"? Это действие нельзя отменить.`,
|
||||
confirmText: 'Удалить',
|
||||
cancelText: 'Отмена',
|
||||
variant: 'danger',
|
||||
})
|
||||
|
||||
if (!confirmed) return
|
||||
|
||||
try {
|
||||
await adminApi.deleteContent(content.key)
|
||||
setContents(contents.filter(c => c.id !== content.id))
|
||||
if (editing?.id === content.id) {
|
||||
handleCancel()
|
||||
}
|
||||
toast.success('Контент удалён')
|
||||
} catch (err) {
|
||||
console.error('Failed to delete content:', err)
|
||||
toast.error('Ошибка удаления')
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-64">
|
||||
@@ -155,15 +181,28 @@ export function AdminContentPage() {
|
||||
{content.content.replace(/<[^>]*>/g, '').slice(0, 100)}...
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleEdit(content)
|
||||
}}
|
||||
className="p-2 text-gray-400 hover:text-accent-400 hover:bg-accent-500/10 rounded-lg transition-colors ml-3"
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</button>
|
||||
<div className="flex items-center gap-1 ml-3">
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleEdit(content)
|
||||
}}
|
||||
className="p-2 text-gray-400 hover:text-accent-400 hover:bg-accent-500/10 rounded-lg transition-colors"
|
||||
title="Редактировать"
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
handleDelete(content)
|
||||
}}
|
||||
className="p-2 text-gray-400 hover:text-red-400 hover:bg-red-500/10 rounded-lg transition-colors"
|
||||
title="Удалить"
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-4 pt-3 border-t border-dark-600">
|
||||
Обновлено: {formatDate(content.updated_at)}
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { AdminUser, UserRole } from '@/types'
|
||||
import { useToast } from '@/store/toast'
|
||||
import { useConfirm } from '@/store/confirm'
|
||||
import { NeonButton } from '@/components/ui'
|
||||
import { Search, Ban, UserCheck, Shield, ShieldOff, ChevronLeft, ChevronRight, Users, X } from 'lucide-react'
|
||||
import { Search, Ban, UserCheck, Shield, ShieldOff, ChevronLeft, ChevronRight, Users, X, KeyRound } from 'lucide-react'
|
||||
|
||||
export function AdminUsersPage() {
|
||||
const [users, setUsers] = useState<AdminUser[]>([])
|
||||
@@ -17,6 +17,9 @@ export function AdminUsersPage() {
|
||||
const [banDuration, setBanDuration] = useState<string>('permanent')
|
||||
const [banCustomDate, setBanCustomDate] = useState('')
|
||||
const [banning, setBanning] = useState(false)
|
||||
const [resetPasswordUser, setResetPasswordUser] = useState<AdminUser | null>(null)
|
||||
const [newPassword, setNewPassword] = useState('')
|
||||
const [resettingPassword, setResettingPassword] = useState(false)
|
||||
|
||||
const toast = useToast()
|
||||
const confirm = useConfirm()
|
||||
@@ -120,6 +123,24 @@ export function AdminUsersPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetPassword = async () => {
|
||||
if (!resetPasswordUser || !newPassword.trim() || newPassword.length < 6) return
|
||||
|
||||
setResettingPassword(true)
|
||||
try {
|
||||
const updated = await adminApi.resetUserPassword(resetPasswordUser.id, newPassword)
|
||||
setUsers(users.map(u => u.id === updated.id ? updated : u))
|
||||
toast.success(`Пароль ${updated.nickname} сброшен`)
|
||||
setResetPasswordUser(null)
|
||||
setNewPassword('')
|
||||
} catch (err) {
|
||||
console.error('Failed to reset password:', err)
|
||||
toast.error('Ошибка сброса пароля')
|
||||
} finally {
|
||||
setResettingPassword(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Header */}
|
||||
@@ -265,6 +286,14 @@ export function AdminUsersPage() {
|
||||
<Shield className="w-4 h-4" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={() => setResetPasswordUser(user)}
|
||||
className="p-2 text-yellow-400 hover:bg-yellow-500/20 rounded-lg transition-colors"
|
||||
title="Сбросить пароль"
|
||||
>
|
||||
<KeyRound className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -393,6 +422,71 @@ export function AdminUsersPage() {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Reset Password Modal */}
|
||||
{resetPasswordUser && (
|
||||
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||
<div className="glass rounded-2xl p-6 max-w-md w-full mx-4 border border-dark-600 shadow-2xl">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h3 className="text-lg font-semibold text-white flex items-center gap-2">
|
||||
<KeyRound className="w-5 h-5 text-yellow-400" />
|
||||
Сбросить пароль {resetPasswordUser.nickname}
|
||||
</h3>
|
||||
<button
|
||||
onClick={() => {
|
||||
setResetPasswordUser(null)
|
||||
setNewPassword('')
|
||||
}}
|
||||
className="p-1.5 text-gray-400 hover:text-white rounded-lg hover:bg-dark-600/50 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mb-6">
|
||||
<label className="block text-sm font-medium text-gray-300 mb-2">
|
||||
Новый пароль
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
placeholder="Минимум 6 символов"
|
||||
className="w-full bg-dark-700/50 border border-dark-600 rounded-xl px-4 py-2.5 text-white placeholder:text-gray-500 focus:outline-none focus:border-accent-500/50 transition-colors"
|
||||
/>
|
||||
{newPassword && newPassword.length < 6 && (
|
||||
<p className="mt-2 text-sm text-red-400">Пароль должен быть минимум 6 символов</p>
|
||||
)}
|
||||
{resetPasswordUser.telegram_id && (
|
||||
<p className="mt-2 text-sm text-gray-400">
|
||||
Пользователь получит уведомление в Telegram о смене пароля
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 justify-end">
|
||||
<NeonButton
|
||||
variant="ghost"
|
||||
onClick={() => {
|
||||
setResetPasswordUser(null)
|
||||
setNewPassword('')
|
||||
}}
|
||||
>
|
||||
Отмена
|
||||
</NeonButton>
|
||||
<NeonButton
|
||||
color="neon"
|
||||
onClick={handleResetPassword}
|
||||
disabled={!newPassword.trim() || newPassword.length < 6 || resettingPassword}
|
||||
isLoading={resettingPassword}
|
||||
icon={<KeyRound className="w-4 h-4" />}
|
||||
>
|
||||
Сбросить
|
||||
</NeonButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { persist } from 'zustand/middleware'
|
||||
import type { User } from '@/types'
|
||||
import { authApi, type RegisterData, type LoginData } from '@/api/auth'
|
||||
|
||||
let syncPromise: Promise<void> | null = null
|
||||
|
||||
interface Pending2FA {
|
||||
sessionId: number
|
||||
}
|
||||
@@ -41,6 +43,7 @@ interface AuthState {
|
||||
bumpAvatarVersion: () => void
|
||||
setBanned: (banInfo: BanInfo) => void
|
||||
clearBanned: () => void
|
||||
syncUser: () => Promise<void>
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
@@ -57,7 +60,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
banInfo: null,
|
||||
|
||||
login: async (data) => {
|
||||
set({ isLoading: true, error: null, pending2FA: null })
|
||||
set({ isLoading: true, error: null, pending2FA: null, banInfo: null })
|
||||
try {
|
||||
const response = await authApi.login(data)
|
||||
|
||||
@@ -82,9 +85,34 @@ export const useAuthStore = create<AuthState>()(
|
||||
}
|
||||
return { requires2FA: false }
|
||||
} catch (err: unknown) {
|
||||
const error = err as { response?: { data?: { detail?: string } } }
|
||||
const error = err as { response?: { status?: number; data?: { detail?: string | BanInfo } } }
|
||||
|
||||
// Check if user is banned (403 with ban info)
|
||||
if (error.response?.status === 403) {
|
||||
const detail = error.response?.data?.detail
|
||||
if (typeof detail === 'object' && detail !== null && 'banned_at' in detail) {
|
||||
set({
|
||||
banInfo: detail as BanInfo,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
})
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
// Regular error - translate common messages
|
||||
let errorMessage = 'Ошибка входа'
|
||||
const detail = error.response?.data?.detail
|
||||
if (typeof detail === 'string') {
|
||||
if (detail === 'Incorrect login or password') {
|
||||
errorMessage = 'Неверный логин или пароль'
|
||||
} else {
|
||||
errorMessage = detail
|
||||
}
|
||||
}
|
||||
|
||||
set({
|
||||
error: error.response?.data?.detail || 'Login failed',
|
||||
error: errorMessage,
|
||||
isLoading: false,
|
||||
})
|
||||
throw err
|
||||
@@ -145,6 +173,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
|
||||
logout: () => {
|
||||
localStorage.removeItem('token')
|
||||
sessionStorage.removeItem('telegram_banner_dismissed')
|
||||
set({
|
||||
user: null,
|
||||
token: null,
|
||||
@@ -181,6 +210,27 @@ export const useAuthStore = create<AuthState>()(
|
||||
clearBanned: () => {
|
||||
set({ banInfo: null })
|
||||
},
|
||||
|
||||
syncUser: async () => {
|
||||
if (!get().isAuthenticated || !get().token) return
|
||||
|
||||
// Prevent duplicate sync calls
|
||||
if (syncPromise) return syncPromise
|
||||
|
||||
syncPromise = (async () => {
|
||||
try {
|
||||
const userData = await authApi.me()
|
||||
set({ user: userData })
|
||||
} catch {
|
||||
// Token invalid - logout
|
||||
get().logout()
|
||||
} finally {
|
||||
syncPromise = null
|
||||
}
|
||||
})()
|
||||
|
||||
return syncPromise
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage',
|
||||
|
||||
@@ -63,6 +63,7 @@ export interface Marathon {
|
||||
is_public: boolean
|
||||
game_proposal_mode: GameProposalMode
|
||||
auto_events_enabled: boolean
|
||||
cover_url: string | null
|
||||
start_date: string | null
|
||||
end_date: string | null
|
||||
participants_count: number
|
||||
@@ -76,6 +77,7 @@ export interface MarathonListItem {
|
||||
title: string
|
||||
status: MarathonStatus
|
||||
is_public: boolean
|
||||
cover_url: string | null
|
||||
participants_count: number
|
||||
start_date: string | null
|
||||
end_date: string | null
|
||||
@@ -90,11 +92,21 @@ export interface MarathonCreate {
|
||||
game_proposal_mode: GameProposalMode
|
||||
}
|
||||
|
||||
export interface MarathonUpdate {
|
||||
title?: string
|
||||
description?: string
|
||||
start_date?: string
|
||||
is_public?: boolean
|
||||
game_proposal_mode?: GameProposalMode
|
||||
auto_events_enabled?: boolean
|
||||
}
|
||||
|
||||
export interface MarathonPublicInfo {
|
||||
id: number
|
||||
title: string
|
||||
description: string | null
|
||||
status: MarathonStatus
|
||||
cover_url: string | null
|
||||
participants_count: number
|
||||
creator_nickname: string
|
||||
}
|
||||
|
||||
123
frontend/src/utils/fuzzySearch.ts
Normal file
123
frontend/src/utils/fuzzySearch.ts
Normal file
@@ -0,0 +1,123 @@
|
||||
// Keyboard layout mapping (RU -> EN and EN -> RU)
|
||||
const ruToEn: Record<string, string> = {
|
||||
'й': 'q', 'ц': 'w', 'у': 'e', 'к': 'r', 'е': 't', 'н': 'y', 'г': 'u', 'ш': 'i', 'щ': 'o', 'з': 'p',
|
||||
'ф': 'a', 'ы': 's', 'в': 'd', 'а': 'f', 'п': 'g', 'р': 'h', 'о': 'j', 'л': 'k', 'д': 'l',
|
||||
'я': 'z', 'ч': 'x', 'с': 'c', 'м': 'v', 'и': 'b', 'т': 'n', 'ь': 'm',
|
||||
'х': '[', 'ъ': ']', 'ж': ';', 'э': "'", 'б': ',', 'ю': '.',
|
||||
}
|
||||
|
||||
const enToRu: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(ruToEn).map(([ru, en]) => [en, ru])
|
||||
)
|
||||
|
||||
function convertLayout(text: string): string {
|
||||
return text
|
||||
.split('')
|
||||
.map(char => {
|
||||
const lower = char.toLowerCase()
|
||||
const converted = ruToEn[lower] || enToRu[lower] || char
|
||||
return char === lower ? converted : converted.toUpperCase()
|
||||
})
|
||||
.join('')
|
||||
}
|
||||
|
||||
function levenshteinDistance(a: string, b: string): number {
|
||||
const matrix: number[][] = []
|
||||
|
||||
for (let i = 0; i <= b.length; i++) {
|
||||
matrix[i] = [i]
|
||||
}
|
||||
for (let j = 0; j <= a.length; j++) {
|
||||
matrix[0][j] = j
|
||||
}
|
||||
|
||||
for (let i = 1; i <= b.length; i++) {
|
||||
for (let j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1]
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1, // substitution
|
||||
matrix[i][j - 1] + 1, // insertion
|
||||
matrix[i - 1][j] + 1 // deletion
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matrix[b.length][a.length]
|
||||
}
|
||||
|
||||
export interface FuzzyMatch<T> {
|
||||
item: T
|
||||
score: number
|
||||
}
|
||||
|
||||
export function fuzzySearch<T>(
|
||||
items: T[],
|
||||
query: string,
|
||||
getSearchField: (item: T) => string
|
||||
): FuzzyMatch<T>[] {
|
||||
if (!query.trim()) {
|
||||
return items.map(item => ({ item, score: 1 }))
|
||||
}
|
||||
|
||||
const normalizedQuery = query.toLowerCase().trim()
|
||||
const convertedQuery = convertLayout(normalizedQuery)
|
||||
|
||||
const results: FuzzyMatch<T>[] = []
|
||||
|
||||
for (const item of items) {
|
||||
const field = getSearchField(item).toLowerCase()
|
||||
|
||||
// Exact substring match - highest score
|
||||
if (field.includes(normalizedQuery)) {
|
||||
results.push({ item, score: 1 })
|
||||
continue
|
||||
}
|
||||
|
||||
// Converted layout match
|
||||
if (field.includes(convertedQuery)) {
|
||||
results.push({ item, score: 0.95 })
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if query matches start of words
|
||||
const words = field.split(/\s+/)
|
||||
const queryWords = normalizedQuery.split(/\s+/)
|
||||
const startsWithMatch = queryWords.every(qw =>
|
||||
words.some(w => w.startsWith(qw))
|
||||
)
|
||||
if (startsWithMatch) {
|
||||
results.push({ item, score: 0.9 })
|
||||
continue
|
||||
}
|
||||
|
||||
// Levenshtein distance for typo tolerance
|
||||
const distance = levenshteinDistance(normalizedQuery, field)
|
||||
const maxLen = Math.max(normalizedQuery.length, field.length)
|
||||
const similarity = 1 - distance / maxLen
|
||||
|
||||
// Also check against converted query
|
||||
const convertedDistance = levenshteinDistance(convertedQuery, field)
|
||||
const convertedSimilarity = 1 - convertedDistance / maxLen
|
||||
|
||||
const bestSimilarity = Math.max(similarity, convertedSimilarity)
|
||||
|
||||
// Only include if similarity is reasonable (> 40%)
|
||||
if (bestSimilarity > 0.4) {
|
||||
results.push({ item, score: bestSimilarity * 0.8 })
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by score descending
|
||||
return results.sort((a, b) => b.score - a.score)
|
||||
}
|
||||
|
||||
export function fuzzyFilter<T>(
|
||||
items: T[],
|
||||
query: string,
|
||||
getSearchField: (item: T) => string
|
||||
): T[] {
|
||||
return fuzzySearch(items, query, getSearchField).map(r => r.item)
|
||||
}
|
||||
@@ -90,13 +90,14 @@ def get_latency_history(service_name: str, hours: int = 24) -> list[dict]:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
since = datetime.now() - timedelta(hours=hours)
|
||||
since = datetime.utcnow() - timedelta(hours=hours)
|
||||
# Use strftime format to match SQLite CURRENT_TIMESTAMP format (no 'T')
|
||||
cursor.execute("""
|
||||
SELECT latency_ms, status, checked_at
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ? AND latency_ms IS NOT NULL
|
||||
ORDER BY checked_at ASC
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
@@ -116,14 +117,14 @@ def get_uptime_stats(service_name: str, hours: int = 24) -> dict:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
since = datetime.now() - timedelta(hours=hours)
|
||||
since = datetime.utcnow() - timedelta(hours=hours)
|
||||
|
||||
cursor.execute("""
|
||||
SELECT COUNT(*) as total,
|
||||
SUM(CASE WHEN status = 'operational' THEN 1 ELSE 0 END) as successful
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ?
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
row = cursor.fetchone()
|
||||
conn.close()
|
||||
@@ -143,12 +144,12 @@ def get_avg_latency(service_name: str, hours: int = 24) -> Optional[float]:
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
since = datetime.now() - timedelta(hours=hours)
|
||||
since = datetime.utcnow() - timedelta(hours=hours)
|
||||
cursor.execute("""
|
||||
SELECT AVG(latency_ms) as avg_latency
|
||||
FROM metrics
|
||||
WHERE service_name = ? AND checked_at > ? AND latency_ms IS NOT NULL
|
||||
""", (service_name, since.isoformat()))
|
||||
""", (service_name, since.strftime("%Y-%m-%d %H:%M:%S")))
|
||||
|
||||
row = cursor.fetchone()
|
||||
conn.close()
|
||||
@@ -231,7 +232,7 @@ def save_ssl_info(domain: str, issuer: str, expires_at: datetime, days_until_exp
|
||||
INSERT OR REPLACE INTO ssl_certificates
|
||||
(domain, issuer, expires_at, days_until_expiry, checked_at)
|
||||
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||
""", (domain, issuer, expires_at.isoformat(), days_until_expiry))
|
||||
""", (domain, issuer, expires_at.strftime("%Y-%m-%d %H:%M:%S"), days_until_expiry))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -249,12 +250,12 @@ def get_ssl_info(domain: str) -> Optional[dict]:
|
||||
return None
|
||||
|
||||
|
||||
def cleanup_old_metrics(days: int = 1):
|
||||
"""Delete metrics older than specified days (default: 24 hours)."""
|
||||
def cleanup_old_metrics(hours: int = 24):
|
||||
"""Delete metrics older than specified hours (default: 24 hours)."""
|
||||
conn = get_connection()
|
||||
cursor = conn.cursor()
|
||||
cutoff = datetime.now() - timedelta(days=days)
|
||||
cursor.execute("DELETE FROM metrics WHERE checked_at < ?", (cutoff.isoformat(),))
|
||||
cutoff = datetime.utcnow() - timedelta(hours=hours)
|
||||
cursor.execute("DELETE FROM metrics WHERE checked_at < ?", (cutoff.strftime("%Y-%m-%d %H:%M:%S"),))
|
||||
deleted = cursor.rowcount
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -9,7 +9,7 @@ from fastapi import FastAPI, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from monitors import ServiceMonitor
|
||||
from monitors import ServiceMonitor, Status
|
||||
from database import init_db, get_recent_incidents, get_latency_history, cleanup_old_metrics
|
||||
|
||||
|
||||
@@ -19,52 +19,91 @@ FRONTEND_URL = os.getenv("FRONTEND_URL", "http://frontend:80")
|
||||
BOT_URL = os.getenv("BOT_URL", "http://bot:8080")
|
||||
EXTERNAL_URL = os.getenv("EXTERNAL_URL", "") # Public URL for external checks
|
||||
PUBLIC_URL = os.getenv("PUBLIC_URL", "") # Public HTTPS URL for SSL checks
|
||||
CHECK_INTERVAL = int(os.getenv("CHECK_INTERVAL", "600")) # 10 minutes
|
||||
CHECK_INTERVAL = int(os.getenv("CHECK_INTERVAL", "60")) # Normal interval (1 minute)
|
||||
FAST_CHECK_INTERVAL = int(os.getenv("FAST_CHECK_INTERVAL", "5")) # Fast interval when issues detected
|
||||
STARTUP_GRACE_PERIOD = int(os.getenv("STARTUP_GRACE_PERIOD", "60")) # Wait before alerting after startup
|
||||
|
||||
# Initialize monitor
|
||||
monitor = ServiceMonitor()
|
||||
startup_time: Optional[datetime] = None # Track when service started
|
||||
|
||||
# Background task reference
|
||||
background_task: Optional[asyncio.Task] = None
|
||||
cleanup_task: Optional[asyncio.Task] = None
|
||||
|
||||
|
||||
def has_issues() -> bool:
|
||||
"""Check if any monitored service has issues."""
|
||||
for name, svc in monitor.services.items():
|
||||
# Skip external if not configured
|
||||
if name == "external" and svc.status == Status.UNKNOWN:
|
||||
continue
|
||||
if svc.status in (Status.DOWN, Status.DEGRADED):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
async def periodic_health_check():
|
||||
"""Background task to check services periodically."""
|
||||
"""Background task to check services periodically with adaptive polling."""
|
||||
while True:
|
||||
try:
|
||||
# Suppress alerts during startup grace period
|
||||
suppress_alerts = is_in_grace_period()
|
||||
if suppress_alerts:
|
||||
remaining = STARTUP_GRACE_PERIOD - (datetime.now() - startup_time).total_seconds()
|
||||
print(f"Grace period: {remaining:.0f}s remaining (alerts suppressed)")
|
||||
|
||||
await monitor.check_all_services(
|
||||
backend_url=BACKEND_URL,
|
||||
frontend_url=FRONTEND_URL,
|
||||
bot_url=BOT_URL,
|
||||
external_url=EXTERNAL_URL,
|
||||
public_url=PUBLIC_URL
|
||||
public_url=PUBLIC_URL,
|
||||
suppress_alerts=suppress_alerts
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Health check error: {e}")
|
||||
await asyncio.sleep(CHECK_INTERVAL)
|
||||
|
||||
# Adaptive polling: check more frequently when issues detected
|
||||
if has_issues():
|
||||
await asyncio.sleep(FAST_CHECK_INTERVAL)
|
||||
else:
|
||||
await asyncio.sleep(CHECK_INTERVAL)
|
||||
|
||||
|
||||
async def periodic_cleanup():
|
||||
"""Background task to cleanup old metrics (hourly)."""
|
||||
"""Background task to cleanup old metrics (runs immediately, then hourly)."""
|
||||
while True:
|
||||
await asyncio.sleep(3600) # 1 hour
|
||||
try:
|
||||
deleted = cleanup_old_metrics(days=1) # Keep only last 24 hours
|
||||
print(f"Cleaned up {deleted} old metrics")
|
||||
deleted = cleanup_old_metrics(hours=24) # Keep only last 24 hours
|
||||
if deleted > 0:
|
||||
print(f"Cleaned up {deleted} old metrics")
|
||||
except Exception as e:
|
||||
print(f"Cleanup error: {e}")
|
||||
await asyncio.sleep(3600) # Wait 1 hour before next cleanup
|
||||
|
||||
|
||||
def is_in_grace_period() -> bool:
|
||||
"""Check if we're still in startup grace period."""
|
||||
if startup_time is None:
|
||||
return True
|
||||
elapsed = (datetime.now() - startup_time).total_seconds()
|
||||
return elapsed < STARTUP_GRACE_PERIOD
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Startup and shutdown events."""
|
||||
global background_task, cleanup_task
|
||||
global background_task, cleanup_task, startup_time
|
||||
|
||||
# Initialize database
|
||||
init_db()
|
||||
print("Database initialized")
|
||||
|
||||
# Mark startup time
|
||||
startup_time = datetime.now()
|
||||
print(f"Startup grace period: {STARTUP_GRACE_PERIOD}s (no alerts until services stabilize)")
|
||||
|
||||
# Start background health checks
|
||||
background_task = asyncio.create_task(periodic_health_check())
|
||||
cleanup_task = asyncio.create_task(periodic_cleanup())
|
||||
@@ -91,12 +130,20 @@ templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def status_page(request: Request):
|
||||
async def status_page(request: Request, period: int = 24):
|
||||
"""Main status page."""
|
||||
services = monitor.get_all_statuses()
|
||||
# Validate period (1, 12, or 24 hours)
|
||||
if period not in (1, 12, 24):
|
||||
period = 24
|
||||
|
||||
services = monitor.get_all_statuses(period_hours=period)
|
||||
overall_status = monitor.get_overall_status()
|
||||
ssl_status = monitor.get_ssl_status()
|
||||
incidents = get_recent_incidents(limit=5)
|
||||
fast_mode = has_issues()
|
||||
current_interval = FAST_CHECK_INTERVAL if fast_mode else CHECK_INTERVAL
|
||||
grace_period_active = is_in_grace_period()
|
||||
grace_period_remaining = max(0, STARTUP_GRACE_PERIOD - (datetime.now() - startup_time).total_seconds()) if startup_time else 0
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"index.html",
|
||||
@@ -107,7 +154,11 @@ async def status_page(request: Request):
|
||||
"ssl_status": ssl_status,
|
||||
"incidents": incidents,
|
||||
"last_check": monitor.last_check,
|
||||
"check_interval": CHECK_INTERVAL
|
||||
"check_interval": current_interval,
|
||||
"fast_mode": fast_mode,
|
||||
"grace_period_active": grace_period_active,
|
||||
"grace_period_remaining": int(grace_period_remaining),
|
||||
"period": period
|
||||
}
|
||||
)
|
||||
|
||||
@@ -118,13 +169,15 @@ async def api_status():
|
||||
services = monitor.get_all_statuses()
|
||||
overall_status = monitor.get_overall_status()
|
||||
ssl_status = monitor.get_ssl_status()
|
||||
current_interval = FAST_CHECK_INTERVAL if has_issues() else CHECK_INTERVAL
|
||||
|
||||
return {
|
||||
"overall_status": overall_status.value,
|
||||
"services": {name: status.to_dict() for name, status in services.items()},
|
||||
"ssl": ssl_status,
|
||||
"last_check": monitor.last_check.isoformat() if monitor.last_check else None,
|
||||
"check_interval_seconds": CHECK_INTERVAL
|
||||
"check_interval_seconds": current_interval,
|
||||
"fast_mode": has_issues()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -184,7 +184,8 @@ class ServiceMonitor:
|
||||
self,
|
||||
service_name: str,
|
||||
result: tuple,
|
||||
now: datetime
|
||||
now: datetime,
|
||||
suppress_alerts: bool = False
|
||||
):
|
||||
"""Process check result with DB persistence and alerting."""
|
||||
if isinstance(result, Exception):
|
||||
@@ -221,13 +222,14 @@ class ServiceMonitor:
|
||||
if stats["total_checks"] > 0:
|
||||
svc.uptime_percent = stats["uptime_percent"]
|
||||
|
||||
# Handle incident tracking and alerting
|
||||
# Handle incident tracking and alerting (skip alerts during grace period)
|
||||
if is_down and not was_down:
|
||||
# Service just went down
|
||||
svc.last_incident = now
|
||||
incident_id = create_incident(service_name, status.value, message)
|
||||
await alert_service_down(service_name, svc.display_name, message)
|
||||
mark_incident_notified(incident_id)
|
||||
if not suppress_alerts:
|
||||
await alert_service_down(service_name, svc.display_name, message)
|
||||
mark_incident_notified(incident_id)
|
||||
|
||||
elif not is_down and was_down:
|
||||
# Service recovered
|
||||
@@ -236,7 +238,8 @@ class ServiceMonitor:
|
||||
started_at = datetime.fromisoformat(open_incident["started_at"])
|
||||
downtime_minutes = int((now - started_at).total_seconds() / 60)
|
||||
resolve_incident(service_name)
|
||||
await alert_service_recovered(service_name, svc.display_name, downtime_minutes)
|
||||
if not suppress_alerts:
|
||||
await alert_service_recovered(service_name, svc.display_name, downtime_minutes)
|
||||
|
||||
async def check_all_services(
|
||||
self,
|
||||
@@ -244,7 +247,8 @@ class ServiceMonitor:
|
||||
frontend_url: str,
|
||||
bot_url: str,
|
||||
external_url: str = "",
|
||||
public_url: str = ""
|
||||
public_url: str = "",
|
||||
suppress_alerts: bool = False
|
||||
):
|
||||
"""Check all services concurrently."""
|
||||
now = datetime.now()
|
||||
@@ -262,7 +266,7 @@ class ServiceMonitor:
|
||||
# Process results
|
||||
service_names = ["backend", "database", "frontend", "bot", "external"]
|
||||
for i, service_name in enumerate(service_names):
|
||||
await self._process_check_result(service_name, results[i], now)
|
||||
await self._process_check_result(service_name, results[i], now, suppress_alerts)
|
||||
|
||||
# Check SSL certificate (if public URL is HTTPS)
|
||||
if public_url and public_url.startswith("https://"):
|
||||
@@ -270,7 +274,15 @@ class ServiceMonitor:
|
||||
|
||||
self.last_check = now
|
||||
|
||||
def get_all_statuses(self) -> dict[str, ServiceStatus]:
|
||||
def get_all_statuses(self, period_hours: int = 24) -> dict[str, ServiceStatus]:
|
||||
"""Get all service statuses with data for specified period."""
|
||||
# Update historical data for requested period
|
||||
for name, svc in self.services.items():
|
||||
svc.latency_history = get_latency_history(name, hours=period_hours)
|
||||
svc.avg_latency_24h = get_avg_latency(name, hours=period_hours)
|
||||
stats = get_uptime_stats(name, hours=period_hours)
|
||||
if stats["total_checks"] > 0:
|
||||
svc.uptime_percent = stats["uptime_percent"]
|
||||
return self.services
|
||||
|
||||
def get_overall_status(self) -> Status:
|
||||
|
||||
@@ -107,6 +107,32 @@
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.fast-mode-badge {
|
||||
display: inline-block;
|
||||
margin-left: 8px;
|
||||
padding: 2px 8px;
|
||||
background: rgba(250, 204, 21, 0.15);
|
||||
border: 1px solid rgba(250, 204, 21, 0.3);
|
||||
border-radius: 12px;
|
||||
color: #facc15;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
.grace-period-badge {
|
||||
display: inline-block;
|
||||
margin-left: 8px;
|
||||
padding: 2px 8px;
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
border: 1px solid rgba(59, 130, 246, 0.3);
|
||||
border-radius: 12px;
|
||||
color: #3b82f6;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
.services-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
@@ -347,6 +373,37 @@
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.period-selector {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.period-btn {
|
||||
padding: 8px 16px;
|
||||
background: rgba(30, 41, 59, 0.5);
|
||||
border: 1px solid rgba(100, 116, 139, 0.3);
|
||||
border-radius: 8px;
|
||||
color: #94a3b8;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.period-btn:hover {
|
||||
border-color: rgba(0, 212, 255, 0.3);
|
||||
color: #e2e8f0;
|
||||
}
|
||||
|
||||
.period-btn.active {
|
||||
background: linear-gradient(135deg, rgba(0, 212, 255, 0.2), rgba(168, 85, 247, 0.2));
|
||||
border-color: rgba(0, 212, 255, 0.5);
|
||||
color: #00d4ff;
|
||||
}
|
||||
|
||||
.refresh-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -424,9 +481,21 @@
|
||||
Checking services...
|
||||
{% endif %}
|
||||
• Auto-refresh every {{ check_interval }}s
|
||||
{% if grace_period_active %}
|
||||
<span class="grace-period-badge">🚀 Startup ({{ grace_period_remaining }}s)</span>
|
||||
{% elif fast_mode %}
|
||||
<span class="fast-mode-badge">⚡ Fast Mode</span>
|
||||
{% endif %}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<!-- Period Selector -->
|
||||
<div class="period-selector">
|
||||
<a href="?period=1" class="period-btn {% if period == 1 %}active{% endif %}">1 час</a>
|
||||
<a href="?period=12" class="period-btn {% if period == 12 %}active{% endif %}">12 часов</a>
|
||||
<a href="?period=24" class="period-btn {% if period == 24 %}active{% endif %}">24 часа</a>
|
||||
</div>
|
||||
|
||||
{% if ssl_status %}
|
||||
<div class="ssl-card {% if ssl_status.days_until_expiry <= 0 %}danger{% elif ssl_status.days_until_expiry <= 14 %}warning{% endif %}">
|
||||
<div class="ssl-header">
|
||||
@@ -491,7 +560,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<div class="metric-label">Avg 24h</div>
|
||||
<div class="metric-label">Avg {{ period }}h</div>
|
||||
<div class="metric-value {% if service.avg_latency_24h and service.avg_latency_24h < 200 %}good{% elif service.avg_latency_24h and service.avg_latency_24h < 500 %}warning{% elif service.avg_latency_24h %}bad{% endif %}">
|
||||
{% if service.avg_latency_24h %}
|
||||
{{ "%.0f"|format(service.avg_latency_24h) }} ms
|
||||
@@ -501,7 +570,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="metric">
|
||||
<div class="metric-label">Uptime 24h</div>
|
||||
<div class="metric-label">Uptime {{ period }}h</div>
|
||||
<div class="metric-value {% if service.uptime_percent >= 99 %}good{% elif service.uptime_percent >= 95 %}warning{% else %}bad{% endif %}">
|
||||
{{ "%.1f"|format(service.uptime_percent) }}%
|
||||
</div>
|
||||
@@ -620,13 +689,29 @@
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
// Save scroll position before unload
|
||||
window.addEventListener('beforeunload', () => {
|
||||
sessionStorage.setItem('scrollPos', window.scrollY.toString());
|
||||
});
|
||||
|
||||
// Restore scroll position on load
|
||||
window.addEventListener('load', () => {
|
||||
const scrollPos = sessionStorage.getItem('scrollPos');
|
||||
if (scrollPos) {
|
||||
window.scrollTo(0, parseInt(scrollPos));
|
||||
}
|
||||
});
|
||||
|
||||
async function refreshStatus(btn) {
|
||||
btn.classList.add('loading');
|
||||
btn.disabled = true;
|
||||
|
||||
try {
|
||||
await fetch('/api/refresh', { method: 'POST' });
|
||||
window.location.reload();
|
||||
// Preserve period parameter on reload
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('period', '{{ period }}');
|
||||
window.location.href = url.toString();
|
||||
} catch (e) {
|
||||
console.error('Refresh failed:', e);
|
||||
btn.classList.remove('loading');
|
||||
@@ -634,9 +719,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh page
|
||||
// Auto-refresh page (preserve period parameter)
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('period', '{{ period }}');
|
||||
window.location.href = url.toString();
|
||||
}, {{ check_interval }} * 1000);
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user