mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
chore: 把配置文件生成的地方换个位置,对Docker用户更友好
ps: Docker只能挂载目录,所以更友好
This commit is contained in:
parent
de3e8da790
commit
f88496023f
@ -26,7 +26,7 @@ local_data = threading.local()
|
||||
def get_data_connection():
|
||||
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
||||
if not hasattr(local_data, 'connection'):
|
||||
local_data.connection = sqlite3.connect('data.db')
|
||||
local_data.connection = sqlite3.connect('./data/data.db')
|
||||
return local_data.connection
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ local_cache = threading.local()
|
||||
def get_cache_connection():
|
||||
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
||||
if not hasattr(local_cache, 'connection'):
|
||||
local_cache.connection = sqlite3.connect('cache.db')
|
||||
local_cache.connection = sqlite3.connect('./data/cache.db')
|
||||
return local_cache.connection
|
||||
|
||||
|
||||
@ -320,7 +320,7 @@ default = {
|
||||
|
||||
|
||||
def handle_default_config():
|
||||
with open("./config.json", "w", encoding="utf-8") as f:
|
||||
with open("./data/config.json", "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(default, indent=2, ensure_ascii=False,
|
||||
escape_forward_slashes=False))
|
||||
f.close()
|
||||
@ -512,7 +512,7 @@ def push_to_list(key, obj):
|
||||
|
||||
def write_config(key, value):
|
||||
config = None
|
||||
with open('config.json', 'r', encoding='utf-8') as f:
|
||||
with open('./data/config.json', 'r', encoding='utf-8') as f:
|
||||
config = json.load(f)
|
||||
|
||||
keys = key.split('.')
|
||||
@ -524,7 +524,7 @@ def write_config(key, value):
|
||||
|
||||
current[keys[-1]] = value
|
||||
variable.config = config
|
||||
with open('config.json', 'w', encoding='utf-8') as f:
|
||||
with open('./data/config.json', 'w', encoding='utf-8') as f:
|
||||
json.dump(config, f, indent=2, ensure_ascii=False,
|
||||
escape_forward_slashes=False)
|
||||
f.close()
|
||||
@ -621,18 +621,18 @@ def write_data(key, value):
|
||||
|
||||
def initConfig():
|
||||
try:
|
||||
with open("./config.json", "r", encoding="utf-8") as f:
|
||||
with open("./data/config.json", "r", encoding="utf-8") as f:
|
||||
try:
|
||||
variable.config = json.loads(f.read())
|
||||
if (not isinstance(variable.config, dict)):
|
||||
logger.warning('配置文件并不是一个有效的字典,使用默认值')
|
||||
variable.config = default
|
||||
with open("./config.json", "w", encoding="utf-8") as f:
|
||||
with open("./data/config.json", "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(variable.config, indent=2,
|
||||
ensure_ascii=False, escape_forward_slashes=False))
|
||||
f.close()
|
||||
except:
|
||||
if os.path.getsize("./config.json") != 0:
|
||||
if os.path.getsize("./data/config.json") != 0:
|
||||
logger.error("配置文件加载失败,请检查是否遵循JSON语法规范")
|
||||
sys.exit(1)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user