diff --git a/backend/app/tiktok_upload.py b/backend/app/tiktok_upload.py index d073126..561c950 100644 --- a/backend/app/tiktok_upload.py +++ b/backend/app/tiktok_upload.py @@ -22,6 +22,19 @@ def _privacy_to_visibility(privacy_level: str) -> int: return 0 +def _friendly_upload_error(log: str) -> str: + text = str(log or "") + low = text.lower() + if "2158" in text or "posting videos too fast" in low or "take a rest" in low: + return "TikTok 限流:发得太快(status 2158)。请至少等几小时后再手动传 1 条,不要连点" + if "login expired" in low or '"status_code": 8' in text: + return "TikTok Cookie 已过期,请重新粘贴 sessionid" + if "invalid parameters" in low: + return "TikTok 拒绝发布参数,请稍后重试 1 次" + tail = " ".join(line.strip() for line in text.strip().splitlines()[-4:] if line.strip())[:240] + return tail or "TikTok 上传失败" + + def _upload_sync( *, channel_pk: str, @@ -93,10 +106,7 @@ def _upload_sync( "privacy_level": privacy_level, "dc_id": working_dc, } - tail = " ".join(line.strip() for line in log.strip().splitlines()[-4:] if line.strip())[:240] - raise ValueError( - tail or "TikTok 上传失败,请检查 Cookie 是否过期或 Node.js 是否可用" - ) + raise ValueError(_friendly_upload_error(log)) async def upload_tiktok_mp4(