Spaces:
Sleeping
Sleeping
Commit
·
d6fcb7e
1
Parent(s):
b0077fd
Fix bug failed on await db.documents.insert_one(doc)
Browse files- app/db.py +2 -0
- app/routers/import_doc.py +1 -1
app/db.py
CHANGED
|
@@ -46,10 +46,12 @@ async def save_to_textbook_fs(doc_id: str, file_path: str):
|
|
| 46 |
except Exception as e:
|
| 47 |
logger.warning(f"⚠️ textbook GridFS save failed: {e}")
|
| 48 |
|
|
|
|
| 49 |
async def fetch_textbook_pdf(doc_id: str):
|
| 50 |
bucket = _get_textbook_fs()
|
| 51 |
return await bucket.open_download_stream_by_name(f"{doc_id}.pdf")
|
| 52 |
|
|
|
|
| 53 |
async def delete_textbook_pdf(doc_id: str):
|
| 54 |
bucket = _get_textbook_fs()
|
| 55 |
try:
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
logger.warning(f"⚠️ textbook GridFS save failed: {e}")
|
| 48 |
|
| 49 |
+
# Fetch to view PDF on frontend
|
| 50 |
async def fetch_textbook_pdf(doc_id: str):
|
| 51 |
bucket = _get_textbook_fs()
|
| 52 |
return await bucket.open_download_stream_by_name(f"{doc_id}.pdf")
|
| 53 |
|
| 54 |
+
# Delete textbook when handshake failed
|
| 55 |
async def delete_textbook_pdf(doc_id: str):
|
| 56 |
bucket = _get_textbook_fs()
|
| 57 |
try:
|
app/routers/import_doc.py
CHANGED
|
@@ -80,7 +80,7 @@ async def import_book(req: ImportRequest):
|
|
| 80 |
"metadata": result
|
| 81 |
}
|
| 82 |
db = get_db()
|
| 83 |
-
await db.documents.
|
| 84 |
asyncio.create_task(parse_and_index(req.candidate_id))
|
| 85 |
logger.info(f"📚 Document {req.candidate_id} queued for indexing")
|
| 86 |
# Head back to frontend
|
|
|
|
| 80 |
"metadata": result
|
| 81 |
}
|
| 82 |
db = get_db()
|
| 83 |
+
await db.documents.replace_one({"_id": req.candidate_id}, doc, upsert=True)
|
| 84 |
asyncio.create_task(parse_and_index(req.candidate_id))
|
| 85 |
logger.info(f"📚 Document {req.candidate_id} queued for indexing")
|
| 86 |
# Head back to frontend
|