Perspective Submission Service
This module implements the perspective submission service for VoxPop, allowing users to submit perspectives on issues with rate limiting and security measures for unverified users.
Design
The system is built around the following components:
- PerspectiveService: Handles the business logic for perspective submissions
- PerspectiveHandler: Exposes the HTTP API endpoint
- Rate Limiting: Uses Redis for tracking submission counts
API Endpoints
Submit Perspective
Endpoint: POST /submit-perspective
Request Body:
{
"issueId": "issue-12345",
"text": "This is my perspective on the issue.",
"fileURL": "http://example.com/document.pdf",
"userAddress": "0x1234567890abcdef",
"isVerified": false,
"captchaToken": "valid-token"
}
Response:
{
"success": true,
"hash": "QmHash123issu"
}
Features
Text Validation
- Maximum text length: 1000 characters
- Sanitizes input to prevent injection attacks
File Validation
- Maximum file size: 5MB
- Currently mocked in the implementation
Unverified Users
- Limited to 5 submissions per day
- Must provide a valid CAPTCHA token
- Error response if rate limit exceeded:
{ "success": false, "error": "Rate limit exceeded. Maximum 5 submissions per day for unverified users." }
IPFS Storage
- Uploads content to IPFS via Pinata (currently mocked)
- Returns an IPFS hash for the content
Configuration
The service requires Redis for rate limiting:
REDIS_ADDR
: Redis server address (default: "localhost:6379")REDIS_PASSWORD
: Redis password (default: "")REDIS_DB
: Redis database number (default: 0)
Example Usage
Verified User
// Request
{
"issueId": "issue-12345",
"text": "This is my perspective on the issue.",
"fileURL": "http://example.com/document.pdf",
"userAddress": "0x1234567890abcdef",
"isVerified": true
}
// Response
{
"success": true,
"hash": "QmHash123issu"
}
Unverified User (with CAPTCHA)
// Request
{
"issueId": "issue-12345",
"text": "This is my perspective on the issue.",
"userAddress": "0x1234567890abcdef",
"isVerified": false,
"captchaToken": "valid-token"
}
// Response
{
"success": true,
"hash": "QmHash123issu"
}
Rate Limit Exceeded
// Response (HTTP 429)
{
"success": false,
"error": "Rate limit exceeded. Maximum 5 submissions per day for unverified users."
}
Testing
Run the tests with:
go test ./perspective