diff --git a/src/commands-handlers.ts b/src/commands-handlers.ts index e08ff12..e5e85c9 100644 --- a/src/commands-handlers.ts +++ b/src/commands-handlers.ts @@ -22,6 +22,7 @@ import { getWalletInfo, getWallets } from './ton-connect/wallets'; import { addTGReturnStrategy, buildUniversalKeyboard, + getFileExtension, pTimeout, pTimeoutException, retryPromise @@ -319,8 +320,12 @@ export async function handleFiles( // await bot.sendMessage(chatId, `Saving in progress...`); // 下载文件并保存 const savePath = await bot.downloadFile(file.file_id, saveDir); + const originName = - (file as TelegramBot.Document).file_name || `${file.file_unique_id}.${savePath}`; + (file as TelegramBot.Document).file_name || + `${file.file_unique_id}${getFileExtension(savePath)}`; + + console.log('savePathsavePath', savePath, originName); await bot.sendMessage( chatId, diff --git a/src/utils.ts b/src/utils.ts index 1d41535..cdb7989 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -96,3 +96,12 @@ export async function retryPromise(fun: () => Promise, retry: number = 3): } throw error; } + +export function getFileExtension(filePath: string) { + const lastDotIndex = filePath.lastIndexOf('.'); + + if (lastDotIndex !== -1 && lastDotIndex < filePath.length - 1) { + return filePath.substring(lastDotIndex); + } + return ''; +}