KOW-3 Fix TMA validation (#58)

This commit is contained in:
Giovani Finazzi 2025-06-06 14:42:37 -03:00 committed by GitHub
parent 72ebc0a4ff
commit b8e13bbbff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,23 +61,27 @@ export default (bot: Telegraf<Context>) => {
...({ reply_to_message_id }) ...({ reply_to_message_id })
}); });
} }
const numberRegex = /^\d+$/;
const isNumber = numberRegex.test(moduleId);
if (isNumber) {
const result = await downloadModule(moduleId); const result = await downloadModule(moduleId);
if (result) { if (result) {
const { filePath, fileName } = result; const { filePath, fileName } = result;
const regexExtension = /\.\w+$/i;
const hasExtension = regexExtension.test(fileName);
if (hasExtension) {
await ctx.replyWithDocument({ source: filePath }, { await ctx.replyWithDocument({ source: filePath }, {
caption: fileName, caption: fileName,
...({ reply_to_message_id }) ...({ reply_to_message_id })
}); });
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
} else { return;
ctx.reply(Strings.maDownloadError, { }
}
}
return ctx.reply(Strings.maInvalidModule, {
parse_mode: "Markdown", parse_mode: "Markdown",
...({ reply_to_message_id }) ...({ reply_to_message_id })
}); });
}
}); });
}; };