mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
refactor: upload excel error tips
This commit is contained in:
@@ -565,7 +565,7 @@ async def parse_excel(file: UploadFile = File(..., description=f"{PLACEHOLDER_PR
|
||||
|
||||
|
||||
@router.post("/importToDb", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_import_to_db")
|
||||
async def import_to_db(session: SessionDep, import_req: ImportRequest):
|
||||
async def import_to_db(session: SessionDep, trans: Trans, import_req: ImportRequest):
|
||||
save_path = os.path.join(path, import_req.filePath)
|
||||
if not os.path.exists(save_path):
|
||||
raise HTTPException(400, "File not found")
|
||||
@@ -585,11 +585,14 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest):
|
||||
for col in field_mapping.keys()
|
||||
}
|
||||
|
||||
if save_path.endswith(".csv"):
|
||||
df = pd.read_csv(save_path, engine='c', dtype=dtype_dict)
|
||||
sheet_name = "Sheet1"
|
||||
else:
|
||||
df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict)
|
||||
try:
|
||||
if save_path.endswith(".csv"):
|
||||
df = pd.read_csv(save_path, engine='c', dtype=dtype_dict)
|
||||
sheet_name = "Sheet1"
|
||||
else:
|
||||
df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict)
|
||||
except Exception as e:
|
||||
raise HTTPException(500, f"{trans('i18n_ds_upload_error')}: {str(e)}")
|
||||
|
||||
conn = engine.raw_connection()
|
||||
cursor = conn.cursor()
|
||||
@@ -615,7 +618,7 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest):
|
||||
"rows": len(df)
|
||||
})
|
||||
except Exception as e:
|
||||
raise HTTPException(400, f"Insert data failed for {table_name}: {str(e)}")
|
||||
raise HTTPException(500, f"Insert data failed for {table_name}: {str(e)}")
|
||||
finally:
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"miss_default": "Default large language model has not been configured"
|
||||
},
|
||||
"i18n_ds_invalid": "Datasource connection is invalid",
|
||||
"i18n_ds_upload_error": "Upload Failed",
|
||||
"i18n_embedded": {
|
||||
"invalid_origin": "Domain name validation failed【{origin}】"
|
||||
},
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"miss_default": "기본 대형 언어 모델이 구성되지 않았습니다"
|
||||
},
|
||||
"i18n_ds_invalid": "데이터 소스 연결이 무효합니다",
|
||||
"i18n_ds_upload_error": "파일 업로드 실패",
|
||||
"i18n_embedded": {
|
||||
"invalid_origin": "도메인 이름 검증 실패 【{origin}】"
|
||||
},
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"miss_default": "尚未配置默认大语言模型"
|
||||
},
|
||||
"i18n_ds_invalid": "数据源连接无效",
|
||||
"i18n_ds_upload_error": "上传文件失败",
|
||||
"i18n_embedded": {
|
||||
"invalid_origin": "域名校验失败【{origin}】"
|
||||
},
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"miss_default": "尚未配置默認大語言模型"
|
||||
},
|
||||
"i18n_ds_invalid": "數據源連接無效",
|
||||
"i18n_ds_upload_error": "上傳文件失敗",
|
||||
"i18n_embedded": {
|
||||
"invalid_origin": "網域校驗失敗【{origin}】"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user