Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Remove tow unused files (#22022)

Yongtao Huang521488f92688
diff --git a/api/core/file/models.py b/api/core/file/models.py
index aa3b5f629cc..f61334e7bc4 100644
--- a/api/core/file/models.py
+++ b/api/core/file/models.py
@@ -51,7 +51,7 @@ class File(BaseModel):
# It should be set to `ToolFile.id` when `transfer_method` is `tool_file`.
related_id: Optional[str] = None
filename: Optional[str] = None
- extension: Optional[str] = Field(default=None, description="File extension, should contains dot")
+ extension: Optional[str] = Field(default=None, description="File extension, should contain dot")
mime_type: Optional[str] = None
size: int = -1
diff --git a/api/core/file/upload_file_parser.py b/api/core/file/upload_file_parser.py
deleted file mode 100644
index 96b28848117..00000000000
--- a/api/core/file/upload_file_parser.py
+++ /dev/null
@@ -1,67 +0,0 @@
-import base64
-import logging
-import time
-from typing import Optional
-
-from configs import dify_config
-from constants import IMAGE_EXTENSIONS
-from core.helper.url_signer import UrlSigner
-from extensions.ext_storage import storage
-
-
-class UploadFileParser:
- @classmethod
- def get_image_data(cls, upload_file, force_url: bool = False) -> Optional[str]:
- if not upload_file:
- return None
-
- if upload_file.extension not in IMAGE_EXTENSIONS:
- return None
-
- if dify_config.MULTIMODAL_SEND_FORMAT == "url" or force_url:
- return cls.get_signed_temp_image_url(upload_file.id)
- else:
- # get image file base64
- try:
- data = storage.load(upload_file.key)
- except FileNotFoundError:
- logging.exception(f"File not found: {upload_file.key}")
- return None
-
- encoded_string = base64.b64encode(data).decode("utf-8")
- return f"data:{upload_file.mime_type};base64,{encoded_string}"
-
- @classmethod
- def get_signed_temp_image_url(cls, upload_file_id) -> str:
- """
- get signed url from upload file
-
- :param upload_file_id: the id of UploadFile object
- :return:
- """
- base_url = dify_config.FILES_URL
- image_preview_url = f"{base_url}/files/{upload_file_id}/image-preview"
-
- return UrlSigner.get_signed_url(url=image_preview_url, sign_key=upload_file_id, prefix="image-preview")
-
- @classmethod
- def verify_image_file_signature(cls, upload_file_id: str, timestamp: str, nonce: str, sign: str) -> bool:
- """
- verify signature
-
- :param upload_file_id: file id
- :param timestamp: timestamp
- :param nonce: nonce
- :param sign: signature
- :return:
- """
- result = UrlSigner.verify(
- sign_key=upload_file_id, timestamp=timestamp, nonce=nonce, sign=sign, prefix="image-preview"
- )
-
- # verify signature
- if not result:
- return False
-
- current_time = int(time.time())
- return current_time - int(timestamp) <= dify_config.FILES_ACCESS_TIMEOUT
diff --git a/api/core/helper/lru_cache.py b/api/core/helper/lru_cache.py
deleted file mode 100644
index 81501d2e4e2..00000000000
--- a/api/core/helper/lru_cache.py
+++ /dev/null
@@ -1,22 +0,0 @@
-from collections import OrderedDict
-from typing import Any
-
-
-class LRUCache:
- def __init__(self, capacity: int):
- self.cache: OrderedDict[Any, Any] = OrderedDict()
- self.capacity = capacity
-
- def get(self, key: Any) -> Any:
- if key not in self.cache:
- return None
- else:
- self.cache.move_to_end(key) # move the key to the end of the OrderedDict
- return self.cache[key]
-
- def put(self, key: Any, value: Any) -> None:
- if key in self.cache:
- self.cache.move_to_end(key)
- self.cache[key] = value
- if len(self.cache) > self.capacity:
- self.cache.popitem(last=False) # pop the first item