Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -653,16 +653,27 @@ def send_video_generation_notification(user_id, user_email, project_name, video_
|
|
| 653 |
Returns:
|
| 654 |
bool: True if successful, False otherwise
|
| 655 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 656 |
try:
|
| 657 |
# Create the notification message
|
| 658 |
message_content = f"Your video for project '{project_name}' has been generated successfully!"
|
|
|
|
| 659 |
|
| 660 |
# Create email subject and body if email notification is requested
|
| 661 |
email_subject = None
|
| 662 |
email_body = None
|
| 663 |
|
| 664 |
if send_email:
|
|
|
|
| 665 |
email_subject = f"🎥 Video Generation Complete - {project_name}"
|
|
|
|
|
|
|
| 666 |
email_body = f"""
|
| 667 |
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f9f9f9;">
|
| 668 |
<div style="background-color: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
|
@@ -705,9 +716,13 @@ def send_video_generation_notification(user_id, user_email, project_name, video_
|
|
| 705 |
</div>
|
| 706 |
</div>
|
| 707 |
"""
|
|
|
|
|
|
|
|
|
|
| 708 |
|
| 709 |
# Use the existing _send_notification function
|
| 710 |
-
|
|
|
|
| 711 |
user_id=user_id,
|
| 712 |
user_email=user_email,
|
| 713 |
message_content=message_content,
|
|
@@ -716,8 +731,20 @@ def send_video_generation_notification(user_id, user_email, project_name, video_
|
|
| 716 |
email_body=email_body
|
| 717 |
)
|
| 718 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
except Exception as e:
|
| 720 |
-
logger.error(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 721 |
return False
|
| 722 |
|
| 723 |
|
|
@@ -778,10 +805,15 @@ def generate_sozo_video(project_id):
|
|
| 778 |
|
| 779 |
# NEW: Send notification if requested
|
| 780 |
if send_email_notification:
|
|
|
|
| 781 |
project_name = project_data.get('name', 'Unnamed Project')
|
| 782 |
user_email = user_data.get('email')
|
| 783 |
|
|
|
|
|
|
|
|
|
|
| 784 |
if user_email:
|
|
|
|
| 785 |
notification_sent = send_video_generation_notification(
|
| 786 |
user_id=uid,
|
| 787 |
user_email=user_email,
|
|
@@ -791,15 +823,20 @@ def generate_sozo_video(project_id):
|
|
| 791 |
)
|
| 792 |
|
| 793 |
if not notification_sent:
|
| 794 |
-
logger.
|
|
|
|
|
|
|
| 795 |
else:
|
| 796 |
-
logger.warning(f"No email found for user {uid}, skipping email notification")
|
|
|
|
|
|
|
|
|
|
| 797 |
|
| 798 |
return jsonify({
|
| 799 |
'success': True,
|
| 800 |
'video_url': video_url,
|
| 801 |
'credits_remaining': current_credits - 5,
|
| 802 |
-
'notification_sent': send_email_notification and user_data.get('email')
|
| 803 |
}), 200
|
| 804 |
|
| 805 |
except Exception as e:
|
|
|
|
| 653 |
Returns:
|
| 654 |
bool: True if successful, False otherwise
|
| 655 |
"""
|
| 656 |
+
logger.info(f"=== VIDEO GENERATION NOTIFICATION START ===")
|
| 657 |
+
logger.info(f"User ID: {user_id}")
|
| 658 |
+
logger.info(f"User Email: {user_email}")
|
| 659 |
+
logger.info(f"Project Name: {project_name}")
|
| 660 |
+
logger.info(f"Video URL: {video_url}")
|
| 661 |
+
logger.info(f"Send Email: {send_email}")
|
| 662 |
+
|
| 663 |
try:
|
| 664 |
# Create the notification message
|
| 665 |
message_content = f"Your video for project '{project_name}' has been generated successfully!"
|
| 666 |
+
logger.info(f"Created notification message: {message_content}")
|
| 667 |
|
| 668 |
# Create email subject and body if email notification is requested
|
| 669 |
email_subject = None
|
| 670 |
email_body = None
|
| 671 |
|
| 672 |
if send_email:
|
| 673 |
+
logger.info("Preparing email notification content...")
|
| 674 |
email_subject = f"🎥 Video Generation Complete - {project_name}"
|
| 675 |
+
logger.info(f"Email subject: {email_subject}")
|
| 676 |
+
|
| 677 |
email_body = f"""
|
| 678 |
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f9f9f9;">
|
| 679 |
<div style="background-color: white; padding: 30px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1);">
|
|
|
|
| 716 |
</div>
|
| 717 |
</div>
|
| 718 |
"""
|
| 719 |
+
logger.info(f"Email body prepared (length: {len(email_body)} chars)")
|
| 720 |
+
else:
|
| 721 |
+
logger.info("Email notification not requested, skipping email content preparation")
|
| 722 |
|
| 723 |
# Use the existing _send_notification function
|
| 724 |
+
logger.info("Calling _send_notification function...")
|
| 725 |
+
result = _send_notification(
|
| 726 |
user_id=user_id,
|
| 727 |
user_email=user_email,
|
| 728 |
message_content=message_content,
|
|
|
|
| 731 |
email_body=email_body
|
| 732 |
)
|
| 733 |
|
| 734 |
+
if result:
|
| 735 |
+
logger.info("✅ Video generation notification sent successfully")
|
| 736 |
+
else:
|
| 737 |
+
logger.error("❌ Video generation notification failed")
|
| 738 |
+
|
| 739 |
+
logger.info(f"=== VIDEO GENERATION NOTIFICATION END (Result: {result}) ===")
|
| 740 |
+
return result
|
| 741 |
+
|
| 742 |
except Exception as e:
|
| 743 |
+
logger.error(f"❌ EXCEPTION in send_video_generation_notification: {e}")
|
| 744 |
+
logger.error(f"Exception type: {type(e).__name__}")
|
| 745 |
+
import traceback
|
| 746 |
+
logger.error(f"Traceback: {traceback.format_exc()}")
|
| 747 |
+
logger.info(f"=== VIDEO GENERATION NOTIFICATION END (Exception) ===")
|
| 748 |
return False
|
| 749 |
|
| 750 |
|
|
|
|
| 805 |
|
| 806 |
# NEW: Send notification if requested
|
| 807 |
if send_email_notification:
|
| 808 |
+
logger.info(f"Email notification requested for project {project_id}")
|
| 809 |
project_name = project_data.get('name', 'Unnamed Project')
|
| 810 |
user_email = user_data.get('email')
|
| 811 |
|
| 812 |
+
logger.info(f"Project name: {project_name}")
|
| 813 |
+
logger.info(f"User email available: {user_email is not None}")
|
| 814 |
+
|
| 815 |
if user_email:
|
| 816 |
+
logger.info(f"Sending video generation notification to {user_email}")
|
| 817 |
notification_sent = send_video_generation_notification(
|
| 818 |
user_id=uid,
|
| 819 |
user_email=user_email,
|
|
|
|
| 823 |
)
|
| 824 |
|
| 825 |
if not notification_sent:
|
| 826 |
+
logger.error(f"❌ Failed to send notification for video generation completion to user {uid}")
|
| 827 |
+
else:
|
| 828 |
+
logger.info(f"✅ Successfully sent notification for video generation completion to user {uid}")
|
| 829 |
else:
|
| 830 |
+
logger.warning(f"⚠️ No email found for user {uid}, skipping email notification")
|
| 831 |
+
else:
|
| 832 |
+
logger.info("Email notification not requested")
|
| 833 |
+
notification_sent = False
|
| 834 |
|
| 835 |
return jsonify({
|
| 836 |
'success': True,
|
| 837 |
'video_url': video_url,
|
| 838 |
'credits_remaining': current_credits - 5,
|
| 839 |
+
'notification_sent': notification_sent if send_email_notification and user_data.get('email') else False
|
| 840 |
}), 200
|
| 841 |
|
| 842 |
except Exception as e:
|