Phoenixak99 commited on
Commit
65168b2
·
verified ·
1 Parent(s): 70a9952

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -594,9 +594,10 @@ def notify_admin_of_generation(perm_link, product_code):
594
  if st.session_state.get("jwt_token"):
595
  try:
596
  decoded = jwt.decode(st.session_state["jwt_token"], options={"verify_signature": False})
597
- user_id = decoded.get('user_id', 'Unknown')
598
- except:
599
- user_id = 'Unknown'
 
600
 
601
  # Prepare the notification data
602
  payload = {
@@ -605,18 +606,29 @@ def notify_admin_of_generation(perm_link, product_code):
605
  "user_id": user_id
606
  }
607
 
 
 
 
608
  # Send the notification
609
- response = requests.post(notification_url, json=payload)
 
 
 
 
 
 
 
610
 
611
- # Check if notification was successful
612
  if response.status_code == 200:
613
  print("✓ Admin notification sent successfully")
 
614
  else:
615
- print("× Failed to send admin notification")
 
616
 
617
  except Exception as e:
618
  print(f"× Error sending notification: {str(e)}")
619
-
620
 
621
  def update_download_count():
622
  auth_headers = get_auth_headers()
 
594
  if st.session_state.get("jwt_token"):
595
  try:
596
  decoded = jwt.decode(st.session_state["jwt_token"], options={"verify_signature": False})
597
+ user_id = decoded.get('data', {}).get('user', {}).get('id')
598
+ except Exception as e:
599
+ print(f"Error decoding JWT: {str(e)}")
600
+ user_id = None
601
 
602
  # Prepare the notification data
603
  payload = {
 
606
  "user_id": user_id
607
  }
608
 
609
+ # Log what we're sending
610
+ print(f"Sending notification with payload: {payload}")
611
+
612
  # Send the notification
613
+ headers = {
614
+ 'Content-Type': 'application/json'
615
+ }
616
+ response = requests.post(notification_url, json=payload, headers=headers)
617
+
618
+ # Log the response
619
+ print(f"Notification response status: {response.status_code}")
620
+ print(f"Notification response content: {response.text}")
621
 
 
622
  if response.status_code == 200:
623
  print("✓ Admin notification sent successfully")
624
+ return True
625
  else:
626
+ print(f"× Failed to send admin notification: {response.text}")
627
+ return False
628
 
629
  except Exception as e:
630
  print(f"× Error sending notification: {str(e)}")
631
+ return False
632
 
633
  def update_download_count():
634
  auth_headers = get_auth_headers()