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():
|
def get_data_connection():
|
||||||
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
||||||
if not hasattr(local_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
|
return local_data.connection
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ local_cache = threading.local()
|
|||||||
def get_cache_connection():
|
def get_cache_connection():
|
||||||
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
# 检查线程本地存储对象是否存在连接对象,如果不存在则创建一个新的连接对象
|
||||||
if not hasattr(local_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
|
return local_cache.connection
|
||||||
|
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ default = {
|
|||||||
|
|
||||||
|
|
||||||
def handle_default_config():
|
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,
|
f.write(json.dumps(default, indent=2, ensure_ascii=False,
|
||||||
escape_forward_slashes=False))
|
escape_forward_slashes=False))
|
||||||
f.close()
|
f.close()
|
||||||
@ -512,7 +512,7 @@ def push_to_list(key, obj):
|
|||||||
|
|
||||||
def write_config(key, value):
|
def write_config(key, value):
|
||||||
config = None
|
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)
|
config = json.load(f)
|
||||||
|
|
||||||
keys = key.split('.')
|
keys = key.split('.')
|
||||||
@ -524,7 +524,7 @@ def write_config(key, value):
|
|||||||
|
|
||||||
current[keys[-1]] = value
|
current[keys[-1]] = value
|
||||||
variable.config = config
|
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,
|
json.dump(config, f, indent=2, ensure_ascii=False,
|
||||||
escape_forward_slashes=False)
|
escape_forward_slashes=False)
|
||||||
f.close()
|
f.close()
|
||||||
@ -621,18 +621,18 @@ def write_data(key, value):
|
|||||||
|
|
||||||
def initConfig():
|
def initConfig():
|
||||||
try:
|
try:
|
||||||
with open("./config.json", "r", encoding="utf-8") as f:
|
with open("./data/config.json", "r", encoding="utf-8") as f:
|
||||||
try:
|
try:
|
||||||
variable.config = json.loads(f.read())
|
variable.config = json.loads(f.read())
|
||||||
if (not isinstance(variable.config, dict)):
|
if (not isinstance(variable.config, dict)):
|
||||||
logger.warning('配置文件并不是一个有效的字典,使用默认值')
|
logger.warning('配置文件并不是一个有效的字典,使用默认值')
|
||||||
variable.config = default
|
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,
|
f.write(json.dumps(variable.config, indent=2,
|
||||||
ensure_ascii=False, escape_forward_slashes=False))
|
ensure_ascii=False, escape_forward_slashes=False))
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
if os.path.getsize("./config.json") != 0:
|
if os.path.getsize("./data/config.json") != 0:
|
||||||
logger.error("配置文件加载失败,请检查是否遵循JSON语法规范")
|
logger.error("配置文件加载失败,请检查是否遵循JSON语法规范")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user