diff --git a/Dockerfile b/Dockerfile index 2912ce4..b90e9b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Create necessary directories and set permissions -RUN mkdir -p /app/uploads/rooms /app/static/uploads && \ +RUN mkdir -p /app/uploads/rooms /app/uploads/profile_pics /app/static/uploads && \ chown -R celery:celery /app && \ chmod -R 755 /app/uploads diff --git a/__pycache__/tasks.cpython-313.pyc b/__pycache__/tasks.cpython-313.pyc index 0c5c467..a367d13 100644 Binary files a/__pycache__/tasks.cpython-313.pyc and b/__pycache__/tasks.cpython-313.pyc differ diff --git a/app.py b/app.py index 5ffd1a1..516d599 100644 --- a/app.py +++ b/app.py @@ -136,7 +136,7 @@ app = create_app() @app.route('/uploads/profile_pics/') def profile_pic(filename): - return send_from_directory(os.path.join(os.getcwd(), 'uploads', 'profile_pics'), filename) + return send_from_directory('/app/uploads/profile_pics', filename) if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/routes/__pycache__/admin.cpython-313.pyc b/routes/__pycache__/admin.cpython-313.pyc index 3304fd8..8037f5b 100644 Binary files a/routes/__pycache__/admin.cpython-313.pyc and b/routes/__pycache__/admin.cpython-313.pyc differ diff --git a/routes/__pycache__/contacts.cpython-313.pyc b/routes/__pycache__/contacts.cpython-313.pyc index 21bd10c..efe899d 100644 Binary files a/routes/__pycache__/contacts.cpython-313.pyc and b/routes/__pycache__/contacts.cpython-313.pyc differ diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index fae39a5..559ffd5 100644 Binary files a/routes/__pycache__/main.cpython-313.pyc and b/routes/__pycache__/main.cpython-313.pyc differ diff --git a/routes/__pycache__/room_files.cpython-313.pyc b/routes/__pycache__/room_files.cpython-313.pyc index 6167f99..1bc2819 100644 Binary files a/routes/__pycache__/room_files.cpython-313.pyc and b/routes/__pycache__/room_files.cpython-313.pyc differ diff --git a/routes/__pycache__/rooms.cpython-313.pyc b/routes/__pycache__/rooms.cpython-313.pyc index 4437009..a0f1ae8 100644 Binary files a/routes/__pycache__/rooms.cpython-313.pyc and b/routes/__pycache__/rooms.cpython-313.pyc differ diff --git a/routes/admin.py b/routes/admin.py index 7f34e49..2233d75 100644 --- a/routes/admin.py +++ b/routes/admin.py @@ -13,7 +13,7 @@ def sync_files(): return jsonify({'error': 'Unauthorized'}), 403 try: - DATA_ROOT = '/data/rooms' + DATA_ROOT = '/app/uploads/rooms' admin_user = User.query.filter_by(is_admin=True).first() if not admin_user: return jsonify({'error': 'No admin user found'}), 500 @@ -73,7 +73,7 @@ def verify_db_state(): return jsonify({'error': 'Unauthorized'}), 403 try: - DATA_ROOT = '/data/rooms' + DATA_ROOT = '/app/uploads/rooms' verification_results = { 'rooms_checked': 0, 'files_in_db_not_fs': [], @@ -208,7 +208,7 @@ def cleanup_orphaned_records(): return jsonify({'error': 'Unauthorized'}), 403 try: - DATA_ROOT = '/data/rooms' + DATA_ROOT = '/app/uploads/rooms' rooms = Room.query.all() cleaned_records = [] diff --git a/routes/contacts.py b/routes/contacts.py index 6403e64..aa0d92b 100644 --- a/routes/contacts.py +++ b/routes/contacts.py @@ -15,7 +15,7 @@ import string contacts_bp = Blueprint('contacts', __name__, url_prefix='/contacts') -UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads', 'profile_pics') +UPLOAD_FOLDER = '/app/uploads/profile_pics' if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) diff --git a/routes/main.py b/routes/main.py index 8d3390b..be016a9 100644 --- a/routes/main.py +++ b/routes/main.py @@ -332,7 +332,7 @@ def init_routes(main_bp): is_admin=current_user.is_admin ) - UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads', 'profile_pics') + UPLOAD_FOLDER = '/app/uploads/profile_pics' if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) diff --git a/routes/room_files.py b/routes/room_files.py index 287bb91..32a29d6 100644 --- a/routes/room_files.py +++ b/routes/room_files.py @@ -217,7 +217,6 @@ def upload_room_file(room_id): # If we are overwriting, delete the trashed file record db.session.delete(trashed_file) - db.session.commit() existing_file = None file.save(file_path) @@ -347,6 +346,19 @@ def delete_file(room_id, filename): if not rf: return jsonify({'error': 'File not found'}), 404 + # If it's a folder, mark all contained items as deleted + if rf.type == 'folder': + folder_path = os.path.join(rf.path, rf.name) if rf.path else rf.name + contained_items = RoomFile.query.filter( + RoomFile.room_id == room_id, + RoomFile.path.like(f"{folder_path}%") + ).all() + + for item in contained_items: + item.deleted = True + item.deleted_by = current_user.id + item.deleted_at = datetime.utcnow() + # Mark as deleted and record who deleted it and when rf.deleted = True rf.deleted_by = current_user.id @@ -1052,6 +1064,9 @@ def delete_permanent(room_id): for item in contained_items: db.session.delete(item) + + # Delete the database record + db.session.delete(rf) log_event( event_type='file_delete_permanent', @@ -1066,10 +1081,15 @@ def delete_permanent(room_id): user_id=current_user.id ) except Exception as e: - print(f"Error deleting {rf.type} from storage: {e}") - - # Delete the database record - db.session.delete(rf) + print(f"Error deleting file {rf.name}: {str(e)}") + continue + + # Commit all changes + try: + db.session.commit() + except Exception as e: + print(f"Error committing changes: {str(e)}") + db.session.rollback() + return jsonify({'error': 'Failed to delete files'}), 500 - db.session.commit() return jsonify({'success': True}) \ No newline at end of file diff --git a/routes/rooms.py b/routes/rooms.py index b3ea612..75312c8 100644 --- a/routes/rooms.py +++ b/routes/rooms.py @@ -346,7 +346,7 @@ def delete_room(room_id): print(f"Attempting to delete room {room_id} ({room_name})") # Delete physical files - room_dir = os.path.join('/data/rooms', str(room_id)) + room_dir = os.path.join('/app/uploads/rooms', str(room_id)) if os.path.exists(room_dir): shutil.rmtree(room_dir) print(f"Deleted room directory: {room_dir}") diff --git a/static/js/rooms/viewManager.js b/static/js/rooms/viewManager.js index c56df66..4308b91 100644 --- a/static/js/rooms/viewManager.js +++ b/static/js/rooms/viewManager.js @@ -348,13 +348,32 @@ export class ViewManager { renderFileActions(file, index) { const actions = []; - // Add details button - actions.push(` - - `); + // Check if file can be previewed + const extension = file.name.split('.').pop().toLowerCase(); + const previewableExtensions = [ + 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', + 'txt', 'md', 'csv', 'py', 'js', 'html', 'css', 'json', 'xml', 'sql', 'sh', 'bat', + 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp', 'tiff', + 'mp3', 'mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv' + ]; + + if (previewableExtensions.includes(extension)) { + // Add preview button for previewable files + actions.push(` + + `); + } else { + // Add details button for non-previewable files + actions.push(` + + `); + } // Add download button if user has permission if (this.roomManager.canDownload) { diff --git a/sync_room_files.py b/sync_room_files.py index 3f08036..a9c2d50 100644 --- a/sync_room_files.py +++ b/sync_room_files.py @@ -3,7 +3,7 @@ from datetime import datetime from app import create_app from models import db, Room, RoomFile, User -DATA_ROOT = '/data/rooms' +DATA_ROOT = '/app/uploads/rooms' app = create_app() diff --git a/tasks.py b/tasks.py index 9149741..a29d5bf 100644 --- a/tasks.py +++ b/tasks.py @@ -20,7 +20,7 @@ def cleanup_trash(): try: # Delete the file from storage if it's a file if file.type == 'file': - file_path = os.path.join('/data/rooms', str(file.room_id), file.path, file.name) + file_path = os.path.join('/app/uploads/rooms', str(file.room_id), file.path, file.name) if os.path.exists(file_path): os.remove(file_path)