From bf6906e54eb926a8f5cd58e79f8ef34d75dddf3f Mon Sep 17 00:00:00 2001 From: jenken827 Date: Sat, 6 Dec 2025 15:15:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81svg=E5=92=8Cico?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/upload/index.js | 5 ++++- functions/utils/telegramAPI.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/functions/upload/index.js b/functions/upload/index.js index d23434b8..c087c849 100644 --- a/functions/upload/index.js +++ b/functions/upload/index.js @@ -406,7 +406,7 @@ async function uploadFileToTelegram(context, fullId, metadata, fileExt, fileName const newFileName = fileName.replace(/\.webp$/, '.jpeg'); const newFile = new File([formdata.get('file')], newFileName, { type: fileType }); formdata.set('file', newFile); - } + } // 选择对应的发送接口 const fileTypeMap = { @@ -425,6 +425,8 @@ async function uploadFileToTelegram(context, fullId, metadata, fileExt, fileName // GIF 发送接口特殊处理 if (fileType === 'image/gif' || fileType === 'image/webp' || fileExt === 'gif' || fileExt === 'webp') { sendFunction = { 'url': 'sendAnimation', 'type': 'animation' }; + }else if (fileType === 'image/svg+xml' || fileType === 'image/x-icon') { + sendFunction = { 'url': 'sendDocument', 'type': 'document' }; } // 根据服务端压缩设置处理接口:从参数中获取serverCompress,如果为false,则使用sendDocument接口 @@ -477,6 +479,7 @@ async function uploadFileToTelegram(context, fullId, metadata, fileExt, fileName waitUntil(endUpload(context, fullId, metadata)); } catch (error) { + console.log('Telegram upload error:', error.message); res = createResponse('upload error, check your environment params about telegram channel!', { status: 400 }); } finally { return res; diff --git a/functions/utils/telegramAPI.js b/functions/utils/telegramAPI.js index 24b33fc0..e0523f84 100644 --- a/functions/utils/telegramAPI.js +++ b/functions/utils/telegramAPI.js @@ -36,8 +36,8 @@ export class TelegramAPI { headers: this.defaultHeaders, body: formData }); - - if (!response.ok) { + console.log('Telegram API response:', response.status, response.statusText); + if (!response.ok) { throw new Error(`Telegram API error: ${response.statusText}`); } From 0bc3bc241fcd20b87a1b5af39cee08b726b4aa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=81=E6=9C=88=E6=9F=92?= <108160987+MarSeventh@users.noreply.github.com> Date: Sat, 6 Dec 2025 15:36:40 +0800 Subject: [PATCH 2/2] Refine GIF handling and update comments Update comments for clarity and adjust GIF handling logic. --- functions/upload/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/upload/index.js b/functions/upload/index.js index c087c849..aad2eaed 100644 --- a/functions/upload/index.js +++ b/functions/upload/index.js @@ -422,10 +422,10 @@ async function uploadFileToTelegram(context, fullId, metadata, fileExt, fileName ? fileTypeMap[Object.keys(fileTypeMap).find(key => fileType.startsWith(key))] : defaultType; - // GIF 发送接口特殊处理 + // GIF ICO 等发送接口特殊处理 if (fileType === 'image/gif' || fileType === 'image/webp' || fileExt === 'gif' || fileExt === 'webp') { sendFunction = { 'url': 'sendAnimation', 'type': 'animation' }; - }else if (fileType === 'image/svg+xml' || fileType === 'image/x-icon') { + } else if (fileType === 'image/svg+xml' || fileType === 'image/x-icon') { sendFunction = { 'url': 'sendDocument', 'type': 'document' }; } @@ -554,4 +554,4 @@ async function tryRetry(err, context, uploadChannel, fullId, metadata, fileExt, } return createResponse(JSON.stringify(errMessages), { status: 500 }); -} \ No newline at end of file +}