refac
This commit is contained in:
1 parent
804f9f3153
commit
4866bec0f2
3 files changed
+12
-10
No files matched your search
@@ -124,7 +124,7 @@ async def process_uploaded_file(
|
|||||||
stt_supported_content_types = getattr(request.app.state.config, 'STT_SUPPORTED_CONTENT_TYPES', [])
|
stt_supported_content_types = getattr(request.app.state.config, 'STT_SUPPORTED_CONTENT_TYPES', [])
|
||||||
|
|
||||||
if strict_match_mime_type(stt_supported_content_types, content_type):
|
if strict_match_mime_type(stt_supported_content_types, content_type):
|
||||||
file_path_processed = Storage.get_file(file_path)
|
file_path_processed = await asyncio.to_thread(Storage.get_file, file_path)
|
||||||
result = transcribe(request, file_path_processed, file_metadata, user)
|
result = transcribe(request, file_path_processed, file_metadata, user)
|
||||||
|
|
||||||
await process_file(
|
await process_file(
|
||||||
@@ -242,7 +242,8 @@ async def upload_file_handler(
|
|||||||
id = str(uuid.uuid4())
|
id = str(uuid.uuid4())
|
||||||
name = filename
|
name = filename
|
||||||
filename = f'{id}_{filename}'
|
filename = f'{id}_{filename}'
|
||||||
contents, file_path = Storage.upload_file(
|
contents, file_path = await asyncio.to_thread(
|
||||||
|
Storage.upload_file,
|
||||||
file.file,
|
file.file,
|
||||||
filename,
|
filename,
|
||||||
{
|
{
|
||||||
@@ -406,7 +407,7 @@ async def delete_all_files(user=Depends(get_admin_user), db: AsyncSession = Depe
|
|||||||
result = await Files.delete_all_files(db=db)
|
result = await Files.delete_all_files(db=db)
|
||||||
if result:
|
if result:
|
||||||
try:
|
try:
|
||||||
Storage.delete_all_files()
|
await asyncio.to_thread(Storage.delete_all_files)
|
||||||
await ASYNC_VECTOR_DB_CLIENT.reset()
|
await ASYNC_VECTOR_DB_CLIENT.reset()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
@@ -618,7 +619,7 @@ async def get_file_content_by_id(
|
|||||||
|
|
||||||
if file.user_id == user.id or user.role == 'admin' or await has_access_to_file(id, 'read', user, db=db):
|
if file.user_id == user.id or user.role == 'admin' or await has_access_to_file(id, 'read', user, db=db):
|
||||||
try:
|
try:
|
||||||
file_path = Storage.get_file(file.path)
|
file_path = await asyncio.to_thread(Storage.get_file, file.path)
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
||||||
# Check if the file already exists in the cache
|
# Check if the file already exists in the cache
|
||||||
@@ -685,7 +686,7 @@ async def get_html_file_content_by_id(
|
|||||||
|
|
||||||
if file.user_id == user.id or user.role == 'admin' or await has_access_to_file(id, 'read', user, db=db):
|
if file.user_id == user.id or user.role == 'admin' or await has_access_to_file(id, 'read', user, db=db):
|
||||||
try:
|
try:
|
||||||
file_path = Storage.get_file(file.path)
|
file_path = await asyncio.to_thread(Storage.get_file, file.path)
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
||||||
# Check if the file already exists in the cache
|
# Check if the file already exists in the cache
|
||||||
@@ -734,7 +735,7 @@ async def get_file_content_by_id(
|
|||||||
headers = {'Content-Disposition': f"attachment; filename*=UTF-8''{encoded_filename}"}
|
headers = {'Content-Disposition': f"attachment; filename*=UTF-8''{encoded_filename}"}
|
||||||
|
|
||||||
if file_path:
|
if file_path:
|
||||||
file_path = Storage.get_file(file_path)
|
file_path = await asyncio.to_thread(Storage.get_file, file_path)
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
||||||
# Check if the file already exists in the cache
|
# Check if the file already exists in the cache
|
||||||
@@ -798,7 +799,7 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user), db: AsyncS
|
|||||||
result = await Files.delete_file_by_id(id, db=db)
|
result = await Files.delete_file_by_id(id, db=db)
|
||||||
if result:
|
if result:
|
||||||
try:
|
try:
|
||||||
Storage.delete_file(file.path)
|
await asyncio.to_thread(Storage.delete_file, file.path)
|
||||||
await ASYNC_VECTOR_DB_CLIENT.delete(collection_name=f'file-{id}')
|
await ASYNC_VECTOR_DB_CLIENT.delete(collection_name=f'file-{id}')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|||||||
@@ -1612,7 +1612,7 @@ async def process_file(
|
|||||||
# Usage: /files/
|
# Usage: /files/
|
||||||
file_path = file.path
|
file_path = file.path
|
||||||
if file_path:
|
if file_path:
|
||||||
file_path = Storage.get_file(file_path)
|
file_path = await asyncio.to_thread(Storage.get_file, file_path)
|
||||||
loader = Loader(
|
loader = Loader(
|
||||||
engine=request.app.state.config.CONTENT_EXTRACTION_ENGINE,
|
engine=request.app.state.config.CONTENT_EXTRACTION_ENGINE,
|
||||||
user=user,
|
user=user,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from open_webui.models.files import Files
|
|||||||
from open_webui.routers.files import upload_file_handler
|
from open_webui.routers.files import upload_file_handler
|
||||||
from open_webui.retrieval.web.utils import validate_url
|
from open_webui.retrieval.web.utils import validate_url
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
@@ -51,7 +52,7 @@ async def get_image_base64_from_url(url: str) -> Optional[str]:
|
|||||||
if not file:
|
if not file:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
file_path = Storage.get_file(file.path)
|
file_path = await asyncio.to_thread(Storage.get_file, file.path)
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
||||||
if file_path.is_file():
|
if file_path.is_file():
|
||||||
@@ -172,7 +173,7 @@ async def get_image_base64_from_file_id(id: str) -> Optional[str]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_path = Storage.get_file(file.path)
|
file_path = await asyncio.to_thread(Storage.get_file, file.path)
|
||||||
file_path = Path(file_path)
|
file_path = Path(file_path)
|
||||||
|
|
||||||
# Check if the file already exists in the cache
|
# Check if the file already exists in the cache
|
||||||
|
|||||||
Reference in new issue
Block a user