Merge pull request #376 from jenken827/support_upload_svg_ico

feat: 支持svg和ico文件的上传
This commit is contained in:
叁月柒
2025-12-06 15:37:37 +08:00
committed by GitHub
2 changed files with 8 additions and 5 deletions

View File

@@ -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 = {
@@ -422,9 +422,11 @@ 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') {
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;
@@ -551,4 +554,4 @@ async function tryRetry(err, context, uploadChannel, fullId, metadata, fileExt,
}
return createResponse(JSON.stringify(errMessages), { status: 500 });
}
}

View File

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