mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 19:37:47 +01:00
refac: DOCS_DIR deprecated
This commit is contained in:
@@ -11,7 +11,7 @@ import mimetypes
|
||||
from open_webui.apps.webui.models.files import FileForm, FileModel, Files
|
||||
from open_webui.apps.retrieval.main import process_file, ProcessFileForm
|
||||
|
||||
from open_webui.config import UPLOAD_DIR, DOCS_DIR
|
||||
from open_webui.config import UPLOAD_DIR
|
||||
from open_webui.env import SRC_LOG_LEVELS
|
||||
from open_webui.constants import ERROR_MESSAGES
|
||||
|
||||
@@ -90,53 +90,6 @@ def upload_file(file: UploadFile = File(...), user=Depends(get_verified_user)):
|
||||
)
|
||||
|
||||
|
||||
@router.post("/upload/dir")
|
||||
def upload_dir(user=Depends(get_admin_user)):
|
||||
file_ids = []
|
||||
for path in Path(DOCS_DIR).rglob("./**/*"):
|
||||
if path.is_file() and not path.name.startswith("."):
|
||||
try:
|
||||
log.debug(f"Processing file from path: {path}")
|
||||
|
||||
filename = path.name
|
||||
file_content_type = mimetypes.guess_type(path)
|
||||
|
||||
# replace filename with uuid
|
||||
id = str(uuid.uuid4())
|
||||
name = filename
|
||||
|
||||
contents = path.read_bytes()
|
||||
file_path = str(path)
|
||||
|
||||
file = Files.insert_new_file(
|
||||
user.id,
|
||||
FileForm(
|
||||
**{
|
||||
"id": id,
|
||||
"filename": filename,
|
||||
"meta": {
|
||||
"name": name,
|
||||
"content_type": file_content_type,
|
||||
"size": len(contents),
|
||||
"path": file_path,
|
||||
},
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
try:
|
||||
process_file(ProcessFileForm(file_id=id))
|
||||
log.debug(f"File processed: {path}, {file.id}")
|
||||
file_ids.append(file.id)
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
log.error(f"Error processing file: {file.id}")
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
pass
|
||||
return file_ids
|
||||
|
||||
|
||||
############################
|
||||
# List Files
|
||||
############################
|
||||
|
||||
Reference in New Issue
Block a user