Skip to content

fix(core): 修复微信公众号、掘金草稿封面未绑定的问题#204

Open
xiaoshuai1024 wants to merge 2 commits into
wechatsync:v2from
xiaoshuai1024:fix/weixin-cover
Open

fix(core): 修复微信公众号、掘金草稿封面未绑定的问题#204
xiaoshuai1024 wants to merge 2 commits into
wechatsync:v2from
xiaoshuai1024:fix/weixin-cover

Conversation

@xiaoshuai1024

@xiaoshuai1024 xiaoshuai1024 commented Jul 1, 2026

Copy link
Copy Markdown

问题

通过 CLI / MCP 同步文章时,传入的 `cover`(封面图)没有生效,草稿箱里的文章始终没有封面。

定位发现多个适配器完全忽略了 `article.cover`,封面相关字段硬编码为空:

适配器 问题字段 原因
`weixin.ts` `fileid0` / `cdn_url0` / `cdn_url_back0` 始终为空 完全忽略 `article.cover`;`uploadImageByUrl` 丢弃了响应里的 `content`(fileid)
`juejin.ts` `cover_image` 硬编码为空 声明了 `cover` 能力,但 `publish` 没读取 `article.cover`

修复

采用统一思路:`publish` 中若 `article.cover` 存在,先上传到平台图床拿 URL/fileid,填入对应字段;上传失败不阻断正文发布,记录 `logger.warn` 后继续。

`packages/core/src/adapters/platforms/weixin.ts`(+21 / -3):

  1. `uploadImageByUrl` 返回值通过 `attrs.fileid` 带出 `res.content`(原先丢弃)
  2. `publish` 上传封面 → 填 `fileid0` / `cdn_url0` / `cdn_url_back0`

`packages/core/src/adapters/platforms/juejin.ts`(+14 / -1):

  1. `publish` 上传封面(复用现有 ImageX `uploadImageByUrl`)→ 填 `cover_image`

`ImageUploadResult.attrs` 字段本就存在,无需改动类型定义。`sync-service.ts` 也早已把 `article.cover` 透传到 `publish`,链路完整。

验证

  • `pnpm --filter @wechatsync/core typecheck` 通过(strict 模式零错误)
  • 本地构建扩展 `pnpm --filter @wechatsync/extension build` 通过
  • 微信实测:CLI `wechatsync sync article.html -p weixin --cover cover.png` 同步后,草稿箱文章封面正常显示(修复前无封面)
  • 掘金实测:通过本地修复版扩展同步,草稿生成成功(cover_image 填入图床 URL);代码路径与微信一致,typecheck 通过

背景

  • 微信草稿接口(`operate_appmsg?sub=create`)封面通过 `fileid0` + `cdn_url0` + `cdn_url_back0` 绑定,fileid 来自 `filetransfer?action=upload_material` 响应的 `content` 字段
  • 掘金草稿接口(`article_draft/create`)封面字段为 `cover_image`,填图床 URL

说明

本 PR 只覆盖微信与掘金两个适配器。知乎适配器也存在「声明了 `cover` 能力但 `publish` 未处理」的情况,但其草稿接口的封面字段未公开、需抓包确认,留作后续单独 PR。

微信适配器此前完全忽略 article.cover,草稿的 fileid0/cdn_url0/
cdn_url_back0 始终为空,导致同步到草稿箱的文章没有封面。

修复:
- uploadImageByUrl 返回值保留 res.content(fileid),原先是丢弃的
- publish 在构造表单前上传封面图(如有),拿 fileid + cdn_url
- 将 fileid0/cdn_url0/cdn_url_back0 填入上传结果
- 封面上传失败不阻断正文发布,记录警告后继续

实测:通过 CLI 同步带封面的文章到草稿箱,封面正常显示。
掘金适配器声明了 cover 能力但 publish 中 cover_image 始终硬编码为空,
导致同步的草稿没有封面。

修复:publish 中若 article.cover 存在,先调用 uploadImageByUrl 上传到
掘金图床(ImageX),拿到的 URL 填入 cover_image 字段。上传失败不阻断
正文发布,记录警告后继续。

与微信封面修复(wechatsync#204)采用相同思路。
@xiaoshuai1024 xiaoshuai1024 changed the title fix(core): 修复微信公众号草稿封面未绑定的问题 fix(core): 修复微信公众号、掘金草稿封面未绑定的问题 Jul 1, 2026
@xiaoshuai1024

Copy link
Copy Markdown
Author

Hi maintainers, gentle ping on this PR -- it's been open for ~2 weeks with no review activity.

Summary

Fixes the draft cover image not being bound when syncing to:

  • WeChat Official Account (微信公众号) -- packages/core/src/adapters/platforms/weixin.ts
  • Juejin (掘金) -- packages/core/src/adapters/platforms/juejin.ts

Scope

  • +35 / -4 across 2 files
  • No new dependencies, no breaking changes
  • Pure bug fix: the cover field was silently dropped in the adapter payload, so the platform fell back to the default (or empty) cover.

Why I'm bumping this

Both are real regressions visible to users (see recent issues around 小红书 long-form sync stuck and local image upload hanging -- the adapter layer is where these surface). Happy to help triage further if useful.

Status

  • mergeable: MERGEABLE on v2 as of today
  • No review / no CI yet

Would appreciate a quick look. If there's a different target branch or a changelog/test convention I missed, happy to adjust.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant