fix(test1): 发帖文案严格使用用户模板,禁止擅自改成直播间文案
发帖时按当前模板重算;去掉强行追加「直播精彩瞬间」的逻辑。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
f226fb87ce
commit
4d85eb6f8d
@ -493,7 +493,7 @@ def _seed_defaults(conn: sqlite3.Connection) -> None:
|
||||
"x_clips_upload_min_gap_sec": 600,
|
||||
"x_clips_delete_clip_after_post": True,
|
||||
"x_clips_daily_max": 20,
|
||||
"x_clips_caption_template": "{anchor} 直播精彩瞬间",
|
||||
"x_clips_caption_template": "{anchor}",
|
||||
"tiktok_auto_retry_failed": False,
|
||||
"tiktok_auto_retry_max_attempts": 3,
|
||||
"tiktok_auto_retry_interval_sec": 300,
|
||||
|
||||
@ -1004,7 +1004,7 @@ async def x_clips_settings_update(body: dict[str, Any] | None = None) -> dict[st
|
||||
except Exception:
|
||||
raise HTTPException(400, "daily_max 无效") from None
|
||||
if "x_clips_caption_template" in raw:
|
||||
patch["x_clips_caption_template"] = str(raw.get("x_clips_caption_template") or "{anchor}")[:200]
|
||||
patch["x_clips_caption_template"] = str(raw.get("x_clips_caption_template") or "").strip()[:200] or "{anchor}"
|
||||
if "x_clips_trigger" in raw:
|
||||
t = str(raw.get("x_clips_trigger") or "tagged").strip().lower()
|
||||
if t not in {"tagged", "all", "favorite"}:
|
||||
|
||||
@ -57,8 +57,11 @@ def _clip_sec(cfg: dict[str, Any], room: dict[str, Any] | None = None) -> int:
|
||||
|
||||
|
||||
def build_caption(job: dict[str, Any], cfg: dict[str, Any] | None = None) -> str:
|
||||
"""Render caption strictly from settings template — never invent live-room copy."""
|
||||
settings = cfg or db.get_settings_map()
|
||||
tpl = str(settings.get("x_clips_caption_template") or "{anchor} 直播精彩瞬间").strip() or "{anchor} 直播精彩瞬间"
|
||||
tpl = str(settings.get("x_clips_caption_template") or "").strip()
|
||||
if not tpl:
|
||||
tpl = "{anchor}"
|
||||
anchor = str(job.get("anchor_name") or "").strip() or "Live"
|
||||
room = str(job.get("room_id") or "").strip()
|
||||
text = (
|
||||
@ -66,13 +69,8 @@ def build_caption(job: dict[str, Any], cfg: dict[str, Any] | None = None) -> str
|
||||
.replace("{room}", room)
|
||||
.replace("{title}", anchor)
|
||||
).strip()
|
||||
bare = "".join(ch for ch in text if not ch.isspace())
|
||||
# Pad very short captions (短主播名会触发旧插件 length>=12 校验)
|
||||
if len(bare) < 8:
|
||||
suffix = "直播精彩瞬间"
|
||||
if suffix not in text:
|
||||
text = f"{text} {suffix}".strip()
|
||||
return text[:270]
|
||||
# X hard limit ~280; leave headroom for media
|
||||
return (text or anchor)[:270]
|
||||
|
||||
|
||||
def _enqueue_job(
|
||||
@ -251,7 +249,7 @@ class XClipsPipeline:
|
||||
"x_clips_trigger": cfg.get("x_clips_trigger") or "tagged",
|
||||
"x_clips_tag": cfg.get("x_clips_tag") or "x",
|
||||
"x_clips_daily_max": x_clips_db.x_clips_daily_max(cfg),
|
||||
"x_clips_caption_template": cfg.get("x_clips_caption_template") or "{anchor} 直播精彩瞬间",
|
||||
"x_clips_caption_template": cfg.get("x_clips_caption_template") or "{anchor}",
|
||||
"x_clips_live_sample": bool(cfg.get("x_clips_live_sample", True)),
|
||||
"x_clips_live_sample_interval_sec": int(cfg.get("x_clips_live_sample_interval_sec") or 180),
|
||||
"x_clips_live_sample_batch": int(cfg.get("x_clips_live_sample_batch") or 1),
|
||||
@ -488,13 +486,10 @@ class XClipsPipeline:
|
||||
async def _do_post(self, job: dict[str, Any], *, manual: bool = False) -> None:
|
||||
jid = str(job.get("id") or "")
|
||||
cfg = db.get_settings_map()
|
||||
caption = str(job.get("caption") or "").strip() or build_caption(job, cfg)
|
||||
bare = "".join(ch for ch in caption if not ch.isspace())
|
||||
if len(bare) < 8:
|
||||
suffix = "直播精彩瞬间"
|
||||
caption = f"{caption} {suffix}".strip() if suffix not in caption else caption
|
||||
if len("".join(ch for ch in caption if not ch.isspace())) < 8:
|
||||
caption = build_caption(job, cfg)
|
||||
# Always re-render from current template at post time (ignore stale job.caption)
|
||||
caption = build_caption(job, cfg)
|
||||
if not caption:
|
||||
raise ValueError("文案模板结果为空")
|
||||
media_url = str(job.get("media_url") or "").strip()
|
||||
media_key = str(job.get("media_key") or "").strip()
|
||||
clip = str(job.get("clip_path") or "").strip()
|
||||
|
||||
@ -81,7 +81,7 @@ export function ClipsPanel({ toast }: { toast: (msg: string, kind?: "ok" | "err"
|
||||
const s = status?.settings || {};
|
||||
setClipSec(Number(s.x_clips_clip_sec || status?.clip_sec || 12));
|
||||
setDailyMax(Number(s.x_clips_daily_max || status?.daily_max || 20));
|
||||
setCaptionTpl(String(s.x_clips_caption_template || "{anchor} 直播精彩瞬间"));
|
||||
setCaptionTpl(String(s.x_clips_caption_template || "{anchor}"));
|
||||
setTrigger(String(s.x_clips_trigger || "tagged"));
|
||||
setSampleAny(Boolean(s.x_clips_sample_any_live ?? true));
|
||||
setAutoPost(Boolean(s.x_clips_auto_post ?? true));
|
||||
@ -190,8 +190,13 @@ export function ClipsPanel({ toast }: { toast: (msg: string, kind?: "ok" | "err"
|
||||
/>
|
||||
</label>
|
||||
<label className={`${label} sm:col-span-2`}>
|
||||
文案模板(可用 {"{anchor}"} / {"{room}"})
|
||||
<input className={field} value={captionTpl} onChange={(e) => setCaptionTpl(e.target.value)} placeholder="{anchor} 直播精彩瞬间" />
|
||||
文案模板(发帖时严格使用;可用 {"{anchor}"} / {"{room}"},也可写死如 street food)
|
||||
<input
|
||||
className={field}
|
||||
value={captionTpl}
|
||||
onChange={(e) => setCaptionTpl(e.target.value)}
|
||||
placeholder="street food"
|
||||
/>
|
||||
</label>
|
||||
<label className={label}>
|
||||
取样范围
|
||||
|
||||
Loading…
Reference in New Issue
Block a user