diff --git a/README.md b/README.md index 47e3979..6f31d5a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Chạy trên Cloudflare Worker, đơn giản hoạt động như một proxy cho - Hỗ trợ tất cả các phương thức HTTP (GET, POST, PUT, DELETE) - Gửi tệp tin bằng `multipart/form-data` (ví dụ: `sendPhoto`, `sendDocument`) - Xử lý biểu tượng cảm xúc và ký tự đặc biệt ổn định hơn +- Tải tệp tin từ đường dẫn `/file/bot{TOKEN}/` ## Cài đặt @@ -66,6 +67,12 @@ fetch('https://{URL_WORKER_CỦA_BẠN}/bot{TOKEN_BOT_CỦA_BẠN}/sendMessage', .then(data => console.log(data)); ``` +### Lấy file từ Telegram + +``` +https://{URL_WORKER_CỦA_BẠN}/file/bot{TOKEN_BOT_CỦA_BẠN}/ +``` + ## 🔒 Bảo mật - Proxy này không lưu trữ hoặc sửa đổi token bot của bạn diff --git a/telegram-bot-proxy.js b/telegram-bot-proxy.js index ebb3bf0..0ced945 100644 --- a/telegram-bot-proxy.js +++ b/telegram-bot-proxy.js @@ -98,12 +98,19 @@ async function handleRequest(request) { }); } - // Extract the bot token and method from the URL path - // Expected format: /bot{token}/{method} - const pathParts = url.pathname.split('/').filter(Boolean); - if (pathParts.length < 2 || !pathParts[0].startsWith('bot')) { - return new Response('Invalid bot request format', { status: 400 }); - } + // Extract path segments to validate the request format. + // Accept either /bot{token}/{method} or /file/bot{token}/{file_path} + const pathParts = url.pathname.split('/').filter(Boolean); + if (pathParts.length < 2) { + return new Response('Invalid request format', { status: 400 }); + } + if (pathParts[0] === 'file') { + if (pathParts.length < 3 || !pathParts[1].startsWith('bot')) { + return new Response('Invalid file request format', { status: 400 }); + } + } else if (!pathParts[0].startsWith('bot')) { + return new Response('Invalid bot request format', { status: 400 }); + } // Reconstruct the Telegram API URL const telegramUrl = `${TELEGRAM_API_BASE}${url.pathname}${url.search}`;