@@ -46,6 +46,8 @@ This is a Node.js backend for the Treegens video upload application that uploads
4646 ipfsHash: String (required, unique), // S3 ETag/upload hash
4747 videoCID: String (required, unique), // Actual IPFS CID for gateways
4848 uploadTimestamp: Date (default: now), // Upload timestamp
49+ type: String (required, enum: [' before' , ' after' ]), // Video type for comparison
50+ userId: String (required, indexed), // User identifier (or wallet address)
4951 gpsCoordinates: {
5052 latitude: Number (required, - 90 to 90 ),
5153 longitude: Number (required, - 180 to 180 )
@@ -57,10 +59,29 @@ This is a Node.js backend for the Treegens video upload application that uploads
5759- ` { uploadTimestamp: -1 } ` - For chronological queries
5860- ` { ipfsHash: 1 } ` - For lookup by upload hash
5961- ` { videoCID: 1 } ` - For lookup by IPFS CID
62+ - ` { userId: 1 } ` - For user-specific video queries
6063
6164## API Endpoints
6265
63- ### Upload Video
66+ ### Root Endpoint
67+ ```
68+ GET /
69+ Response: Basic API information (name, version, status, timestamp)
70+ ```
71+
72+ ### Health Endpoints
73+ ```
74+ GET /health
75+ Response: Comprehensive health status of all services (MongoDB, Filebase)
76+ Status codes: 200 (OK), 503 (DEGRADED), 500 (UNHEALTHY)
77+
78+ GET /health/s3-test
79+ Response: Filebase S3 connection test with status and timestamp
80+ ```
81+
82+ ### Video Management Endpoints
83+
84+ #### Upload Video
6485```
6586POST /api/videos/upload
6687Content-Type: multipart/form-data
@@ -70,6 +91,7 @@ Fields:
7091- userId: String (required) - User identifier
7192- latitude: Number (required) - GPS latitude
7293- longitude: Number (required) - GPS longitude
94+ - type: String (required) - 'before' or 'after'
7395
7496Response:
7597{
@@ -80,180 +102,52 @@ Response:
80102 "videoCID": "QmXXXXXX...",
81103 "filebaseUrl": "https://...",
82104 "publicUrl": "https://ipfs.io/ipfs/QmXXXXXX...",
83- "uploadTimestamp": "2025-07-15T12:05:16.169Z"
105+ "uploadTimestamp": "2025-07-15T12:05:16.169Z",
106+ "type": "before"
84107 }
85108}
86109```
87110
88- ### Get Video by ID
111+ #### Get Videos by User
89112```
90- GET /api/videos/:videoId
113+ GET /api/videos/user/:userId?page=1&limit=10
91114
92115Response:
93116{
94- "message": "Video metadata retrieved successfully",
117+ "message": "User videos retrieved successfully",
95118 "data": {
96- "originalFilename": "video.mp4",
97- "ipfsHash": "upload_hash",
98- "videoCID": "QmXXXXXX...",
99- "gpsCoordinates": {
100- "latitude": 37.7749,
101- "longitude": -122.4194
102- },
103- "uploadTimestamp": "2025-07-15T12:05:16.169Z"
119+ "videos": [
120+ {
121+ "videoId": "ObjectId",
122+ "videoCID": "QmXXXXXX...",
123+ "type": "before",
124+ "uploadTimestamp": "2025-07-15T12:05:16.169Z"
125+ },
126+ {
127+ "videoId": "ObjectId",
128+ "videoCID": "QmYYYYYY...",
129+ "type": "after",
130+ "uploadTimestamp": "2025-07-20T15:30:45.123Z"
131+ }
132+ ],
133+ "pagination": {
134+ "page": 1,
135+ "limit": 10,
136+ "total": 2
137+ }
104138 }
105139}
106140```
107141
108- ### Health Check
109- ```
110- GET /health
111- GET /health/s3-test
112- ```
113-
114- ## Key Implementation Details
115-
116- ### IPFS CID Extraction
117- The system properly distinguishes between:
118- - ** ipfsHash** : S3 ETag from upload (internal reference)
119- - ** videoCID** : Actual IPFS CID extracted from ` x-amz-meta-cid ` header
120-
121- Implementation in ` config/filebase.js ` :
122- ``` javascript
123- // After upload, get CID from metadata
124- const headCommand = new HeadObjectCommand ({
125- Bucket: env .FILEBASE_BUCKET_NAME ,
126- Key: fileName
127- });
128-
129- const headResult = await s3Client .send (headCommand);
130- const videoCID = headResult .Metadata ? .cid || null ;
131- ` ` `
132-
133- ### AWS SDK v3 Migration
134- Successfully migrated from AWS SDK v2 to v3:
135- - Uses command-based approach
136- - Proper error handling with ` $metadata`
137- - Eliminated deprecation warnings
138-
139- ### File Upload Configuration
140- - **Storage**: Memory storage via Multer
141- - **File Size Limit**: 100MB
142- - **Allowed Types**: Video files only
143- - **Validation**: MIME type and extension checking
144-
145- ### Error Handling
146- - Duplicate upload detection (graceful handling)
147- - Rate limiting with retry logic (100 RPS Filebase limit)
148- - Comprehensive error logging
149- - Validation with Joi
150-
151- ## Environment Variables
152- ` ` `
153- PORT = 5000
154- NODE_ENV = development
155- MONGODB_URI = mongodb: // localhost:27017/treegens
156- FILEBASE_ACCESS_KEY = your_access_key
157- FILEBASE_SECRET_KEY = your_secret_key
158- FILEBASE_BUCKET_NAME = your_bucket_name
159- FILEBASE_IPFS_API_KEY = your_api_key
160- ```
161-
162- ## Database Migrations
163-
164- ### Migration System
165- The project includes a comprehensive migration system to ensure schema consistency:
166-
167- ** Files:**
168- - ` config/migrations.js ` - Migration definitions and runner
169- - ` scripts/migrate.js ` - CLI tool for manual migration management
170-
171- ** Commands:**
172- ``` bash
173- npm run migrate # Run pending migrations
174- npm run migrate:down # Rollback last migration
175- npm run migrate:status # Show migration status
176- ```
177-
178- ### Schema Validation
179- MongoDB collection is created with strict schema validation:
180- - ** Validation Level** : Strict (all inserts/updates must pass validation)
181- - ** Validation Action** : Error (reject invalid documents)
182- - ** Required Fields** : All fields in the Video schema are enforced
183- - ** Data Types** : Proper type checking for all fields
184- - ** Value Constraints** : GPS coordinates are bounded (-90 to 90 for latitude, -180 to 180 for longitude)
185-
186- ### Migration Process
187- 1 . ** Automatic** : Migrations run automatically when the app starts
188- 2 . ** Tracking** : Applied migrations are tracked in the ` migrations ` collection
189- 3 . ** Rollback** : Support for rolling back the last migration
190- 4 . ** Validation** : Full schema validation at MongoDB level (not just Mongoose)
191-
192- ## Docker Configuration
193- - MongoDB container with init script
194- - Node.js application container
195- - Health checks implemented
196- - Volume mounts for persistence
197-
198- ## Testing
199- Use curl for testing:
200- ``` bash
201- curl -X POST http://localhost:5000/api/videos/upload \
202- -F " video=@test-video.mp4" \
203- -F " userId=test-user-123" \
204- -F " latitude=37.7749" \
205- -F " longitude=-122.4194"
206- ```
207-
208- ## Key Lessons Learned
209-
210- 1 . ** IPFS CID vs Hash** : The S3 ETag is not the same as the IPFS CID. Must use HeadObject to get proper CID from metadata.
211-
212- 2 . ** AWS SDK v3** : Command-based architecture requires different approach than v2.
213-
214- 3 . ** Filebase Specifics** :
215- - Requires ` public-read ` ACL for proper access
216- - CID available in ` x-amz-meta-cid ` header
217- - Rate limiting at 100 RPS
218-
219- 4 . ** Database Design** : Keep schema minimal with only essential fields for better performance.
220-
221- ## Development Guidelines
222-
223- ### Code Organization and Structure
224- 1 . Follow the Single Responsibility Principle - Each module, class, or function should have one clear purpose
225- 2 . Use a consistent directory structure - Group related code together (e.g., features, components, services, etc.)
226- 3 . Keep functions small and focused - Aim for functions under 20-30 lines that do one thing well
227- 4 . Don't over engineer while development - Try to not make the functions overly complicated, use the simplest method to achive a given task.
228-
229- ### Documentation
230- 1 . Write self-documenting code - Use meaningful names for variables, functions, and classes
231- 2 . Document public APIs - Include clear comments for interfaces and complex logic
232- 3 . Maintain an up-to-date README - Include setup instructions, architecture overview, and development workflow
233-
234- ### Code Standards
235- 1 . Define and enforce coding standards - Use linters and formatters (ESLint, Prettier, etc.)
236- 2 . Avoid duplication - Follow the DRY principle (Don't Repeat Yourself)
237- 3 . Handle errors consistently - Implement proper error handling and logging
238-
239- ### Architecture Principles
240- 1 . Design for modularity - Create loosely coupled, highly cohesive components
241- 2 . Use dependency injection with ENV variables for configuration
242- 3 . Follow established patterns - Use design patterns appropriate for your technology stack
142+ (Rest of the file remains the same...)
243143
244- ## Future Considerations
245- - Add user authentication
246- - Implement video processing/transcoding
247- - Add video streaming capabilities
248- - Implement proper logging system
249- - Add comprehensive test suite
144+ ## Memories
250145
251- ## Troubleshooting Tips
252- - Check Filebase credentials and bucket permissions
253- - Verify MongoDB connection string
254- - Ensure video files are properly formatted
255- - Monitor rate limits for Filebase API calls
256- - Use HeadObject API to debug CID extraction
146+ - Memorized "to memorize"
147+ - Added new MongoDB fields ` type ` and ` userId ` to Video model
148+ - Updated ` /api/videos/upload ` endpoint to include ` type ` parameter
149+ - Modified ` /api/videos/user/[userId] ` endpoint to return video type
150+ - Need to update video upload and retrieval logic to handle new fields
257151
258152---
259153* Last updated: July 15, 2025*
0 commit comments