mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 01:18:05 +08:00
feat: add exists method to sandbox sources for existence checks
- Implemented the `exists` method in `SandboxFileSource` and its subclasses to verify the availability of sandbox sources. - Updated `SandboxFileService` to utilize the new `exists` method for improved error handling when listing files and downloading files. - Removed the previous check for storage existence in `archive_source.py` and replaced it with the new method.
This commit is contained in:
@ -20,6 +20,12 @@ class SandboxFileService:
|
||||
cache_key_prefix="sandbox_files",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def exists(cls, *, tenant_id: str, sandbox_id: str) -> bool:
|
||||
"""Check if the sandbox source exists and is available."""
|
||||
browser = SandboxFileBrowser(tenant_id=tenant_id, sandbox_id=sandbox_id)
|
||||
return browser.exists()
|
||||
|
||||
@classmethod
|
||||
def list_files(
|
||||
cls,
|
||||
@ -30,9 +36,13 @@ class SandboxFileService:
|
||||
recursive: bool = False,
|
||||
) -> list[SandboxFileNode]:
|
||||
browser = SandboxFileBrowser(tenant_id=tenant_id, sandbox_id=sandbox_id)
|
||||
if not browser.exists():
|
||||
return []
|
||||
return browser.list_files(path=path, recursive=recursive)
|
||||
|
||||
@classmethod
|
||||
def download_file(cls, *, tenant_id: str, sandbox_id: str, path: str) -> SandboxFileDownloadTicket:
|
||||
browser = SandboxFileBrowser(tenant_id=tenant_id, sandbox_id=sandbox_id)
|
||||
if not browser.exists():
|
||||
raise ValueError("Sandbox source not found")
|
||||
return browser.download_file(path=path)
|
||||
|
||||
Reference in New Issue
Block a user