Add constants and utility function for file storage
This commit is contained in:
parent
4b08504ff7
commit
ab1c3f0b85
3 changed files with 37 additions and 4 deletions
28
src/backend/langflow/services/storage/constants.py
Normal file
28
src/backend/langflow/services/storage/constants.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
EXTENSION_TO_CONTENT_TYPE = {
|
||||||
|
"json": "application/json",
|
||||||
|
"txt": "text/plain",
|
||||||
|
"csv": "text/csv",
|
||||||
|
"html": "text/html",
|
||||||
|
"pdf": "application/pdf",
|
||||||
|
"png": "image/png",
|
||||||
|
"jpg": "image/jpeg",
|
||||||
|
"jpeg": "image/jpeg",
|
||||||
|
"gif": "image/gif",
|
||||||
|
"svg": "image/svg+xml",
|
||||||
|
"mp3": "audio/mpeg",
|
||||||
|
"wav": "audio/wav",
|
||||||
|
"mp4": "video/mp4",
|
||||||
|
"webm": "video/webm",
|
||||||
|
"zip": "application/zip",
|
||||||
|
"tar": "application/x-tar",
|
||||||
|
"gz": "application/gzip",
|
||||||
|
"doc": "application/msword",
|
||||||
|
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
"xls": "application/vnd.ms-excel",
|
||||||
|
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
"ppt": "application/vnd.ms-powerpoint",
|
||||||
|
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||||
|
"xml": "application/xml",
|
||||||
|
"yaml": "application/x-yaml",
|
||||||
|
"yml": "application/x-yaml",
|
||||||
|
}
|
||||||
|
|
@ -18,19 +18,19 @@ class StorageService(Service):
|
||||||
self.ready = True
|
self.ready = True
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def save_file(self, folder: str, file_name: str, data):
|
def save_file(self, folder: str, file_name: str, data) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_file(self, folder: str, file_name: str):
|
def get_file(self, folder: str, file_name: str) -> bytes:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def list_files(self, folder: str):
|
def list_files(self, folder: str) -> list[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete_file(self, folder: str, file_name: str):
|
def delete_file(self, folder: str, file_name: str) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
|
|
|
||||||
5
src/backend/langflow/services/storage/utils.py
Normal file
5
src/backend/langflow/services/storage/utils.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from langflow.services.storage.constants import EXTENSION_TO_CONTENT_TYPE
|
||||||
|
|
||||||
|
|
||||||
|
def build_content_type_from_extension(extension: str):
|
||||||
|
return EXTENSION_TO_CONTENT_TYPE.get(extension.lower(), "application/octet-stream")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue