feat: GEO/SEO structured data + search ranking tracker

This commit is contained in:
Yuzhiran Dev
2026-06-09 17:18:09 +08:00
parent 23ff63baa9
commit 8595bbc521
26 changed files with 961 additions and 51 deletions
+23
View File
@@ -14,6 +14,16 @@ _creator_semaphore = threading.Semaphore(3)
router = APIRouter(prefix="/api/tasks", tags=["tasks"])
def _check_task_org(task, current_user, db):
"""Check if task's topic belongs to user's org"""
if current_user.role == "admin" or not task.topic_id:
return True
topic = db.query(Topic).filter(Topic.id == task.topic_id).first()
if topic and topic.org_id != current_user.org_id:
raise HTTPException(status_code=404, detail="任务不存在")
return True
@router.get("", response_model=List[ContentTaskResponse])
def list_tasks(
status: Optional[str] = None,
@@ -94,6 +104,7 @@ def get_task(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
return task
@@ -106,6 +117,7 @@ def start_task(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
from datetime import datetime, timezone
task.status = "running"
@@ -128,6 +140,7 @@ def update_progress(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
task.progress = progress
if message:
@@ -148,6 +161,7 @@ def complete_task(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
from datetime import datetime, timezone
finished = datetime.now(timezone.utc)
@@ -175,6 +189,7 @@ def fail_task(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
from datetime import datetime, timezone
finished = datetime.now(timezone.utc)
@@ -197,6 +212,7 @@ def cancel_task(
task = db.query(ContentTask).filter(ContentTask.task_id == task_id).first()
if not task:
raise HTTPException(status_code=404, detail="任务不存在")
_check_task_org(task, current_user, db)
task.status = "cancelled"
db.commit()
@@ -406,6 +422,13 @@ def run_creator_task(
):
from datetime import datetime, timezone
if topic_id:
topic = db.query(Topic).filter(Topic.id == topic_id).first()
if not topic:
raise HTTPException(status_code=404, detail="选题不存在")
if current_user.role != "admin" and topic.org_id != current_user.org_id:
raise HTTPException(status_code=404, detail="选题不存在")
now = datetime.now(timezone.utc)
task_id = f"task_{uuid.uuid4().hex[:16]}"