From 758e1a18e44ca9f832b13a30c5558d0b6904a37e Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 12 Jan 2026 22:01:32 -0500 Subject: [PATCH] images --- backend/services/export_import_service.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/backend/services/export_import_service.py b/backend/services/export_import_service.py index b21c789..ce5ff30 100644 --- a/backend/services/export_import_service.py +++ b/backend/services/export_import_service.py @@ -50,8 +50,9 @@ def export_questions_to_zip() -> Tuple[bytes, str]: 'created_at': category.created_at.isoformat() if category.created_at else None }) - # Get base folder for file operations - base_folder = Path(current_app.config.get('UPLOAD_FOLDER')).parent.parent + # Get folders for file operations + images_folder = Path(current_app.config.get('UPLOAD_FOLDER')) + audio_folder = Path(current_app.config.get('AUDIO_FOLDER')) # Export questions with media files missing_files = [] @@ -78,7 +79,7 @@ def export_questions_to_zip() -> Tuple[bytes, str]: question_data['image_filename'] = image_filename # Copy image file to temp directory - source_path = os.path.join(base_folder, question.image_path.lstrip('/')) + source_path = os.path.join(images_folder, image_filename) dest_path = os.path.join(images_dir, image_filename) if os.path.exists(source_path): @@ -97,7 +98,7 @@ def export_questions_to_zip() -> Tuple[bytes, str]: question_data['audio_filename'] = audio_filename # Copy audio file to temp directory - source_path = os.path.join(base_folder, question.audio_path.lstrip('/')) + source_path = os.path.join(audio_folder, audio_filename) dest_path = os.path.join(audio_dir, audio_filename) if os.path.exists(source_path): @@ -249,10 +250,11 @@ def clear_all_data(): def clear_all_media_files(): """Delete all images and audio files from static directories.""" - base_folder = Path(current_app.config.get('UPLOAD_FOLDER')).parent.parent + # Get folders from config + images_dir = str(Path(current_app.config.get('UPLOAD_FOLDER'))) + audio_dir = str(Path(current_app.config.get('AUDIO_FOLDER'))) # Clear images - images_dir = os.path.join(base_folder, 'backend', 'static', 'images') if os.path.exists(images_dir): for filename in os.listdir(images_dir): if filename == '.gitkeep': @@ -265,7 +267,6 @@ def clear_all_media_files(): print(f"Warning: Failed to delete {file_path}: {e}") # Clear audio - audio_dir = os.path.join(base_folder, 'backend', 'static', 'audio') if os.path.exists(audio_dir): for filename in os.listdir(audio_dir): if filename == '.gitkeep': @@ -311,10 +312,9 @@ def import_questions_from_zip(zip_path: str) -> dict: with open(manifest_path, 'r') as f: manifest = json.load(f) - # Get base folder for file operations - base_folder = Path(current_app.config.get('UPLOAD_FOLDER')).parent.parent - images_dest_dir = os.path.join(base_folder, 'backend', 'static', 'images') - audio_dest_dir = os.path.join(base_folder, 'backend', 'static', 'audio') + # Get destination folders from config + images_dest_dir = str(Path(current_app.config.get('UPLOAD_FOLDER'))) + audio_dest_dir = str(Path(current_app.config.get('AUDIO_FOLDER'))) # Ensure destination directories exist os.makedirs(images_dest_dir, exist_ok=True)