70 lines
2.4 KiB
Markdown
70 lines
2.4 KiB
Markdown
---
|
|
name: publisher-module
|
|
description: Multi-platform content publishing module for Sage — articles, videos, audio to 10 social platforms
|
|
category: devops
|
|
---
|
|
|
|
# Publisher Module
|
|
|
|
Multi-platform content publishing for Sage. Covers 10 platforms: weibo, douyin, bilibili, kuaishou, wechat (公众号), channels (视频号), xiaohongshu, toutiao, youtube, twitter.
|
|
|
|
## Architecture
|
|
|
|
- **Repo**: `git@git.opencomputing.cn:yumoqing/publisher.git`
|
|
- **Tables** (4): `publisher_platform`, `publisher_content`, `publisher_task`, `publisher_log`
|
|
- **Content types**: article, video, audio, image
|
|
- **DSPY pattern**: `import json` + `get_sor_context(env, 'sage')` + `env.run_scheduled(sor)`
|
|
|
|
## Adding a Platform
|
|
|
|
Edit `publisher/platforms.py`:
|
|
|
|
```python
|
|
from publisher.platforms import register
|
|
|
|
def publish_newplat(platform, content):
|
|
headers = {'Authorization': 'Bearer ' + platform['access_token']}
|
|
body = {'text': content.get('title', '')}
|
|
return ('POST', 'https://api.newplat.com/publish', headers, body, content['content_type'])
|
|
|
|
register('newplat', '新平台', publish_newplat, ['article', 'image', 'video'])
|
|
```
|
|
|
|
Each platform needs in `publisher_platform`:
|
|
- `app_key` + `app_secret` (all)
|
|
- `access_token` (all)
|
|
- `refresh_token` (YouTube)
|
|
- `extra_config` JSON with platform-specific fields (uid/open_id/channel_id/etc.)
|
|
|
|
## Platform Credentials Quick Reference
|
|
|
|
| platform_code | extra_config fields | Notes |
|
|
|---|---|---|
|
|
| weibo | uid | Weibo user UID required |
|
|
| douyin | open_id | OAuth authorized user |
|
|
| bilibili | cookie | Some endpoints need Cookie |
|
|
| kuaishou | open_id | User identifier |
|
|
| wechat | — | Token expires every 2h |
|
|
| channels | open_id | Separate auth from 公众号 |
|
|
| xiaohongshu | user_id | Creator ID |
|
|
| toutiao | user_id | Author ID |
|
|
| youtube | channel_id | Needs refresh_token |
|
|
| twitter | oauth_token_secret | OAuth 1.0a |
|
|
|
|
## Deployment Checklist
|
|
|
|
1. `cp -r publisher $SAGE_ROOT/`
|
|
2. `cp models/publisher_*.json $SAGE_ROOT/models/`
|
|
3. `cp -r wwwroot/publisher $SAGE_ROOT/wwwroot/`
|
|
4. Execute `ddl/mysql.sql`
|
|
5. Run `scripts/load_path.py`
|
|
6. `from publisher.init import load_publisher` + `load_publisher()` in sage.py
|
|
7. Restart Sage
|
|
|
|
## Pitfalls
|
|
|
|
- Platform APIs require real credentials — access_token expires, need refresh flow
|
|
- Content format differs per platform (Weibo 2000, WeChat title 64, Twitter 280)
|
|
- Network errors auto-retry 3 times before marking failed
|
|
- `sor` parameter allows DSPY context reuse
|