From b1cc8a2781cde76a125d14b111f73a4051f227b9 Mon Sep 17 00:00:00 2001 From: wuzekai <3025054974@qq.com> Date: Tue, 8 Jul 2025 05:24:52 +0000 Subject: [PATCH] Update ocr.py --- ocr.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ocr.py b/ocr.py index bdac9b9..aafa3db 100644 --- a/ocr.py +++ b/ocr.py @@ -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/", 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 -- 2.22.0