From d711e64cd9bc0a26afd56dc0cc5606a4dcd7ca5d Mon Sep 17 00:00:00 2001 From: GiovaniFZ Date: Fri, 6 Jun 2025 13:59:36 -0300 Subject: [PATCH] KOW-3 Fix TMA validation --- src/commands/modarchive.ts | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/commands/modarchive.ts b/src/commands/modarchive.ts index 721a517..7d1489e 100644 --- a/src/commands/modarchive.ts +++ b/src/commands/modarchive.ts @@ -61,23 +61,27 @@ export default (bot: Telegraf) => { ...({ reply_to_message_id }) }); } - - const result = await downloadModule(moduleId); - - if (result) { - const { filePath, fileName } = result; - - await ctx.replyWithDocument({ source: filePath }, { - caption: fileName, - ...({ reply_to_message_id }) - }); - - fs.unlinkSync(filePath); - } else { - ctx.reply(Strings.maDownloadError, { - parse_mode: "Markdown", - ...({ reply_to_message_id }) - }); + const numberRegex = /^\d+$/; + const isNumber = numberRegex.test(moduleId); + if (isNumber) { + const result = await downloadModule(moduleId); + if (result) { + const { filePath, fileName } = result; + const regexExtension = /\.\w+$/i; + const hasExtension = regexExtension.test(fileName); + if (hasExtension) { + await ctx.replyWithDocument({ source: filePath }, { + caption: fileName, + ...({ reply_to_message_id }) + }); + fs.unlinkSync(filePath); + return; + } + } } + return ctx.reply(Strings.maInvalidModule, { + parse_mode: "Markdown", + ...({ reply_to_message_id }) + }); }); };