Commit b1cc8a27 authored by wuzekai's avatar wuzekai

Update ocr.py

parent 96e3991e
Pipeline #579 canceled with stages
......@@ -125,3 +125,34 @@ def download_image(uuid_str):
except Exception as e:
return jsonify({"error": f"Failed to send image: {str(e)}"}), 500
@ocr.route("/delete/<uuid_str>", methods=["DELETE"])
def delete_files(uuid_str):
if not is_valid_uuid(uuid_str):
return jsonify({"error": "Invalid UUID format"}), 400
deleted_files = []
# 删除上传的图片文件
image_file = os.path.join(upload_dir, f"{uuid_str}.jpg")
if os.path.exists(image_file):
os.remove(image_file)
deleted_files.append(f"{uuid_str}.jpg")
# 删除输出的 JSON 文件
json_file = os.path.join(output_dir, f"{uuid_str}.json")
if os.path.exists(json_file):
os.remove(json_file)
deleted_files.append(f"{uuid_str}.json")
# 删除 OCR 结果文件
result_file = os.path.join(result_dir, f"{uuid_str}.jpg")
if os.path.exists(result_file):
os.remove(result_file)
deleted_files.append(f"{uuid_str}.jpg")
if not deleted_files:
return jsonify({"message": "No files found for this UUID"}), 404
return jsonify({
"message": "Files deleted successfully",
"deleted_files": deleted_files
}), 200
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment