SOY NV AI
commited on
Commit
Β·
e5a14e2
1
Parent(s):
e044254
Fix: Add file path validation and better error handling for file reading in Parent Chunk creation
Browse files- app/routes.py +19 -1
app/routes.py
CHANGED
|
@@ -3670,6 +3670,12 @@ def create_file_parent_chunk(file_id):
|
|
| 3670 |
if not file.original_filename.lower().endswith(('.txt', '.md')):
|
| 3671 |
return jsonify({'error': 'Parent Chunkλ ν
μ€νΈ νμΌ(.txt, .md)μλ§ μμ±ν μ μμ΅λλ€.'}), 400
|
| 3672 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3673 |
# νμΌ λ΄μ© μ½κΈ°
|
| 3674 |
try:
|
| 3675 |
encoding = 'utf-8'
|
|
@@ -3679,8 +3685,20 @@ def create_file_parent_chunk(file_id):
|
|
| 3679 |
except UnicodeDecodeError:
|
| 3680 |
with open(file.file_path, 'r', encoding='cp949') as f:
|
| 3681 |
content = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3682 |
except Exception as e:
|
| 3683 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3684 |
|
| 3685 |
if not content or len(content.strip()) == 0:
|
| 3686 |
return jsonify({'error': 'νμΌ λ΄μ©μ΄ λΉμ΄μμ΅λλ€.'}), 400
|
|
|
|
| 3670 |
if not file.original_filename.lower().endswith(('.txt', '.md')):
|
| 3671 |
return jsonify({'error': 'Parent Chunkλ ν
μ€νΈ νμΌ(.txt, .md)μλ§ μμ±ν μ μμ΅λλ€.'}), 400
|
| 3672 |
|
| 3673 |
+
# νμΌ κ²½λ‘ νμΈ
|
| 3674 |
+
if not file.file_path or not os.path.exists(file.file_path):
|
| 3675 |
+
error_msg = f'νμΌ κ²½λ‘κ° μ ν¨νμ§ μμ΅λλ€: {file.file_path}'
|
| 3676 |
+
print(f"[Parent Chunk μμ±] β μ€λ₯: {error_msg}")
|
| 3677 |
+
return jsonify({'error': error_msg}), 500
|
| 3678 |
+
|
| 3679 |
# νμΌ λ΄μ© μ½κΈ°
|
| 3680 |
try:
|
| 3681 |
encoding = 'utf-8'
|
|
|
|
| 3685 |
except UnicodeDecodeError:
|
| 3686 |
with open(file.file_path, 'r', encoding='cp949') as f:
|
| 3687 |
content = f.read()
|
| 3688 |
+
except FileNotFoundError:
|
| 3689 |
+
error_msg = f'νμΌμ μ°Ύμ μ μμ΅λλ€: {file.file_path}'
|
| 3690 |
+
print(f"[Parent Chunk μμ±] β μ€λ₯: {error_msg}")
|
| 3691 |
+
return jsonify({'error': error_msg}), 500
|
| 3692 |
+
except PermissionError:
|
| 3693 |
+
error_msg = f'νμΌ μ½κΈ° κΆνμ΄ μμ΅λλ€: {file.file_path}'
|
| 3694 |
+
print(f"[Parent Chunk μμ±] β μ€λ₯: {error_msg}")
|
| 3695 |
+
return jsonify({'error': error_msg}), 500
|
| 3696 |
except Exception as e:
|
| 3697 |
+
error_msg = f'νμΌμ μ½μ μ μμ΅λλ€: {str(e)}'
|
| 3698 |
+
print(f"[Parent Chunk μμ±] β μ€λ₯: {error_msg}")
|
| 3699 |
+
import traceback
|
| 3700 |
+
traceback.print_exc()
|
| 3701 |
+
return jsonify({'error': error_msg}), 500
|
| 3702 |
|
| 3703 |
if not content or len(content.strip()) == 0:
|
| 3704 |
return jsonify({'error': 'νμΌ λ΄μ©μ΄ λΉμ΄μμ΅λλ€.'}), 400
|