plokmii commited on
Commit
76749e0
·
verified ·
1 Parent(s): b1f6e79

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -1005,12 +1005,22 @@ def cloud_sync():
1005
 
1006
  cloud_info = sync_module.get_db_info(cloud_path)
1007
 
 
 
 
 
 
 
 
 
1008
  if (local_info['latest'] == cloud_info['latest']
1009
  and local_info['reports'] == cloud_info['reports']
1010
  and local_info['patients'] == cloud_info['patients']
1011
  and local_info['users'] == cloud_info['users']):
1012
- summary = f"兩邊一致 — {local_info['patients']} 病患、{local_info['reports']} 報告、{local_info['users']} 使用者"
1013
- return jsonify({'ok': True, 'summary': summary})
 
 
1014
 
1015
  sync_module.backup_local()
1016
  merged_path, stats = sync_module.merge_dbs(sync_module.LOCAL_DB, cloud_path)
@@ -1020,10 +1030,17 @@ def cloud_sync():
1020
  sync_module.upload_db(sync_module.LOCAL_DB)
1021
 
1022
  merged_info = sync_module.get_db_info(sync_module.LOCAL_DB)
1023
- summary = (f"新增 {stats['patients_added']} 病患、{stats['reports_added']} 報告、{stats['users_added']} 使用者 | "
1024
- f"更新 {stats['reports_updated']} 報告、{stats.get('users_updated',0)} 使用者 | "
1025
- f"合計 {merged_info['patients']} 病患{merged_info['reports']} 報告、{merged_info['users']} 使用者")
1026
- return jsonify({'ok': True, 'summary': summary})
 
 
 
 
 
 
 
1027
  except Exception as e:
1028
  return jsonify({'error': str(e)})
1029
 
 
1005
 
1006
  cloud_info = sync_module.get_db_info(cloud_path)
1007
 
1008
+ result = {
1009
+ 'ok': True,
1010
+ 'before': {
1011
+ 'local': f"{local_info['patients']} 病患 / {local_info['reports']} 報告",
1012
+ 'cloud': f"{cloud_info['patients']} 病患 / {cloud_info['reports']} 報告",
1013
+ }
1014
+ }
1015
+
1016
  if (local_info['latest'] == cloud_info['latest']
1017
  and local_info['reports'] == cloud_info['reports']
1018
  and local_info['patients'] == cloud_info['patients']
1019
  and local_info['users'] == cloud_info['users']):
1020
+ result['status'] = 'identical'
1021
+ result['message'] = '兩邊一致,不需要同步'
1022
+ result['after'] = result['before']['local']
1023
+ return jsonify(result)
1024
 
1025
  sync_module.backup_local()
1026
  merged_path, stats = sync_module.merge_dbs(sync_module.LOCAL_DB, cloud_path)
 
1030
  sync_module.upload_db(sync_module.LOCAL_DB)
1031
 
1032
  merged_info = sync_module.get_db_info(sync_module.LOCAL_DB)
1033
+ result['status'] = 'synced'
1034
+ result['message'] = '同步完成'
1035
+ result['after'] = f"{merged_info['patients']} 病患 / {merged_info['reports']} 報告"
1036
+ result['details'] = {
1037
+ 'patients_added': stats['patients_added'],
1038
+ 'reports_added': stats['reports_added'],
1039
+ 'reports_updated': stats['reports_updated'],
1040
+ 'users_added': stats['users_added'],
1041
+ 'users_updated': stats.get('users_updated', 0),
1042
+ }
1043
+ return jsonify(result)
1044
  except Exception as e:
1045
  return jsonify({'error': str(e)})
1046