From fc5ad4b7628f24f083e6ab98461f852b51828fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AA=E4=B8=8D=E8=83=BD=E5=81=9C?= Date: Fri, 20 Mar 2026 14:25:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86media/uploadimg?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E6=96=87=E4=BB=B6=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=92=8C=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加文件大小和格式检查常量 - GIF图片或大于1MB的图片自动回退使用material接口 - 确保向后兼容现有工作流 --- .../scripts/wechat-api.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/skills/baoyu-post-to-wechat/scripts/wechat-api.ts b/skills/baoyu-post-to-wechat/scripts/wechat-api.ts index 7266460..154bf66 100644 --- a/skills/baoyu-post-to-wechat/scripts/wechat-api.ts +++ b/skills/baoyu-post-to-wechat/scripts/wechat-api.ts @@ -73,6 +73,10 @@ async function fetchAccessToken(appId: string, appSecret: string): Promise = { ".jpg": "image/jpeg", ".jpeg": "image/jpeg", @@ -118,7 +127,14 @@ async function uploadImage( ".gif": "image/gif", ".webp": "image/webp", }; - contentType = mimeTypes[ext] || "image/jpeg"; + contentType = mimeTypes[fileExt] || "image/jpeg"; + } + + // media/uploadimg 接口只支持 JPG/PNG 且小于 1MB,如果是其他格式或文件过大,需要使用 material 接口 + const isGifOrLarge = fileExt === ".gif" || fileSize > BODY_IMG_MAX_SIZE; + if (uploadType === "body" && isGifOrLarge) { + console.error(`[wechat-api] Image ${filename} is GIF or larger than 1MB, using material API instead`); + uploadType = "material"; } const boundary = `----WebKitFormBoundary${Date.now().toString(16)}`;