feat: GEO/SEO structured data + search ranking tracker
This commit is contained in:
@@ -186,6 +186,13 @@ def create_metric(
|
||||
return metric
|
||||
|
||||
|
||||
def _check_metric_org(metric, current_user, db):
|
||||
"""Check if metric's topic belongs to user's org"""
|
||||
topic = db.query(Topic).filter(Topic.id == metric.topic_id).first()
|
||||
if topic and current_user.role != "admin" and topic.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="数据记录不存在")
|
||||
|
||||
|
||||
@router.put("/entries/{metric_id}", response_model=ContentMetricsResponse)
|
||||
def update_metric(
|
||||
metric_id: int,
|
||||
@@ -196,6 +203,7 @@ def update_metric(
|
||||
metric = db.query(ContentMetrics).filter(ContentMetrics.id == metric_id).first()
|
||||
if not metric:
|
||||
raise HTTPException(status_code=404, detail="数据记录不存在")
|
||||
_check_metric_org(metric, current_user, db)
|
||||
|
||||
for k, v in data.model_dump(exclude_unset=True).items():
|
||||
setattr(metric, k, v)
|
||||
@@ -214,6 +222,7 @@ def delete_metric(
|
||||
metric = db.query(ContentMetrics).filter(ContentMetrics.id == metric_id).first()
|
||||
if not metric:
|
||||
raise HTTPException(status_code=404, detail="数据记录不存在")
|
||||
_check_metric_org(metric, current_user, db)
|
||||
db.delete(metric)
|
||||
db.commit()
|
||||
return {"ok": True}
|
||||
@@ -357,6 +366,8 @@ def fetch_zhihu_metrics(
|
||||
topic = db.query(Topic).filter(Topic.id == data.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="选题不存在")
|
||||
|
||||
post_id = _extract_zhihu_post_id(data.zhihu_url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user