## Major Achievements ✅ ### Story 1.14: 前端事件画廊页面 - Gallery Page Implementation - ✅ Protected /gallery route with authentication redirect - ✅ Infinite scroll with React Query + Intersection Observer - ✅ Responsive event cards with thumbnail, date, location - ✅ Loading states, empty states, error handling - ✅ Dark theme UI consistent with design system ### Full-Stack Integration Testing Framework - ✅ Docker-based test environment (PostgreSQL + LocalStack) - ✅ E2E tests with Playwright (authentication, gallery workflows) - ✅ API integration tests covering complete user journeys - ✅ Automated test data generation and cleanup - ✅ Performance and concurrency testing ### Technical Stack Validation - ✅ Next.js 15 + React Query + TypeScript frontend - ✅ NestJS + TypeORM + PostgreSQL backend - ✅ AWS S3/SQS integration (LocalStack for testing) - ✅ JWT authentication with secure token management - ✅ Complete data pipeline: Edge → Backend → Processing → Gallery ## Files Added/Modified ### Frontend Implementation - src/app/gallery/page.tsx - Main gallery page with auth protection - src/services/events.ts - API client for events with pagination - src/hooks/use-events.ts - React Query hooks for infinite scroll - src/components/gallery/ - Modular UI components (EventCard, GalleryGrid, States) - src/contexts/query-provider.tsx - React Query configuration ### Testing Infrastructure - docker-compose.test.yml - Complete test environment setup - test-setup.sh - One-command test environment initialization - test-data/seed-test-data.js - Automated test data generation - e2e/gallery.spec.ts - Comprehensive E2E gallery tests - test/integration.e2e-spec.ts - Full-stack workflow validation - TESTING.md - Complete testing guide and documentation ### Project Configuration - package.json (root) - Monorepo scripts and workspace management - playwright.config.ts - E2E testing configuration - .env.test - Test environment variables - README.md - Project documentation ## Test Results 📊 - ✅ Unit Tests: 10/10 passing (Frontend components) - ✅ Integration Tests: Full workflow validation - ✅ E2E Tests: Complete user journey coverage - ✅ Lint: No warnings or errors - ✅ Build: Production ready (11.7kB gallery page) ## Milestone: Epic 1 "First Light" Achieved 🚀 The complete data flow is now validated: 1. User Authentication ✅ 2. Device Registration ✅ 3. Event Upload Pipeline ✅ 4. Background Processing ✅ 5. Gallery Display ✅ This establishes the foundation for all future development. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
5.9 KiB
Meteor Edge Client
A Rust-based command-line client for registering and managing edge devices in the Meteor IoT platform.
Overview
The Meteor Edge Client enables edge devices (like Raspberry Pi) to securely register themselves with user accounts through JWT authentication. Once registered, devices can upload data to the platform and be managed remotely.
Features
- Hardware ID Detection: Automatically extracts unique hardware identifiers from
/proc/cpuinfo,/etc/machine-id, or falls back to hostname+MAC address - JWT Authentication: Secure registration using JWT tokens from the web interface
- Configuration Persistence: Stores registration state in TOML format
- Registration Prevention: Prevents duplicate registrations
- Health Checking: Validates backend connectivity
- Cross-platform: Works on Linux ARM systems (Raspberry Pi) and development machines
Installation
Prerequisites
- Rust 1.70+ (2021 edition)
- Network connectivity to the Meteor backend
Build from Source
# Clone the repository
git clone <repository-url>
cd meteor-edge-client
# Build the application
cargo build --release
# The binary will be available at target/release/meteor-edge-client
Usage
Commands
1. Check Device Status
./meteor-edge-client status
Shows hardware ID, registration status, and configuration file location.
2. Register Device
./meteor-edge-client register <JWT_TOKEN>
Registers the device with the backend using a JWT token from the web interface.
Optional parameters:
--api-url <URL>: Specify backend API URL (default: http://localhost:3000)
3. Health Check
./meteor-edge-client health [--api-url <URL>]
Verifies connectivity to the backend API.
4. Version Information
./meteor-edge-client version
Registration Workflow
- User Authentication: User logs into the web interface
- Token Generation: User obtains a JWT token from their profile
- Device Registration: User SSHs into the edge device and runs:
./meteor-edge-client register <JWT_TOKEN> - Automatic Prevention: Subsequent registration attempts are blocked
Configuration
The client stores configuration in a TOML file at:
- Linux:
/etc/meteor-client/config.toml(system-wide) - User:
~/.config/meteor-client/config.toml(user-specific) - Fallback:
./meteor-client-config.toml(local directory)
Configuration Format
registered = true
hardware_id = "CPU_00000000a1b2c3d4"
registered_at = "2023-07-30T12:00:00Z"
user_profile_id = "user-uuid-here"
device_id = "device-uuid-here"
Hardware ID Sources
The client attempts to extract hardware IDs in this order:
- CPU Serial (from
/proc/cpuinfo) - Most reliable on Raspberry Pi - Machine ID (from
/etc/machine-id) - Systemd systems - Fallback (hostname + MAC address) - Last resort
API Integration
Backend Requirements
The client expects the backend to provide:
GET /health- Health check endpointPOST /api/v1/devices/register- Device registration endpoint
Authentication
Requests to the registration endpoint include:
Authorization: Bearer <JWT_TOKEN>
Content-Type: application/json
{
"hardwareId": "CPU_00000000a1b2c3d4"
}
Response Format
Successful registration returns:
{
"message": "Device registered successfully",
"device": {
"id": "device-uuid",
"userProfileId": "user-uuid",
"hardwareId": "CPU_00000000a1b2c3d4",
"status": "active",
"registeredAt": "2023-07-30T12:00:00Z"
}
}
Error Handling
The client handles various error scenarios:
- Invalid JWT tokens: Clear error messages about authentication failure
- Already registered devices: Prevents duplicate registration attempts
- Network connectivity: Timeout and connection error handling
- Missing backend: Health check failures with helpful diagnostics
- Permission issues: Configuration file write permission errors
Development
Running Tests
# Run all unit tests
cargo test
# Run with output
cargo test -- --nocapture
Integration Testing
# Run the demo integration test
./demo_integration_test.sh
Module Structure
src/main.rs- CLI application and command handlingsrc/hardware.rs- Hardware ID extraction logicsrc/api.rs- HTTP client for backend communicationsrc/config.rs- Configuration file management
Production Deployment
System Service Setup
For production deployment, consider setting up a systemd service:
[Unit]
Description=Meteor Edge Client
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/meteor-edge-client status
User=meteor
Group=meteor
[Install]
WantedBy=multi-user.target
Permissions
The client may require elevated permissions to:
- Read hardware information from
/proc/cpuinfo - Write configuration files to
/etc/meteor-client/
Security Considerations
- JWT tokens should be transmitted securely (HTTPS in production)
- Configuration files contain sensitive device information
- Network communications should use TLS in production environments
Troubleshooting
Common Issues
-
"Could not read hardware ID"
- Ensure the device has accessible hardware identifiers
- Check file permissions on
/proc/cpuinfoand/etc/machine-id
-
"Failed to reach backend"
- Verify network connectivity
- Check backend URL and port
- Ensure backend service is running
-
"Device already registered"
- This is expected behavior after successful registration
- Use
statuscommand to check current registration state
-
Configuration file errors
- Check write permissions in the config directory
- Verify disk space availability
Debug Mode
For additional debugging information, check the verbose output when running commands.
License
[Specify your license here]
Contributing
[Contribution guidelines if applicable]