Product Images Download Script - Summary
✅ Script Status: READY TO USE
Script đã hoàn thiện và sẵn sàng sử dụng!📁 Files Created
🚀 Quick Start
1. Install Dependencies (Already done!)
2. Run Script
📊 CSV Analysis Results
Phân tích filebruno_vassari_products.csv:
- Total products: 48
- With image URLs: 8
- Without image URLs: 40
Note: Chỉ có 8 products có image URLs trong CSV, 40 products còn lại không có URLs.
🎯 Script Features
✅ Implemented Features
- ✅ Parse CSV với regex (handle malformed CSV với commas trong text)
- ✅ Download images với retry logic (3 lần)
- ✅ Organized folder structure (
/temp-images/bruno-vassari/) - ✅ Error handling gracefull
- ✅ Generate mapping file (
images-mapping.json) - ✅ Support resume (skip already downloaded)
- ✅ Progress reporting với percentage
- ✅ Concurrent downloads (5 at a time)
- ✅ Timeout handling (30s)
- ✅ HTTP error handling (404, 500, timeout)
🎨 Output Format
File naming:product-{No}-{sanitized-filename}.jpg
images-mapping.json):
🧪 Testing
Test 1: Single Image Download ✅
Test 2: CSV Parsing ✅
Test 3: Dry Run ✅
📈 Expected Runtime
Với 8 images để download:- Estimated time: ~30-60 seconds
- Concurrent downloads: 5 at a time
- Timeout per image: 30 seconds
- Retry attempts: 3 per failed download
🔧 Configuration
Edit config tại đầu script nếu cần:🐛 Troubleshooting
”No image URL” cho nhiều products?
- Expected: CSV chỉ có 8/48 products với image URLs
- Check: CSV file columns - cần column “Image URL” với URLs
Downloads fail?
- Check: Internet connection
- Check: URLs are accessible
- Solution: Script tự động retry 3 lần
”Permission denied”?
📝 Next Steps
- Run script:
npm run download:images - Check output:
ls -la temp-images/bruno-vassari/ - Review mapping:
cat temp-images/images-mapping.json - Handle failures: Check statistics report cho failed downloads
📚 Additional Notes
CSV Format Handling
Script sử dụng regex-based parser để handle malformed CSV:- Dấu phẩy trong text không được quote (VD: “Kem Giảm Kích Ứng, Mẩn Đỏ Da”)
- Regex extract URLs trực tiếp từ raw line
- Workaround cho standard CSV parser limitations
Resume Feature
Chạy lại script sẽ skip đã downloaded:Error Logging
Failed URLs logged in:- Console output
- Statistics report
- Mapping file với error details
Script Location:
/Users/tannguyen/Documents/fullstack/triseo.drmanhlinhmd.com/scripts/download-product-images.js
Last Updated: 2025-01-10
Status: ✅ Ready for production use