128 lines
2.5 KiB
Markdown
128 lines
2.5 KiB
Markdown
![]() |
# 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:
|
||
|
|
||
|
1. **PerspectiveService**: Handles the business logic for perspective submissions
|
||
|
2. **PerspectiveHandler**: Exposes the HTTP API endpoint
|
||
|
3. **Rate Limiting**: Uses Redis for tracking submission counts
|
||
|
|
||
|
## API Endpoints
|
||
|
|
||
|
### Submit Perspective
|
||
|
|
||
|
**Endpoint**: `POST /submit-perspective`
|
||
|
|
||
|
**Request Body**:
|
||
|
```json
|
||
|
{
|
||
|
"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**:
|
||
|
```json
|
||
|
{
|
||
|
"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:
|
||
|
```json
|
||
|
{
|
||
|
"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
|
||
|
|
||
|
```json
|
||
|
// 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)
|
||
|
|
||
|
```json
|
||
|
// 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
|
||
|
|
||
|
```json
|
||
|
// Response (HTTP 429)
|
||
|
{
|
||
|
"success": false,
|
||
|
"error": "Rate limit exceeded. Maximum 5 submissions per day for unverified users."
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Testing
|
||
|
|
||
|
Run the tests with:
|
||
|
|
||
|
```bash
|
||
|
go test ./perspective
|
||
|
```
|