Tuchuanhuhuhu commited on
Commit
6431f64
1 Parent(s): 8783eb5

自动迁移旧版设置文件,以后只使用config.json

Browse files
Files changed (1) hide show
  1. modules/config.py +24 -18
modules/config.py CHANGED
@@ -28,6 +28,30 @@ if os.path.exists("config.json"):
28
  else:
29
  config = {}
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ## 处理docker if we are running in Docker
32
  dockerflag = config.get("dockerflag", False)
33
  if os.environ.get("dockerrun") == "yes":
@@ -64,24 +88,6 @@ if dockerflag:
64
  if not (isinstance(username, type(None)) or isinstance(password, type(None))):
65
  auth_list.append((os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
66
  authflag = True
67
- else:
68
- if (
69
- not my_api_key
70
- and os.path.exists("api_key.txt")
71
- and os.path.getsize("api_key.txt")
72
- ):
73
- with open("api_key.txt", "r") as f:
74
- my_api_key = f.read().strip()
75
- if os.path.exists("auth.json"):
76
- authflag = True
77
- with open("auth.json", "r", encoding='utf-8') as f:
78
- auth = json.load(f)
79
- for _ in auth:
80
- if auth[_]["username"] and auth[_]["password"]:
81
- auth_list.append((auth[_]["username"], auth[_]["password"]))
82
- else:
83
- logging.error("请检查auth.json文件中的用户名和密码!")
84
- sys.exit(1)
85
 
86
  @contextmanager
87
  def retrieve_openai_api(api_key = None):
 
28
  else:
29
  config = {}
30
 
31
+ if os.path.exists("api_key.txt"):
32
+ logging.info("检测到api_key.txt文件,正在进行迁移...")
33
+ with open("api_key.txt", "r") as f:
34
+ config["openai_api_key"] = f.read().strip()
35
+ os.rename("api_key.txt", "api_key(deprecated).txt")
36
+ with open("config.json", "w", encoding='utf-8') as f:
37
+ json.dump(config, f, indent=4)
38
+
39
+ if os.path.exists("auth.json"):
40
+ logging.info("检测到auth.json文件,正在进行迁移...")
41
+ auth_list = []
42
+ with open("auth.json", "r", encoding='utf-8') as f:
43
+ auth = json.load(f)
44
+ for _ in auth:
45
+ if auth[_]["username"] and auth[_]["password"]:
46
+ auth_list.append((auth[_]["username"], auth[_]["password"]))
47
+ else:
48
+ logging.error("请检查auth.json文件中的用户名和密码!")
49
+ sys.exit(1)
50
+ config["users"] = auth_list
51
+ os.rename("auth.json", "auth(deprecated).json")
52
+ with open("config.json", "w", encoding='utf-8') as f:
53
+ json.dump(config, f, indent=4)
54
+
55
  ## 处理docker if we are running in Docker
56
  dockerflag = config.get("dockerflag", False)
57
  if os.environ.get("dockerrun") == "yes":
 
88
  if not (isinstance(username, type(None)) or isinstance(password, type(None))):
89
  auth_list.append((os.environ.get("USERNAME"), os.environ.get("PASSWORD")))
90
  authflag = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  @contextmanager
93
  def retrieve_openai_api(api_key = None):