Spaces:
Sleeping
Sleeping
[NOTICKET] Fix upload file
Browse files- .vscode/launch.json +15 -0
- services/knowledge/upload_file.py +4 -0
.vscode/launch.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"configurations": [
|
| 3 |
+
{
|
| 4 |
+
"name": "Python Debugger: FastAPI",
|
| 5 |
+
"type": "debugpy",
|
| 6 |
+
"request": "launch",
|
| 7 |
+
"module": "uvicorn",
|
| 8 |
+
"args": [
|
| 9 |
+
"app:app",
|
| 10 |
+
"--reload"
|
| 11 |
+
],
|
| 12 |
+
"jinja": true
|
| 13 |
+
}
|
| 14 |
+
]
|
| 15 |
+
}
|
services/knowledge/upload_file.py
CHANGED
|
@@ -33,6 +33,7 @@ class KnowledgeFileService:
|
|
| 33 |
existing = await get_file_by_filename(self.db,
|
| 34 |
filename=file.filename,
|
| 35 |
user_id=self.user.user_id)
|
|
|
|
| 36 |
if existing:
|
| 37 |
logger.info(
|
| 38 |
"ℹ️ File already exists, skipping upload",
|
|
@@ -45,6 +46,7 @@ class KnowledgeFileService:
|
|
| 45 |
else:
|
| 46 |
# 2️⃣ Upload to Azure Blob
|
| 47 |
upload_result = await upload_file(file, self.user.tenant_id, self.user.user_id)
|
|
|
|
| 48 |
|
| 49 |
if not upload_result.get("uploaded"):
|
| 50 |
logger.error(
|
|
@@ -53,6 +55,7 @@ class KnowledgeFileService:
|
|
| 53 |
)
|
| 54 |
raise RuntimeError(upload_result.get("message", "Upload failed"))
|
| 55 |
|
|
|
|
| 56 |
# 3️⃣ Persist metadata into DB
|
| 57 |
cv_file = CVFile(
|
| 58 |
user_id=self.user.user_id,
|
|
@@ -60,6 +63,7 @@ class KnowledgeFileService:
|
|
| 60 |
filename=file.filename,
|
| 61 |
url=upload_result["url"],
|
| 62 |
is_extracted=False,
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
try:
|
|
|
|
| 33 |
existing = await get_file_by_filename(self.db,
|
| 34 |
filename=file.filename,
|
| 35 |
user_id=self.user.user_id)
|
| 36 |
+
print(f"DEBUG: KnowledgeFileService/get_file_by_filename/existing: {existing}")
|
| 37 |
if existing:
|
| 38 |
logger.info(
|
| 39 |
"ℹ️ File already exists, skipping upload",
|
|
|
|
| 46 |
else:
|
| 47 |
# 2️⃣ Upload to Azure Blob
|
| 48 |
upload_result = await upload_file(file, self.user.tenant_id, self.user.user_id)
|
| 49 |
+
print(f"DEBUG: KnowledgeFileService/upload_result: {upload_result}")
|
| 50 |
|
| 51 |
if not upload_result.get("uploaded"):
|
| 52 |
logger.error(
|
|
|
|
| 55 |
)
|
| 56 |
raise RuntimeError(upload_result.get("message", "Upload failed"))
|
| 57 |
|
| 58 |
+
|
| 59 |
# 3️⃣ Persist metadata into DB
|
| 60 |
cv_file = CVFile(
|
| 61 |
user_id=self.user.user_id,
|
|
|
|
| 63 |
filename=file.filename,
|
| 64 |
url=upload_result["url"],
|
| 65 |
is_extracted=False,
|
| 66 |
+
is_deleted=False,
|
| 67 |
)
|
| 68 |
|
| 69 |
try:
|