GmailTrust commited on
Commit
5ddde19
·
verified ·
1 Parent(s): 0de483f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -24
app.py CHANGED
@@ -75,43 +75,30 @@ client = ZGMApiClient("https://gm.haivl.wtf", ZGM_API_TOKEN)
75
  def get_key_from_api() -> tuple[Optional[str], str]:
76
  try:
77
  response = requests.get(f"{KEY_API_URL}/api/keys/get", timeout=5)
78
- print(f"API Response: {response.text}") # Thêm log debug
79
  response.raise_for_status()
80
  data = response.json()
81
- print(f"Extracted Key: {data['key']}") # Thêm log debug
82
  return data["key"], f"Còn lại {data['remaining']} key."
83
  except requests.exceptions.RequestException as e:
84
- print(f"API Error: {str(e)}") # Thêm log debug
85
  return None, f"Lỗi khi lấy key từ API: {str(e)}"
86
 
87
- # Hàm xác thực và xóa key (gọi API trên VPS)
88
  def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
89
- # Kiểm tra key có hợp lệ không (gọi API để lấy key và so sánh)
90
- key_from_api, message = get_key_from_api()
91
- print(f"Input Key: {access_key}, API Key: {key_from_api}") # Thêm log debug
92
  if not key_from_api:
93
  return False, message
94
- if access_key != key_from_api:
95
  return False, "Key không hợp lệ! Vui lòng nhập key hợp lệ để tiếp tục."
96
 
97
  # Chỉ xóa key trên VPS khi thuê thành công (đã gọi API xóa trong get_key_from_api)
98
  if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
99
- remaining_message = message
100
- if "Còn lại" in message:
101
- remaining_keys = int(message.split("Còn lại ")[1].split(" key")[0])
102
- if remaining_keys < 100:
103
- remaining_message += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
104
- return True, remaining_message
105
- else:
106
- return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."
107
-
108
- # Chỉ xóa key trên VPS khi thuê thành công (đã gọi API xóa trong get_key_from_api)
109
- if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
110
- remaining_message = message
111
- if "Còn lại" in message:
112
- remaining_keys = int(message.split("Còn lại ")[1].split(" key")[0])
113
- if remaining_keys < 100:
114
- remaining_message += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
115
  return True, remaining_message
116
  else:
117
  return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."
 
75
  def get_key_from_api() -> tuple[Optional[str], str]:
76
  try:
77
  response = requests.get(f"{KEY_API_URL}/api/keys/get", timeout=5)
78
+ print(f"API Response: {response.text}") # Debug log
79
  response.raise_for_status()
80
  data = response.json()
81
+ print(f"Extracted Key: {data['key']}") # Debug log
82
  return data["key"], f"Còn lại {data['remaining']} key."
83
  except requests.exceptions.RequestException as e:
84
+ print(f"API Error: {str(e)}") # Debug log
85
  return None, f"Lỗi khi lấy key từ API: {str(e)}"
86
 
87
+ # Hàm xác thực và xóa key (gọi API một lần)
88
  def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
89
+ key_from_api, message = get_key_from_api() # Gọi API một lần
90
+ print(f"Input Key: {access_key}, API Key: {key_from_api}") # Debug log
 
91
  if not key_from_api:
92
  return False, message
93
+ if access_key.strip() != key_from_api.strip(): # So sánh sau khi loại bỏ whitespace
94
  return False, "Key không hợp lệ! Vui lòng nhập key hợp lệ để tiếp tục."
95
 
96
  # Chỉ xóa key trên VPS khi thuê thành công (đã gọi API xóa trong get_key_from_api)
97
  if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
98
+ remaining_keys = int(message.split("Còn lại ")[1].split(" key")[0])
99
+ remaining_message = f"Còn lại {remaining_keys} key."
100
+ if remaining_keys < 100:
101
+ remaining_message += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
 
 
 
 
 
 
 
 
 
 
 
 
102
  return True, remaining_message
103
  else:
104
  return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."