|
@@ -249,7 +249,7 @@ async def get_content():
|
|
|
return jsonify({"status_code": 404, "detail": "content not found", "data": {}})
|
|
return jsonify({"status_code": 404, "detail": "content not found", "data": {}})
|
|
|
|
|
|
|
|
row = rows[0]
|
|
row = rows[0]
|
|
|
-
|
|
|
|
|
|
|
+ oss_client = OSSClient()
|
|
|
return jsonify(
|
|
return jsonify(
|
|
|
{
|
|
{
|
|
|
"status_code": 200,
|
|
"status_code": 200,
|
|
@@ -258,6 +258,10 @@ async def get_content():
|
|
|
"title": row.get("title", ""),
|
|
"title": row.get("title", ""),
|
|
|
"text": row.get("text", ""),
|
|
"text": row.get("text", ""),
|
|
|
"doc_id": row.get("doc_id", ""),
|
|
"doc_id": row.get("doc_id", ""),
|
|
|
|
|
+ "textType": row.get("text_type"),
|
|
|
|
|
+ "url": oss_client.generate_url(row.get("text"))
|
|
|
|
|
+ if row.get("text_type") == 3
|
|
|
|
|
+ else "",
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
@@ -291,7 +295,7 @@ async def content_list():
|
|
|
doc_status=doc_status,
|
|
doc_status=doc_status,
|
|
|
order_by=order_by,
|
|
order_by=order_by,
|
|
|
)
|
|
)
|
|
|
-
|
|
|
|
|
|
|
+ oss_client = OSSClient()
|
|
|
# 格式化 entities,只保留必要字段
|
|
# 格式化 entities,只保留必要字段
|
|
|
entities = [
|
|
entities = [
|
|
|
{
|
|
{
|
|
@@ -299,6 +303,10 @@ async def content_list():
|
|
|
"title": row.get("title") or "",
|
|
"title": row.get("title") or "",
|
|
|
"text": row.get("text") or "",
|
|
"text": row.get("text") or "",
|
|
|
"statusDesc": "可用" if row.get("status") == 2 else "不可用",
|
|
"statusDesc": "可用" if row.get("status") == 2 else "不可用",
|
|
|
|
|
+ "textType": row.get("text_type"),
|
|
|
|
|
+ "url": oss_client.generate_url(row.get("text"))
|
|
|
|
|
+ if row.get("text_type") == 3
|
|
|
|
|
+ else "",
|
|
|
}
|
|
}
|
|
|
for row in result["entities"]
|
|
for row in result["entities"]
|
|
|
]
|
|
]
|
|
@@ -520,11 +528,8 @@ async def upload_pdf():
|
|
|
# 检查文件扩展名是否是 .pdf
|
|
# 检查文件扩展名是否是 .pdf
|
|
|
if not file.filename.lower().endswith(".pdf"):
|
|
if not file.filename.lower().endswith(".pdf"):
|
|
|
return jsonify(
|
|
return jsonify(
|
|
|
- {
|
|
|
|
|
- "status": "error",
|
|
|
|
|
- "message": "Invalid file format. Only PDF files are allowed.",
|
|
|
|
|
- }
|
|
|
|
|
- ), 400
|
|
|
|
|
|
|
+ {"status_code": 400, "detail": "Only PDF files are allowed."}
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 获取文件名
|
|
# 获取文件名
|
|
|
filename = file.filename
|
|
filename = file.filename
|
|
@@ -533,14 +538,11 @@ async def upload_pdf():
|
|
|
# 检查文件的 MIME 类型是否是 application/pdf
|
|
# 检查文件的 MIME 类型是否是 application/pdf
|
|
|
if file.content_type != "application/pdf":
|
|
if file.content_type != "application/pdf":
|
|
|
return jsonify(
|
|
return jsonify(
|
|
|
- {
|
|
|
|
|
- "status": "error",
|
|
|
|
|
- "message": "Invalid MIME type. Only PDF files are allowed.",
|
|
|
|
|
- }
|
|
|
|
|
- ), 400
|
|
|
|
|
|
|
+ {"status_code": 400, "detail": "Only PDF files are allowed."}
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 保存到本地(可选,视需要)
|
|
# 保存到本地(可选,视需要)
|
|
|
- file_path = os.path.join("/tmp", book_id) # 临时存储路径
|
|
|
|
|
|
|
+ file_path = os.path.join("/tmp", book_id + ".pdf") # 临时存储路径
|
|
|
await file.save(file_path)
|
|
await file.save(file_path)
|
|
|
resource = get_resource_manager()
|
|
resource = get_resource_manager()
|
|
|
books = Books(resource.mysql_client)
|
|
books = Books(resource.mysql_client)
|
|
@@ -548,7 +550,7 @@ async def upload_pdf():
|
|
|
try:
|
|
try:
|
|
|
oss_client = OSSClient()
|
|
oss_client = OSSClient()
|
|
|
# 上传文件到 OSS
|
|
# 上传文件到 OSS
|
|
|
- oss_path = f"rag/pdfs/{book_id}"
|
|
|
|
|
|
|
+ oss_path = f"rag/pdfs/{book_id}.pdf"
|
|
|
oss_client.upload_file(file_path, oss_path)
|
|
oss_client.upload_file(file_path, oss_path)
|
|
|
await books.insert_book(book_id, filename, oss_path)
|
|
await books.insert_book(book_id, filename, oss_path)
|
|
|
return jsonify({"status_code": 200, "detail": "success"})
|
|
return jsonify({"status_code": 200, "detail": "success"})
|