Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,16 +75,20 @@ 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 |
response.raise_for_status()
|
| 79 |
data = response.json()
|
|
|
|
| 80 |
return data["key"], f"Còn lại {data['remaining']} key."
|
| 81 |
except requests.exceptions.RequestException as e:
|
|
|
|
| 82 |
return None, f"Lỗi khi lấy key từ API: {str(e)}"
|
| 83 |
|
| 84 |
# Hàm xác thực và xóa key (gọi API trên VPS)
|
| 85 |
def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
| 86 |
# Kiểm tra key có hợp lệ không (gọi API để lấy key và so sánh)
|
| 87 |
key_from_api, message = get_key_from_api()
|
|
|
|
| 88 |
if not key_from_api:
|
| 89 |
return False, message
|
| 90 |
if access_key != key_from_api:
|
|
@@ -100,6 +104,17 @@ def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
|
| 100 |
return True, remaining_message
|
| 101 |
else:
|
| 102 |
return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Hàm xử lý bất đồng bộ với chỉ báo tải
|
| 105 |
def execute_with_loading(func, *args, **kwargs):
|
|
|
|
| 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:
|
|
|
|
| 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."
|
| 118 |
|
| 119 |
# Hàm xử lý bất đồng bộ với chỉ báo tải
|
| 120 |
def execute_with_loading(func, *args, **kwargs):
|