feat: Improve folder filtering logic to ensure exact matches and handle root folder case

This commit is contained in:
Will Miao
2025-08-28 05:33:53 +08:00
parent 7a8b7598c7
commit a4074c93bc

View File

@@ -142,10 +142,18 @@ class BaseModelService(ABC):
if folder is not None: if folder is not None:
if search_options and search_options.get('recursive', True): if search_options and search_options.get('recursive', True):
# Recursive folder filtering - include all subfolders # Recursive folder filtering - include all subfolders
data = [ # Ensure we match exact folder or its subfolders by checking path boundaries
item for item in data if folder == "":
if item['folder'].startswith(folder) # Empty folder means root - include all items
] pass # Don't filter anything
else:
# Add trailing slash to ensure we match folder boundaries correctly
folder_with_separator = folder + "/"
data = [
item for item in data
if (item['folder'] == folder or
item['folder'].startswith(folder_with_separator))
]
else: else:
# Exact folder filtering # Exact folder filtering
data = [ data = [