lamhieu commited on
Commit
aa9c9a7
Β·
1 Parent(s): e0a203d

chore: update something

Browse files
Files changed (1) hide show
  1. docsifer/router.py +4 -1
docsifer/router.py CHANGED
@@ -5,6 +5,7 @@ import json
5
  import tempfile
6
  import os
7
  import aiohttp
 
8
  from pathlib import Path
9
 
10
  from fastapi import APIRouter, HTTPException, UploadFile, File, Form, BackgroundTasks
@@ -66,8 +67,10 @@ async def convert_document(
66
  # If a file is provided, use the existing flow
67
  if file is not None:
68
  with tempfile.TemporaryDirectory() as tmpdir:
69
- temp_path = Path(tmpdir) / file.filename
70
  contents = await file.read()
 
 
 
71
  temp_path.write_bytes(contents)
72
  result, token_count = await docsifer_service.convert_file(
73
  file_path=str(temp_path),
 
5
  import tempfile
6
  import os
7
  import aiohttp
8
+ import mimetypes
9
  from pathlib import Path
10
 
11
  from fastapi import APIRouter, HTTPException, UploadFile, File, Form, BackgroundTasks
 
67
  # If a file is provided, use the existing flow
68
  if file is not None:
69
  with tempfile.TemporaryDirectory() as tmpdir:
 
70
  contents = await file.read()
71
+ guessed_ext = mimetypes.guess_extension(file.content_type) or ""
72
+ new_name = f"{Path(file.filename).stem}{guessed_ext}"
73
+ temp_path = Path(tmpdir) / new_name
74
  temp_path.write_bytes(contents)
75
  result, token_count = await docsifer_service.convert_file(
76
  file_path=str(temp_path),