Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,31 +71,50 @@ class ZGMApiClient:
|
|
| 71 |
# Khởi tạo client
|
| 72 |
client = ZGMApiClient("https://gm.haivl.wtf", ZGM_API_TOKEN)
|
| 73 |
|
| 74 |
-
# Hàm
|
| 75 |
-
def
|
| 76 |
try:
|
| 77 |
-
response = requests.get(f"{KEY_API_URL}/api/keys/
|
| 78 |
-
print(f"API Response: {response.text}") # Debug log
|
| 79 |
response.raise_for_status()
|
| 80 |
data = response.json()
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
except requests.exceptions.RequestException as e:
|
| 84 |
-
print(f"API Error: {str(e)}") # Debug log
|
| 85 |
-
return
|
| 86 |
|
| 87 |
-
# Hàm xác thực và xóa key
|
| 88 |
def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 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
|
| 97 |
if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 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."
|
|
|
|
| 71 |
# Khởi tạo client
|
| 72 |
client = ZGMApiClient("https://gm.haivl.wtf", ZGM_API_TOKEN)
|
| 73 |
|
| 74 |
+
# Hàm kiểm tra key từ API trên VPS mà không xóa
|
| 75 |
+
def validate_key_from_api(access_key: str) -> tuple[bool, str]:
|
| 76 |
try:
|
| 77 |
+
response = requests.get(f"{KEY_API_URL}/api/keys/validate", params={"key": access_key}, timeout=5)
|
| 78 |
+
print(f"Validate API Response: {response.text}") # Debug log
|
| 79 |
response.raise_for_status()
|
| 80 |
data = response.json()
|
| 81 |
+
if data["valid"]:
|
| 82 |
+
return True, f"Còn lại {data['remaining']} key."
|
| 83 |
+
else:
|
| 84 |
+
return False, "Key không hợp lệ! Vui lòng nhập key hợp lệ để tiếp tục."
|
| 85 |
+
except requests.exceptions.RequestException as e:
|
| 86 |
+
print(f"Validate API Error: {str(e)}") # Debug log
|
| 87 |
+
return False, f"Lỗi khi kiểm tra key từ API: {str(e)}"
|
| 88 |
+
|
| 89 |
+
# Hàm xóa key từ API trên VPS
|
| 90 |
+
def remove_key_from_api(access_key: str) -> tuple[bool, str]:
|
| 91 |
+
try:
|
| 92 |
+
response = requests.delete(f"{KEY_API_URL}/api/keys/remove", params={"key": access_key}, timeout=5)
|
| 93 |
+
print(f"Remove API Response: {response.text}") # Debug log
|
| 94 |
+
response.raise_for_status()
|
| 95 |
+
data = response.json()
|
| 96 |
+
if data["success"]:
|
| 97 |
+
return True, f"Còn lại {data['remaining']} key."
|
| 98 |
+
else:
|
| 99 |
+
return False, "Không thể xóa key."
|
| 100 |
except requests.exceptions.RequestException as e:
|
| 101 |
+
print(f"Remove API Error: {str(e)}") # Debug log
|
| 102 |
+
return False, f"Lỗi khi xóa key từ API: {str(e)}"
|
| 103 |
|
| 104 |
+
# Hàm xác thực và xóa key
|
| 105 |
def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
| 106 |
+
# Kiểm tra key có hợp lệ không
|
| 107 |
+
is_valid, message = validate_key_from_api(access_key)
|
| 108 |
+
print(f"Input Key: {access_key}, Valid: {is_valid}") # Debug log
|
| 109 |
+
if not is_valid:
|
| 110 |
return False, message
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
# Chỉ xóa key khi thuê OTP thành công
|
| 113 |
if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
|
| 114 |
+
success, remove_message = remove_key_from_api(access_key)
|
| 115 |
+
if not success:
|
| 116 |
+
return True, f"Thuê OTP thành công nhưng {remove_message}"
|
| 117 |
+
remaining_keys = int(remove_message.split("Còn lại ")[1].split(" key")[0])
|
| 118 |
remaining_message = f"Còn lại {remaining_keys} key."
|
| 119 |
if remaining_keys < 100:
|
| 120 |
remaining_message += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
|