refac
This commit is contained in:
1 parent
9ef579ce4b
commit
2f642754ac
1 file changed
+7
-2
@@ -253,14 +253,19 @@ async def _resolve_file(ref: str, user: dict, model_knowledge: list[dict] | None
|
|||||||
"""Resolve a file reference (ID or filename) to a file info dict with content."""
|
"""Resolve a file reference (ID or filename) to a file info dict with content."""
|
||||||
from open_webui.models.files import Files
|
from open_webui.models.files import Files
|
||||||
|
|
||||||
# Try direct ID lookup first
|
# Get the set of files this user can access
|
||||||
|
accessible = await _get_accessible_files(user, model_knowledge)
|
||||||
|
accessible_ids = {fi['id'] for fi in accessible}
|
||||||
|
|
||||||
|
# Try direct ID lookup first — but verify access
|
||||||
f = await Files.get_file_by_id(ref)
|
f = await Files.get_file_by_id(ref)
|
||||||
if f and f.data:
|
if f and f.data:
|
||||||
|
if f.id not in accessible_ids:
|
||||||
|
return None # User cannot access this file
|
||||||
return {'id': f.id, 'filename': f.filename, 'content': f.data.get('content', ''),
|
return {'id': f.id, 'filename': f.filename, 'content': f.data.get('content', ''),
|
||||||
'meta': f.meta, 'updated_at': f.updated_at, 'created_at': f.created_at}
|
'meta': f.meta, 'updated_at': f.updated_at, 'created_at': f.created_at}
|
||||||
|
|
||||||
# Try filename match within accessible files
|
# Try filename match within accessible files
|
||||||
accessible = await _get_accessible_files(user, model_knowledge)
|
|
||||||
matches = [fi for fi in accessible if fi['filename'] == ref]
|
matches = [fi for fi in accessible if fi['filename'] == ref]
|
||||||
|
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
|
|||||||
Reference in new issue
Block a user