feat(wechat-channel): add draft upload functionality for video channel
- Add isDraft parameter to TencentVideo class to control publishing behavior - Modify click_publish method to click "保存草稿" instead of "发表" when isDraft is true - Update post_video_tencent function to accept and pass is_draft parameter - Add is_draft parameter to /postVideo API endpoint to receive frontend data - Add "视频号上传草稿" checkbox in frontend that appears only for video channel platform - Update defaultTabInit to include isDraft property with default value false - Include isDraft in publishData sent to backend API - Implement proper URL checking for draft vs publish success confirmation The new functionality allows users to save WeChat Channel videos as drafts instead of immediately publishing them when the checkbox is selected.
This commit is contained in:
@@ -82,13 +82,14 @@ async def weixin_setup(account_file, handle=False):
|
||||
|
||||
|
||||
class TencentVideo(object):
|
||||
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, category=None):
|
||||
def __init__(self, title, file_path, tags, publish_date: datetime, account_file, category=None, is_draft=False):
|
||||
self.title = title # 视频标题
|
||||
self.file_path = file_path
|
||||
self.tags = tags
|
||||
self.publish_date = publish_date
|
||||
self.account_file = account_file
|
||||
self.category = category
|
||||
self.is_draft = is_draft # 是否保存为草稿
|
||||
self.local_executable_path = LOCAL_CHROME_PATH or None
|
||||
|
||||
async def set_schedule_time_tencent(self, page, publish_date):
|
||||
@@ -185,21 +186,37 @@ class TencentVideo(object):
|
||||
async def click_publish(self, page):
|
||||
while True:
|
||||
try:
|
||||
publish_buttion = page.locator('div.form-btns button:has-text("发表")')
|
||||
if await publish_buttion.count():
|
||||
await publish_buttion.click()
|
||||
await page.wait_for_url("https://channels.weixin.qq.com/platform/post/list", timeout=5000)
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
if self.is_draft:
|
||||
# 点击"保存草稿"按钮
|
||||
draft_button = page.locator('div.form-btns button:has-text("保存草稿")')
|
||||
if await draft_button.count():
|
||||
await draft_button.click()
|
||||
# 等待跳转到草稿箱页面或确认保存成功
|
||||
await page.wait_for_url("**/post/list**", timeout=5000) # 使用通配符匹配包含post/list的URL
|
||||
tencent_logger.success(" [-]视频草稿保存成功")
|
||||
else:
|
||||
# 点击"发表"按钮
|
||||
publish_button = page.locator('div.form-btns button:has-text("发表")')
|
||||
if await publish_button.count():
|
||||
await publish_button.click()
|
||||
await page.wait_for_url("https://channels.weixin.qq.com/platform/post/list", timeout=5000)
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
except Exception as e:
|
||||
current_url = page.url
|
||||
if "https://channels.weixin.qq.com/platform/post/list" in current_url:
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
if self.is_draft:
|
||||
# 检查是否在草稿相关的页面
|
||||
if "post/list" in current_url or "draft" in current_url:
|
||||
tencent_logger.success(" [-]视频草稿保存成功")
|
||||
break
|
||||
else:
|
||||
tencent_logger.exception(f" [-] Exception: {e}")
|
||||
tencent_logger.info(" [-] 视频正在发布中...")
|
||||
await asyncio.sleep(0.5)
|
||||
# 检查是否在发布列表页面
|
||||
if "https://channels.weixin.qq.com/platform/post/list" in current_url:
|
||||
tencent_logger.success(" [-]视频发布成功")
|
||||
break
|
||||
tencent_logger.exception(f" [-] Exception: {e}")
|
||||
tencent_logger.info(" [-] 视频正在发布中...")
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
async def detect_upload_status(self, page):
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user