feat: parse docx blocks during upload
This commit is contained in:
@@ -6,6 +6,7 @@ from uuid import uuid4
|
||||
from fastapi import UploadFile
|
||||
from sqlalchemy.orm import Session
|
||||
from ..models.template import Template
|
||||
from ..models.template_block import TemplateBlock
|
||||
from .storage import upload_file
|
||||
|
||||
|
||||
@@ -52,3 +53,26 @@ def create_template_record(db: Session, name: str, file_path: str, type: str = "
|
||||
db.commit()
|
||||
db.refresh(tmpl)
|
||||
return tmpl
|
||||
|
||||
|
||||
def save_template_blocks(db: Session, template_id: int, blocks: list[dict]) -> list[TemplateBlock]:
|
||||
"""批量保存解析出的模板区域。"""
|
||||
records = [
|
||||
TemplateBlock(
|
||||
template_id=template_id,
|
||||
block_id=block["block_id"],
|
||||
parent_block_id=block.get("parent_block_id"),
|
||||
block_type=block["type"],
|
||||
block_name=block.get("text", "")[:200] or None,
|
||||
text_preview=block.get("text", "")[:500] or None,
|
||||
level=block.get("level", 0),
|
||||
sort_order=block.get("sort_order", index),
|
||||
table_rows=block.get("rows"),
|
||||
table_cols=block.get("cols"),
|
||||
)
|
||||
for index, block in enumerate(blocks, start=1)
|
||||
]
|
||||
|
||||
db.add_all(records)
|
||||
db.commit()
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user