diff --git a/scraper.py b/scraper.py index fdf7067..1d28794 100644 --- a/scraper.py +++ b/scraper.py @@ -78,25 +78,29 @@ def scrape_and_store(db: Session, req: ScrapeRequest) -> List[ScrapedPost]: if not media_items: continue + # ✅ Upload thumbnail separately and store local version + uploaded_thumb = upload_media_from_url(post.thumbnail_url, str(req.seller_id), f"{post_id}/thumbnail") + final_thumbnail = uploaded_thumb or post.thumbnail_url # fallback if upload fails + # Save to DB post_entry = InstagramPost( ig_post_id=post_id, account_id=account.id, media_type="carousel" if post.media_type == 8 else ("video" if post.media_type == 2 else "image"), caption=post.caption_text or "", - thumbnail_url=post.thumbnail_url, + thumbnail_url=final_thumbnail, local_media=[m.dict() for m in media_items], created_at=post.taken_at or datetime.utcnow(), ) db.add(post_entry) db.commit() - # Add to result for response + # Add to response result.append(ScrapedPost( ig_post_id=post_id, media_type=post_entry.media_type, caption=post_entry.caption, - thumbnail_url=post_entry.thumbnail_url, + thumbnail_url=final_thumbnail, local_media=media_items, created_at=post_entry.created_at )) @@ -105,4 +109,4 @@ def scrape_and_store(db: Session, req: ScrapeRequest) -> List[ScrapedPost]: if new_post_count >= req.max_count: break - return result \ No newline at end of file + return result