여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""승인 카드가 권위 있는 경로이고 알림톡은 그 화면으로 보내는 편의 채널이다."""
|
|
|
|
import json
|
|
from config import social_config as config
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
from zoneinfo import ZoneInfo
|
|
|
|
import httpx
|
|
from sqlalchemy import update
|
|
from common.database.model.models import place_social_posts as Post, users, places
|
|
from crud import social_crud as db
|
|
from services.external import alimtalk
|
|
|
|
TEMPLATE = json.loads(
|
|
(Path(__file__).parent / "resources/social_approval.json").read_text()
|
|
)
|
|
|
|
|
|
async def request_approval(post_id, user_id, token, path):
|
|
from services.social_service import sha
|
|
|
|
async def load(s):
|
|
post = await s.get(Post, post_id)
|
|
user = await s.get(users, user_id)
|
|
place = await s.get(places, post.place_id)
|
|
return getattr(user, "contact_number", None), place.name
|
|
|
|
number, name = await db.transaction(load)
|
|
if not alimtalk.is_configured() or not number:
|
|
return
|
|
# 야간 발송 정책이 미결이라 밤에는 화면 채널만 쓴다.
|
|
if not 8 <= datetime.now(ZoneInfo("Asia/Seoul")).hour < 21:
|
|
return
|
|
origin = config.get("SOCIAL_APP_ORIGIN", "").rstrip("/")
|
|
if not origin.startswith("https://"):
|
|
error = "ALIMTALK_APP_ORIGIN_REQUIRED"
|
|
else:
|
|
try:
|
|
async with httpx.AsyncClient(timeout=20) as client:
|
|
await alimtalk.send(
|
|
number,
|
|
config.get("ALIMTALK_TEMPLATE_CODE", TEMPLATE["template_code"]),
|
|
dict(zip(TEMPLATE["variables"], [name, origin + path])),
|
|
client=client,
|
|
)
|
|
error = None
|
|
except Exception:
|
|
error = "ALIMTALK_SEND_FAILED"
|
|
|
|
async def save(s):
|
|
await s.execute(
|
|
update(Post)
|
|
.where(
|
|
Post.post_id == post_id,
|
|
Post.approval_token_sha == sha(token),
|
|
Post.status == "PENDING_APPROVAL",
|
|
)
|
|
.values(
|
|
last_error=error,
|
|
approval_channel="screen" if error else "alimtalk",
|
|
approval_sent_at=None if error else datetime.now(timezone.utc),
|
|
)
|
|
)
|
|
|
|
await db.transaction(save)
|
|
if error:
|
|
# 발송 요청 자체가 실패했음을 호출자에게 알린다.
|
|
raise RuntimeError(error)
|