Update helper.py
Browse files
helper.py
CHANGED
@@ -3,16 +3,11 @@ import uuid
|
|
3 |
from datetime import datetime, timedelta
|
4 |
import random
|
5 |
import string
|
6 |
-
|
7 |
-
github_username_zed_userid_list = [
|
8 |
-
("aaa", 123123),
|
9 |
-
]
|
10 |
-
|
11 |
|
12 |
def generate_random_tuple():
|
13 |
"""
|
14 |
Generate a random tuple containing a string and an integer.
|
15 |
-
|
16 |
Returns:
|
17 |
tuple: A tuple containing:
|
18 |
- str: A random string of length 6-12 consisting of ASCII letters and digits.
|
@@ -26,28 +21,14 @@ def generate_random_tuple():
|
|
26 |
|
27 |
return (random_string, random_int)
|
28 |
|
29 |
-
|
30 |
def create_jwt(github_user_login: str, user_id: int) -> str:
|
31 |
"""
|
32 |
Create a JSON Web Token (JWT) for a given GitHub user.
|
33 |
-
|
34 |
Args:
|
35 |
github_user_login (str): The GitHub username of the user.
|
36 |
user_id (int): The user's ID.
|
37 |
-
|
38 |
Returns:
|
39 |
str: A JWT encoded string containing user information and authentication details.
|
40 |
-
|
41 |
-
Note:
|
42 |
-
The token has a lifetime of 1 hour and includes the following claims:
|
43 |
-
- iat: Issued at time
|
44 |
-
- exp: Expiration time
|
45 |
-
- jti: Unique token identifier
|
46 |
-
- userId: User's ID
|
47 |
-
- githubUserLogin: GitHub username
|
48 |
-
- isStaff: Boolean indicating staff status (default: False)
|
49 |
-
- hasLlmClosedBetaFeatureFlag: Boolean for LLM closed beta feature (default: False)
|
50 |
-
- plan: User's plan (default: "Free")
|
51 |
"""
|
52 |
LLM_TOKEN_LIFETIME = timedelta(hours=1)
|
53 |
now = datetime.utcnow()
|
@@ -63,4 +44,6 @@ def create_jwt(github_user_login: str, user_id: int) -> str:
|
|
63 |
"plan": "Free"
|
64 |
}
|
65 |
|
66 |
-
|
|
|
|
|
|
3 |
from datetime import datetime, timedelta
|
4 |
import random
|
5 |
import string
|
6 |
+
import os
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def generate_random_tuple():
|
9 |
"""
|
10 |
Generate a random tuple containing a string and an integer.
|
|
|
11 |
Returns:
|
12 |
tuple: A tuple containing:
|
13 |
- str: A random string of length 6-12 consisting of ASCII letters and digits.
|
|
|
21 |
|
22 |
return (random_string, random_int)
|
23 |
|
|
|
24 |
def create_jwt(github_user_login: str, user_id: int) -> str:
|
25 |
"""
|
26 |
Create a JSON Web Token (JWT) for a given GitHub user.
|
|
|
27 |
Args:
|
28 |
github_user_login (str): The GitHub username of the user.
|
29 |
user_id (int): The user's ID.
|
|
|
30 |
Returns:
|
31 |
str: A JWT encoded string containing user information and authentication details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
"""
|
33 |
LLM_TOKEN_LIFETIME = timedelta(hours=1)
|
34 |
now = datetime.utcnow()
|
|
|
44 |
"plan": "Free"
|
45 |
}
|
46 |
|
47 |
+
# 使用环境变量获取密钥,如果没有设置,则使用默认值
|
48 |
+
secret_key = os.environ.get('JWT_SECRET_KEY', 'llm-secret')
|
49 |
+
return jwt.encode(payload, secret_key, algorithm='HS256')
|