mirror of
https://github.com/open-webui/computer.git
synced 2026-11-30 00:45:14 -05:00
refac
This commit is contained in:
1 parent
e8003e6399
commit
dbb9ea1625
2 files changed
+39
-23
No files matched your search
@@ -128,6 +128,29 @@
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Bubble: right-aligned -->
|
||||
{#if meta?.files?.length > 0}
|
||||
<div class="mb-1 w-full flex flex-col justify-end overflow-x-auto gap-1 flex-wrap">
|
||||
{#each meta.files as upload}
|
||||
<div class="self-end">
|
||||
{#if upload.type === 'image'}
|
||||
<img src={upload.url} alt={upload.name || 'image'} class="max-h-96 rounded-lg" />
|
||||
{:else}
|
||||
<div class="relative group py-1.5 px-2 w-48 flex items-center gap-1.5 bg-white dark:bg-[#1a1a1a] border border-gray-100 dark:border-white/5 rounded-xl text-left flex-shrink-0 shadow-sm">
|
||||
<div class="shrink-0">
|
||||
<Icon name="page-text" size={14} class="text-gray-500 dark:text-gray-400" />
|
||||
</div>
|
||||
<div class="flex flex-col justify-center w-full overflow-hidden">
|
||||
<div class="dark:text-gray-100 text-xs flex justify-between items-center w-full gap-2">
|
||||
<div class="font-medium truncate flex-1">{upload.name || 'File'}</div>
|
||||
<div class="text-[10px] text-gray-500 capitalize shrink-0">{upload.type === 'file' ? 'File' : (upload.type || 'File')}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="flex justify-end">
|
||||
<div class="max-w-[90%] px-4 py-2 rounded-3xl bg-gray-50 dark:bg-white/[0.06]">
|
||||
<div
|
||||
@@ -154,27 +177,6 @@
|
||||
/>{segment.label}</button
|
||||
>{/if}{/each}
|
||||
</div>
|
||||
{#if meta?.files?.length > 0}
|
||||
<div class="flex flex-wrap gap-2 mt-3">
|
||||
{#each meta.files as upload}
|
||||
{#if upload.type === 'image'}
|
||||
<img src={upload.url} alt={upload.name || 'image'} class="max-w-[240px] max-h-[240px] rounded-xl object-cover shadow-sm border border-gray-100 dark:border-white/5" />
|
||||
{:else}
|
||||
<div class="relative group py-1.5 px-2 w-48 flex items-center gap-1.5 bg-white dark:bg-[#1a1a1a] border border-gray-100 dark:border-white/5 rounded-xl text-left flex-shrink-0 shadow-sm">
|
||||
<div class="shrink-0">
|
||||
<Icon name="page-text" size={14} class="text-gray-500 dark:text-gray-400" />
|
||||
</div>
|
||||
<div class="flex flex-col justify-center w-full overflow-hidden">
|
||||
<div class="dark:text-gray-100 text-xs flex justify-between items-center w-full gap-2">
|
||||
<div class="font-medium truncate flex-1">{upload.name || 'File'}</div>
|
||||
<div class="text-[10px] text-gray-500 capitalize shrink-0">{upload.type === 'file' ? 'File' : (upload.type || 'File')}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{#if siblingTotal > 1 || onedit}
|
||||
|
||||
+16
-2
@@ -75,7 +75,8 @@ async def read_file(
|
||||
workspace: str,
|
||||
) -> str:
|
||||
"""Read file contents with optional line range. Lines are 1-indexed.
|
||||
:param path: Path relative to workspace root.
|
||||
Supports absolute paths for user-attached files.
|
||||
:param path: Path relative to workspace root, or absolute path for attached files.
|
||||
:param start_line: First line to read (1-indexed, 0 = from beginning).
|
||||
:param end_line: Last line to read (inclusive, 0 = to end of file).
|
||||
"""
|
||||
@@ -543,7 +544,20 @@ async def read_url(url: str, *, workspace: str) -> str:
|
||||
|
||||
|
||||
def _resolve_path(path: str, workspace: str) -> Path:
|
||||
"""Resolve a relative path within the workspace. Rejects traversal."""
|
||||
"""Resolve a path within the workspace or uploads dir. Rejects traversal."""
|
||||
from cptr.utils.storage import UPLOADS_DIR
|
||||
|
||||
p = Path(path)
|
||||
# Allow absolute paths to the uploads directory (for user-attached files)
|
||||
if p.is_absolute():
|
||||
full = p.resolve()
|
||||
uploads = str(UPLOADS_DIR.resolve())
|
||||
ws = str(Path(workspace).resolve())
|
||||
if str(full).startswith(uploads) or str(full).startswith(ws):
|
||||
return full
|
||||
raise ValueError(f"Path outside allowed directories: {path}")
|
||||
|
||||
# Relative paths resolve against workspace
|
||||
ws = Path(workspace).resolve()
|
||||
full = (ws / path).resolve()
|
||||
if not str(full).startswith(str(ws)):
|
||||
|
||||
Reference in new issue
Block a user