|
|
@@ -197,37 +197,6 @@ async def update_image_modified_json(
|
|
|
if cursor:
|
|
|
cursor.close()
|
|
|
|
|
|
-
|
|
|
-@router.put("/_update/json/{id}", status_code=200, summary="修改图片的 modified_json")
|
|
|
-def _update_image_modified_json(
|
|
|
- id: int,
|
|
|
- new_json_data: Dict[str, Any],
|
|
|
- db_conn: PooledMySQLConnection = db_dependency
|
|
|
-):
|
|
|
- """根据 id 更新 modified_json 字段。updated_at 会自动更新。"""
|
|
|
- cursor = None
|
|
|
- try:
|
|
|
- cursor = db_conn.cursor()
|
|
|
- new_json_str = json.dumps(new_json_data, ensure_ascii=False)
|
|
|
- query = f"UPDATE {settings.DB_IMAGE_TABLE_NAME} SET modified_json = %s WHERE id = %s"
|
|
|
- cursor.execute(query, (new_json_str, id))
|
|
|
-
|
|
|
- if cursor.rowcount == 0:
|
|
|
- raise HTTPException(status_code=404, detail=f"ID为 {id} 的图片未找到。")
|
|
|
-
|
|
|
- db_conn.commit()
|
|
|
- logger.info(f"图片ID {id} 的 modified_json 已更新。")
|
|
|
- return {"message": f"成功更新图片ID {id} 的JSON数据"}
|
|
|
- except Exception as e:
|
|
|
- db_conn.rollback()
|
|
|
- logger.error(f"更新JSON失败 ({id}): {e}")
|
|
|
- if isinstance(e, HTTPException): raise e
|
|
|
- raise HTTPException(status_code=500, detail="更新JSON数据失败。")
|
|
|
- finally:
|
|
|
- if cursor:
|
|
|
- cursor.close()
|
|
|
-
|
|
|
-
|
|
|
@router.get("/image_file/{id}", summary="获取指定ID的图片文件")
|
|
|
def get_image_file(id: int, db_conn: PooledMySQLConnection = db_dependency):
|
|
|
"""根据 id 查找记录,并返回对应的图片文件。"""
|