[feat] solution/backend,docs: 미니블로그 승인 → 쓰레드 자동 게재, 쓰레드 초안 생성 OpenAI 전환
사장님 지시: "쓰레드에 연동되어 있으면 같이 업로드 되는 기능". 미니블로그의 두 승인 경로(이메일 GET 토큰, 로그인 "바로 발행")를 공통 메서드로 묶고, 그 끝에서 쓰레드 연동을 시도한다. 미니블로그 승인 자체가 발화 동의로 취급되므로 쓰레드 쪽 별도 승인은 묻지 않는다(DECISIONS 7-1-2 개정, 문구를 그대로 재사용하는 경우에 한정). 겸사겸사 쓰레드 초안 생성(generate_social_post)이 LLM_PROVIDER 를 안 타고 Gemini 를 직접 호출하던 것도 다른 생성 함수와 같은 추상화로 맞췄다. - blog_jobs._published_places: sites.domain IS NOT NULL 조건 추가(쓰레드 기준과 통일) - social_service.publish_reused_text: 연동 없음/게시 비활성/domain 미확정이면 스킵, 정상이면 APPROVED 삽입 + run_post(job_type=9) enqueue — 새 게시 로직은 안 만든다 - post_service: decide/approve_by_owner → _approve_and_publish 로 공통화, _try_social_share 는 실패를 전부 삼켜 미니블로그 승인을 막지 않는다 - gemini_text.generate_social_post: services.llm.provider.active() 로 전환, Gemini 전용 import 제거 - DECISIONS.md 7-1-2, MINI_BLOG.md 5·8절, SOCIAL.md 갱신 test_blog_owner.py·test_social.py 다수 추가/수정, 관련 스위트 전체 PASS
This commit is contained in:
1 parent
07c53d30bf
commit
47da2f29b3
9 files changed
+861
-101
No files matched your search
@@ -13,6 +13,7 @@ from datetime import date, datetime, timedelta, timezone
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from config import social_config
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import place_posts, places, sites, users
|
||||
from common.enums import DBWRType, PostStatus, SiteStatus
|
||||
@@ -49,6 +50,7 @@ async def _published_places() -> list:
|
||||
places.deleted == False, # noqa: E712
|
||||
sites.deleted == False, # noqa: E712
|
||||
sites.status == SiteStatus.PUBLISHED.value,
|
||||
sites.domain.isnot(None),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -92,7 +94,7 @@ async def _generate_for_place(place) -> int:
|
||||
continue
|
||||
generated = await blog_service.generate_one(
|
||||
place_name=place.name, region=region, topic_kind=kind,
|
||||
material=material, used_topics=sorted(used_set),
|
||||
material=material, used_topics=sorted(used_set), place_category=place.category,
|
||||
)
|
||||
if not generated:
|
||||
continue
|
||||
@@ -171,7 +173,7 @@ async def generate_range(place_id: str, start_date: date, end_date: date) -> dic
|
||||
continue
|
||||
generated = await blog_service.generate_one(
|
||||
place_name=place.name, region=region, topic_kind=kind,
|
||||
material=material, used_topics=sorted(used_set),
|
||||
material=material, used_topics=sorted(used_set), place_category=place.category,
|
||||
)
|
||||
if not generated:
|
||||
continue
|
||||
@@ -219,7 +221,7 @@ async def generate_one_for_date(place_id: str, target_date: date) -> dict | None
|
||||
continue
|
||||
generated = await blog_service.generate_one(
|
||||
place_name=place.name, region=region, topic_kind=kind,
|
||||
material=material, used_topics=sorted(used_set),
|
||||
material=material, used_topics=sorted(used_set), place_category=place.category,
|
||||
)
|
||||
if not generated:
|
||||
continue
|
||||
@@ -261,6 +263,41 @@ def _mail_body(*, place_name: str, post, user, origin: str, approve_token: str)
|
||||
)
|
||||
|
||||
|
||||
def _notify_address(place, user) -> str:
|
||||
# notify_email 이 있으면 그 업장 전용 수신자다 — 없으면 계정 이메일(users.email)로 대체한다
|
||||
# (사장님 한 명이 사이트를 여러 개 가질 수 있어 계정 이메일 하나로는 업장별 수신자를 못 나눈다).
|
||||
return place.notify_email or user.email
|
||||
|
||||
|
||||
def _app_origin() -> str:
|
||||
"""메일의 승인·수정 링크가 향할 곳 — 빌더 앱(과 그 앞의 API)이 사는 오리진.
|
||||
|
||||
★ site_payload.publish_origin() 을 쓰면 안 된다 — 그건 발행된 고객 사이트(/s/<slug>)
|
||||
전용이다. 로컬에선 그게 solution-site 정적 서버(포트 80)라, 메일의 "수정하려면"
|
||||
링크(/blog?...)가 거기로 가서 404 났다(2026-09-21 실측). SNS 알림(notify_service.py)이
|
||||
이미 같은 목적으로 쓰는 SOCIAL_APP_ORIGIN 을 그대로 재사용한다 — 설정을 두 벌 안 둔다.
|
||||
비어 있으면(로컬에서 안 채웠으면) publish_origin() 으로 폴백해 링크가 아예 상대경로로
|
||||
깨지는 것보다는 낫게 한다."""
|
||||
return social_config.get("SOCIAL_APP_ORIGIN") or site_payload.publish_origin()
|
||||
|
||||
|
||||
async def _send_one(place, user, post) -> bool:
|
||||
"""토큰 발급 → 메일 본문 조립 → 발송 → 성공하면 SENT 로 표시. 실패하면 DB 를 안 건드린다."""
|
||||
token, token_hash, expires = blog_service.issue_token()
|
||||
body = _mail_body(
|
||||
place_name=place.name, post=post, user=user,
|
||||
origin=_app_origin(), approve_token=token,
|
||||
)
|
||||
ok = mail_service.send(to=_notify_address(place, user), subject=f"[{place.name}] 이번 글 올릴까요?", text=body)
|
||||
if not ok:
|
||||
return False
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()],
|
||||
[lambda s, pid=post.post_id, h=token_hash, e=expires: _crud.mark_sent(s, pid, h, e)],
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def send_reviewed() -> int:
|
||||
"""검수를 통과한 글을 사장님에게 한 통씩 보낸다. 보낸 수를 돌려준다."""
|
||||
if not mail_service.is_configured():
|
||||
@@ -273,22 +310,45 @@ async def send_reviewed() -> int:
|
||||
if not rows:
|
||||
return 0
|
||||
|
||||
targets = {str(place.place_id): (place.name, user) for place, user in await _published_places()}
|
||||
origin = site_payload.publish_origin()
|
||||
places_by_id = {str(place.place_id): (place, user) for place, user in await _published_places()}
|
||||
sent = 0
|
||||
for post in rows:
|
||||
target = targets.get(str(post.place_id))
|
||||
if not target or not mail_service.is_valid_address(target[1].email or ""):
|
||||
target = places_by_id.get(str(post.place_id))
|
||||
if not target:
|
||||
continue
|
||||
place_name, user = target
|
||||
token, token_hash, expires = blog_service.issue_token()
|
||||
body = _mail_body(place_name=place_name, post=post, user=user, origin=origin, approve_token=token)
|
||||
ok = mail_service.send(to=user.email, subject=f"[{place_name}] 이번 글 올릴까요?", text=body)
|
||||
if not ok:
|
||||
place, user = target
|
||||
if not mail_service.is_valid_address(_notify_address(place, user) or ""):
|
||||
continue
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_posts.DBType()],
|
||||
[lambda s, pid=post.post_id, h=token_hash, e=expires: _crud.mark_sent(s, pid, h, e)],
|
||||
)
|
||||
sent += 1
|
||||
if await _send_one(place, user, post):
|
||||
sent += 1
|
||||
return sent
|
||||
|
||||
|
||||
async def send_now_for_place(place_id: str) -> dict:
|
||||
"""사장님이 빌더 화면에서 누르는 즉시 발송 — 아침 9시 스윕을 기다리지 않고 이 업장의
|
||||
오늘 몫을 지금 보낸다(2026-09-21, 사장님 요청: "지금 바로 발송할 수 있도록").
|
||||
'하루 한 통' 원칙은 그대로다 — 이미 오늘 보냈으면(REVIEWED 가 아니면) 보낼 게 없다."""
|
||||
if not mail_service.is_configured():
|
||||
return {"sent": False, "reason": "MAIL_NOT_CONFIGURED"}
|
||||
|
||||
place = user = None
|
||||
for p, u in await _published_places():
|
||||
if str(p.place_id) == str(place_id):
|
||||
place, user = p, u
|
||||
break
|
||||
if place is None:
|
||||
return {"sent": False, "reason": "NOTHING_DUE"}
|
||||
|
||||
post = await DB_SESSION_MNG.execute_lambda(
|
||||
place_posts.DBType(), DBWRType.DB_READ.value,
|
||||
lambda s: _crud.next_due_for_mail(s, place_id, PostStatus.REVIEWED.value, _today_kst()),
|
||||
)
|
||||
if post is None:
|
||||
return {"sent": False, "reason": "NOTHING_DUE"}
|
||||
|
||||
if not mail_service.is_valid_address(_notify_address(place, user) or ""):
|
||||
return {"sent": False, "reason": "NO_VALID_EMAIL"}
|
||||
|
||||
if not await _send_one(place, user, post):
|
||||
return {"sent": False, "reason": "SEND_FAILED"}
|
||||
return {"sent": True, "reason": None}
|
||||
Reference in new issue
Block a user