Skip to content

Commit

Permalink
fix fileName
Browse files Browse the repository at this point in the history
  • Loading branch information
YongZL committed Aug 14, 2024
1 parent 9c02de3 commit fb1256a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/commands-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getWalletInfo, getWallets } from './ton-connect/wallets';
import {
addTGReturnStrategy,
buildUniversalKeyboard,
getFileExtension,
pTimeout,
pTimeoutException,
retryPromise
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ export async function retryPromise<T>(fun: () => Promise<T>, 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 '';
}

0 comments on commit fb1256a

Please sign in to comment.