Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -102,42 +102,42 @@ class AuthManager:
|
|
102 |
self.logger.info(f"\033[92mRefresh Token: {self.refresh_token}\033[0m")
|
103 |
|
104 |
def fetch_apikey(self) -> str:
|
105 |
-
|
106 |
-
|
107 |
-
return self.api_key
|
108 |
-
|
109 |
-
try:
|
110 |
-
url = "https://chat.notdiamond.ai/login"
|
111 |
-
headers = {
|
112 |
-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
113 |
-
}
|
114 |
-
response = self.session.get(url, headers=headers)
|
115 |
-
response.raise_for_status()
|
116 |
-
|
117 |
-
# 匹配 <script> 标签中的 JS 文件路径
|
118 |
-
match = re.search(r'<script src="(/_next/static/chunks/app/layout-[^"]+\.js)"', response.text)
|
119 |
-
if not match:
|
120 |
-
self.logger.warning("未找到匹配的脚本标签")
|
121 |
-
return ""
|
122 |
-
|
123 |
-
js_url = f"https://chat.notdiamond.ai{match.group(1)}"
|
124 |
-
js_response = self.session.get(js_url, headers=headers)
|
125 |
-
js_response.raise_for_status()
|
126 |
-
|
127 |
-
# 匹配 API key
|
128 |
-
api_key_match = re.search(r'\("https://spuckhogycrxcbomznwo\.supabase\.co","([^"]+)"\)', js_response.text)
|
129 |
-
if api_key_match:
|
130 |
-
self.api_key = api_key_match.group(1)
|
131 |
-
logger.info(f"Extracted API key: {self.api_key}")
|
132 |
return self.api_key
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
return ""
|
136 |
|
137 |
-
except requests.RequestException as e:
|
138 |
-
self.logger.error(f"请求JS文件时发生错误: {e}")
|
139 |
-
return ""
|
140 |
-
|
141 |
def login(self) -> None:
|
142 |
"""使用电子邮件和密码进行用户登录,并获取用户信息。"""
|
143 |
api_key = self.fetch_apikey()
|
|
|
102 |
self.logger.info(f"\033[92mRefresh Token: {self.refresh_token}\033[0m")
|
103 |
|
104 |
def fetch_apikey(self) -> str:
|
105 |
+
"""获取API密钥。"""
|
106 |
+
if self.api_key:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
return self.api_key
|
108 |
+
|
109 |
+
try:
|
110 |
+
url = "https://chat.notdiamond.ai/login"
|
111 |
+
headers = {
|
112 |
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
113 |
+
}
|
114 |
+
response = self.session.get(url, headers=headers)
|
115 |
+
response.raise_for_status()
|
116 |
+
|
117 |
+
# 匹配 <script> 标签中的 JS 文件路径
|
118 |
+
match = re.search(r'<script src="(/_next/static/chunks/app/layout-[^"]+\.js)"', response.text)
|
119 |
+
if not match:
|
120 |
+
self.logger.warning("未找到匹配的脚本标签")
|
121 |
+
return ""
|
122 |
+
|
123 |
+
js_url = f"https://chat.notdiamond.ai{match.group(1)}"
|
124 |
+
js_response = self.session.get(js_url, headers=headers)
|
125 |
+
js_response.raise_for_status()
|
126 |
+
|
127 |
+
# 匹配 API key
|
128 |
+
api_key_match = re.search(r'\("https://spuckhogycrxcbomznwo\.supabase\.co","([^"]+)"\)', js_response.text)
|
129 |
+
if api_key_match:
|
130 |
+
self.api_key = api_key_match.group(1)
|
131 |
+
logger.info(f"Extracted API key: {self.api_key}")
|
132 |
+
return self.api_key
|
133 |
+
else:
|
134 |
+
self.logger.error("未能匹配API key")
|
135 |
+
return ""
|
136 |
+
|
137 |
+
except requests.RequestException as e:
|
138 |
+
self.logger.error(f"请求JS文件时发生错误: {e}")
|
139 |
return ""
|
140 |
|
|
|
|
|
|
|
|
|
141 |
def login(self) -> None:
|
142 |
"""使用电子邮件和密码进行用户登录,并获取用户信息。"""
|
143 |
api_key = self.fetch_apikey()
|