diff --git a/ocr.py b/ocr.py index bdac9b982429a8e452b7c7f1bf9e15126c70bb09..aafa3db6d249114b487759729411006c0959f571 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