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 search_options and search_options.get('recursive', True):
# Recursive folder filtering - include all subfolders
data = [
item for item in data
if item['folder'].startswith(folder)
]
# Ensure we match exact folder or its subfolders by checking path boundaries
if 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:
# Exact folder filtering
data = [