Upload app.py with huggingface_hub
Browse files
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 |
-
|
| 1013 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 1024 |
-
|
| 1025 |
-
|
| 1026 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|