update:env

This commit is contained in:
lan
2023-08-15 17:23:30 +08:00
parent a4d85bce27
commit d00cef42a1
50 changed files with 224 additions and 80 deletions
+54
View File
@@ -7,3 +7,57 @@ from pathlib import Path
data_root = Path('./data')
if not data_root.exists():
data_root.mkdir(parents=True, exist_ok=True)
default_value = {
'file_storage': 'SystemFileStorage',
'name': '文件快递柜-FileCodeBox',
'description': '开箱即用的文件快传系统',
'keywords': 'FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文本,文件',
's3_access_key_id': '',
's3_secret_access_key': '',
's3_bucket_name': '',
's3_endpoint_url': '',
'openUpload': 1,
'uploadSize': 1024 * 1024 * 10,
'uploadMinute': 1,
'uploadCount': 10,
'errorMinute': 1,
'errorCount': 1,
}
class Settings:
__instance = None
def __init__(self):
# 读取.env
if not (data_root / '.env').exists():
with open(data_root / '.env', 'w', encoding='utf-8') as f:
for key, value in default_value.items():
f.write(f'{key}={value}\n')
# 更新default_value
with open(data_root / '.env', 'r', encoding='utf-8') as f:
for line in f.readlines():
key, value = line.strip().split('=')
# 将字符串转换为原本的类型
if value.isdigit():
value = int(value)
default_value[key] = value
# 更新self
for key, value in default_value.items():
self.__setattr__(key, value)
def __new__(cls, *args, **kwargs):
if not cls.__instance:
cls.__instance = super(Settings, cls).__new__(cls, *args, **kwargs)
return cls.__instance
def __setattr__(self, key, value):
self.__dict__[key] = value
with open(data_root / '.env', 'w', encoding='utf-8') as f:
for key, value in self.__dict__.items():
f.write(f'{key}={value}\n')
settings = Settings()