修改了common_items_path 配置文件路径
This commit is contained in:
parent
01062249e3
commit
ed0ae9f3ce
Binary file not shown.
@ -233,7 +233,7 @@ def copy_data_files():
|
|||||||
data_dir = os.path.join('dist', 'BodyBalanceBackend', 'data')
|
data_dir = os.path.join('dist', 'BodyBalanceBackend', 'data')
|
||||||
|
|
||||||
# 数据库文件列表 - 这些文件会在程序首次运行时自动创建
|
# 数据库文件列表 - 这些文件会在程序首次运行时自动创建
|
||||||
db_files = ['body_balance.db']
|
db_files = ['body_balance.db','common_items.json']
|
||||||
|
|
||||||
# 检查是否存在现有数据库文件,如果存在则复制
|
# 检查是否存在现有数据库文件,如果存在则复制
|
||||||
copied_count = 0
|
copied_count = 0
|
||||||
|
|||||||
@ -11,6 +11,7 @@ cors_origins = *
|
|||||||
|
|
||||||
[DATABASE]
|
[DATABASE]
|
||||||
path = D:/BodyCheck/data/body_balance.db
|
path = D:/BodyCheck/data/body_balance.db
|
||||||
|
common_items_path = D:/BodyCheck/data/common_items.json
|
||||||
backup_interval = 24
|
backup_interval = 24
|
||||||
max_backups = 7
|
max_backups = 7
|
||||||
|
|
||||||
|
|||||||
@ -385,10 +385,12 @@ class AppServer:
|
|||||||
@self.app.route('/api/common-items', methods=['GET'])
|
@self.app.route('/api/common-items', methods=['GET'])
|
||||||
def get_common_items():
|
def get_common_items():
|
||||||
try:
|
try:
|
||||||
base_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
|
# 从配置读取通用项文件路径,支持相对backend目录
|
||||||
data_dir = os.path.join(base_dir, 'data')
|
fpath = self.config_manager.get_config_value('DATABASE', 'common_items_path', 'data/common_items.json') if self.config_manager else 'data/common_items.json'
|
||||||
os.makedirs(data_dir, exist_ok=True)
|
if not os.path.isabs(fpath):
|
||||||
fpath = os.path.join(data_dir, 'common_items.json')
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
fpath = os.path.join(base_dir, fpath)
|
||||||
|
os.makedirs(os.path.dirname(fpath), exist_ok=True)
|
||||||
if not os.path.exists(fpath):
|
if not os.path.exists(fpath):
|
||||||
with open(fpath, 'w', encoding='utf-8') as f:
|
with open(fpath, 'w', encoding='utf-8') as f:
|
||||||
json.dump({'treatment': [], 'suggestion': []}, f, ensure_ascii=False)
|
json.dump({'treatment': [], 'suggestion': []}, f, ensure_ascii=False)
|
||||||
@ -406,10 +408,12 @@ class AppServer:
|
|||||||
label = str(payload.get('label', '')).strip()
|
label = str(payload.get('label', '')).strip()
|
||||||
if itype not in ['treatment', 'suggestion'] or not label:
|
if itype not in ['treatment', 'suggestion'] or not label:
|
||||||
return jsonify({'success': False, 'error': '参数无效'}), 400
|
return jsonify({'success': False, 'error': '参数无效'}), 400
|
||||||
base_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
|
# 从配置读取通用项文件路径,支持相对backend目录
|
||||||
data_dir = os.path.join(base_dir, 'data')
|
fpath = self.config_manager.get_config_value('DATABASE', 'common_items_path', 'data/common_items.json') if self.config_manager else 'data/common_items.json'
|
||||||
os.makedirs(data_dir, exist_ok=True)
|
if not os.path.isabs(fpath):
|
||||||
fpath = os.path.join(data_dir, 'common_items.json')
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
fpath = os.path.join(base_dir, fpath)
|
||||||
|
os.makedirs(os.path.dirname(fpath), exist_ok=True)
|
||||||
data = {'treatment': [], 'suggestion': []}
|
data = {'treatment': [], 'suggestion': []}
|
||||||
if os.path.exists(fpath):
|
if os.path.exists(fpath):
|
||||||
try:
|
try:
|
||||||
@ -436,10 +440,12 @@ class AppServer:
|
|||||||
label = str(payload.get('label', '')).strip()
|
label = str(payload.get('label', '')).strip()
|
||||||
if itype not in ['treatment', 'suggestion'] or not label:
|
if itype not in ['treatment', 'suggestion'] or not label:
|
||||||
return jsonify({'success': False, 'error': '参数无效'}), 400
|
return jsonify({'success': False, 'error': '参数无效'}), 400
|
||||||
base_dir = os.path.dirname(sys.executable) if getattr(sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
|
# 从配置读取通用项文件路径,支持相对backend目录
|
||||||
data_dir = os.path.join(base_dir, 'data')
|
fpath = self.config_manager.get_config_value('DATABASE', 'common_items_path', 'data/common_items.json') if self.config_manager else 'data/common_items.json'
|
||||||
os.makedirs(data_dir, exist_ok=True)
|
if not os.path.isabs(fpath):
|
||||||
fpath = os.path.join(data_dir, 'common_items.json')
|
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
fpath = os.path.join(base_dir, fpath)
|
||||||
|
os.makedirs(os.path.dirname(fpath), exist_ok=True)
|
||||||
data = {'treatment': [], 'suggestion': []}
|
data = {'treatment': [], 'suggestion': []}
|
||||||
if os.path.exists(fpath):
|
if os.path.exists(fpath):
|
||||||
try:
|
try:
|
||||||
@ -1190,7 +1196,7 @@ class AppServer:
|
|||||||
}), 400
|
}), 400
|
||||||
|
|
||||||
# 验证数据格式
|
# 验证数据格式
|
||||||
supported_devices = ['camera', 'femtobolt','imu','pressure']
|
supported_devices = ['camera1','camera2', 'femtobolt','imu','pressure']
|
||||||
for device_name in data.keys():
|
for device_name in data.keys():
|
||||||
if device_name not in supported_devices:
|
if device_name not in supported_devices:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user