search inside folders
This commit is contained in:
@@ -557,32 +557,49 @@ def download_zip(room_id):
|
||||
@login_required
|
||||
def search_room_files(room_id):
|
||||
"""
|
||||
Search for files in a room by name.
|
||||
Search for files in a room by name, including files in subfolders.
|
||||
|
||||
Args:
|
||||
room_id (int): ID of the room to search in
|
||||
|
||||
Returns:
|
||||
JSON response containing matching files
|
||||
JSON response containing matching files with their full paths
|
||||
"""
|
||||
room = Room.query.get_or_404(room_id)
|
||||
if not user_has_permission(room, 'can_view'):
|
||||
abort(403)
|
||||
query = request.args.get('query', '').strip().lower()
|
||||
|
||||
# Search RoomFile for this room
|
||||
files = RoomFile.query.filter(RoomFile.room_id==room_id).all()
|
||||
files = RoomFile.query.filter(RoomFile.room_id==room_id, RoomFile.deleted==False).all()
|
||||
matches = []
|
||||
|
||||
for f in files:
|
||||
if query in f.name.lower():
|
||||
# Create full path by combining folder path and filename
|
||||
full_path = f"{f.path}/{f.name}" if f.path else f.name
|
||||
|
||||
if query in f.name.lower() or query in full_path.lower():
|
||||
uploader_full_name = None
|
||||
uploader_profile_pic = None
|
||||
if f.uploader:
|
||||
uploader_full_name = f.uploader.username
|
||||
if getattr(f.uploader, 'last_name', None):
|
||||
uploader_full_name += ' ' + f.uploader.last_name
|
||||
uploader_profile_pic = f.uploader.profile_picture if getattr(f.uploader, 'profile_picture', None) else None
|
||||
|
||||
matches.append({
|
||||
'name': f.name,
|
||||
'type': f.type,
|
||||
'size': f.size if f.type == 'file' else '-',
|
||||
'modified': f.modified,
|
||||
'uploaded_by': f.uploader.username if f.uploader else None,
|
||||
'uploaded_by': uploader_full_name,
|
||||
'uploader_profile_pic': uploader_profile_pic,
|
||||
'uploaded_at': f.uploaded_at.isoformat() if f.uploaded_at else None,
|
||||
'path': f.path,
|
||||
'full_path': full_path, # Add full path to the response
|
||||
'starred': current_user in f.starred_by
|
||||
})
|
||||
|
||||
return jsonify(matches)
|
||||
|
||||
@room_files_bp.route('/<int:room_id>/move', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user