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)}`;