mirror of
https://github.com/tiennm99/cf-worker-telegram.git
synced 2026-09-03 08:18:24 +00:00
Merge pull request #10 from tuanpb99/codex/fix-api-file-retrieval-issue
Fix file download paths: Allow both standard API and file download paths in request validation
This commit is contained in:
@@ -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}/<file_path>`
|
||||
|
||||
## 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}/<file_path>
|
||||
```
|
||||
|
||||
## 🔒 Bảo mật
|
||||
|
||||
- Proxy này không lưu trữ hoặc sửa đổi token bot của bạn
|
||||
|
||||
+13
-6
@@ -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}`;
|
||||
|
||||
Reference in New Issue
Block a user