|
1 | 1 | <p align="center"> |
2 | | - <img src="docs/logo.svg" alt="UploadBot logo" width="144" height="144"> |
| 2 | + <img src="docs/logo.svg" alt="UploadBot logo" width="128" height="128"> |
3 | 3 | </p> |
4 | 4 |
|
5 | 5 | <h1 align="center">UploadBot</h1> |
|
11 | 11 | <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-78dba9" alt="MIT license"></a> |
12 | 12 | </p> |
13 | 13 |
|
14 | | -**Turn Telegram files into shareable links as they stream.** Send a document, |
15 | | -photo, video, or audio file to the bot and receive a public download URL from |
| 14 | +Send a file to your Telegram bot and get a public download link from |
16 | 15 | [File2Share](https://file2share.us). Send a public file URL to receive it on Telegram. |
17 | 16 |
|
| 17 | +UploadBot passes file chunks straight from Telegram into the upload request. |
| 18 | +Uploading starts before downloading finishes, with bounded buffers and no |
| 19 | +temporary files on the bot host. |
| 20 | + |
18 | 21 | ```text |
19 | | -Telegram -> 512 KiB chunks -> UploadBot -> HTTP PUT -> File2Share |
20 | | - │ |
21 | | - No temporary file |
| 22 | +Telegram -> 512 KiB chunks -> UploadBot -> File2Share -> Download link |
22 | 23 | ``` |
23 | 24 |
|
24 | | -## Why UploadBot? |
25 | | - |
26 | | -- **Start uploading immediately.** Telegram chunks feed directly into an |
27 | | - asynchronous HTTP upload, without waiting for the full download. |
28 | | -- **Keep memory bounded.** Backpressure and a configurable concurrency limit |
29 | | - keep file size from becoming buffer size. |
30 | | -- **Stay responsive.** Shared HTTP connections, optional native cryptography and |
31 | | - uvloop, progress updates, and cancellable transfers. |
32 | | -- **Run it your way.** Environment configuration, an optional user allowlist, |
33 | | - Docker Compose, and support for custom upload hosts. |
34 | | - |
35 | | -## File2Share hosting |
36 | | - |
37 | | -The default host is `https://file2share.us`. No hosting account or API key is |
38 | | -needed. UploadBot streams each file in a single PUT request and returns the |
39 | | -direct file URL supplied by File2Share. |
40 | | - |
41 | | -- Files can be up to **95 MB** (`95000000` bytes). |
42 | | -- File2Share keeps uploads for **up to 14 days**. |
43 | | -- The host allows **40 uploads per hour per IP address**. |
44 | | -- Anyone with the download link can access the file. |
45 | | -- Programs and web pages such as `.exe`, `.apk`, `.html`, and `.svg` are rejected |
46 | | - by the host. Archive those files before sending them. |
| 25 | +## What you get |
47 | 26 |
|
48 | | -These are the host's limits, documented in the |
49 | | -[File2Share command-line guide](https://www.file2share.us/cli). Larger files need |
50 | | -File2Share's separate chunked upload API, which UploadBot does not implement. |
51 | | -Increasing `MAX_FILE_SIZE` above 95 MB is rejected when File2Share is selected. |
52 | | - |
53 | | -Custom hosts can be configured with `TRANSFER_URL`. They must accept raw PUT |
54 | | -uploads at `/<filename>` and return a download URL in the response body or the |
55 | | -`X-Direct-Url` header. Limits and retention depend on the selected host. |
| 27 | +- **Streaming uploads** without a separate download-to-disk step. |
| 28 | +- **Responsive transfers** with progress updates and `/cancel`. |
| 29 | +- **Controlled concurrency** with one transfer per user and a global limit. |
| 30 | +- **Simple hosting** with uv, Docker Compose, and an optional user allowlist. |
56 | 31 |
|
57 | 32 | ## Quick start |
58 | 33 |
|
59 | | -Requires **Python 3.11+**, a Telegram bot token from |
60 | | -[@BotFather](https://t.me/BotFather), and an API ID/hash from |
61 | | -[my.telegram.org/apps](https://my.telegram.org/apps). The API ID/hash are also |
62 | | -required for bot accounts because UploadBot uses Telegram's MTProto interface. |
| 34 | +You need [uv](https://docs.astral.sh/uv/getting-started/installation/), Python 3.11+, |
| 35 | +a bot token from [BotFather](https://t.me/BotFather), and an API ID/hash from |
| 36 | +[my.telegram.org/apps](https://my.telegram.org/apps). |
63 | 37 |
|
64 | 38 | ```bash |
65 | 39 | git clone https://github.com/IlyaKhalafi/UploadBot.git |
66 | 40 | cd UploadBot |
67 | | -python3 -m venv .venv |
68 | | -source .venv/bin/activate |
69 | | -python -m pip install -r requirements.lock |
70 | | -python -m pip install --no-deps . |
71 | 41 | cp .env.example .env |
72 | 42 | # Fill in API_ID, API_HASH, and BOT_TOKEN in .env. |
73 | | -python main.py |
| 43 | +uv sync --locked --no-dev --extra speed |
| 44 | +uv run --no-sync uploadbot |
74 | 45 | ``` |
75 | 46 |
|
76 | | -On Windows, activate with `.venv\Scripts\activate`. The lock includes optional |
77 | | -speed packages; uvloop is automatically skipped on Windows. For a minimal |
78 | | -installation without speed extras, use `python -m pip install -r requirements.txt`. |
79 | | - |
80 | | -Using [uv](https://docs.astral.sh/uv/)? Install the same locked environment with |
81 | | -`uv sync --locked --extra speed`, then run `uv run --no-sync python main.py`. |
82 | | -Startup is noninteractive and works with a service manager. |
| 47 | +No File2Share account or hosting API key is required. For a personal bot, set |
| 48 | +`ALLOWED_USER_IDS` in `.env` to your numeric Telegram user ID. |
83 | 49 |
|
84 | | -## Use it |
| 50 | +## Try it |
85 | 51 |
|
86 | | -| Send to the bot | Result | |
| 52 | +| Send in a private chat | Result | |
87 | 53 | | --- | --- | |
88 | | -| `/start` or `/help` | Welcome message, file limit, and commands | |
89 | | -| A document, photo, video, audio, voice message, or animation | Stream to File2Share and return a public download URL | |
90 | | -| A public HTTP(S) file URL | Ask Telegram to fetch and send the file | |
| 54 | +| A document, photo, video, or audio file | A public download URL | |
| 55 | +| A public HTTP(S) file URL | The file sent back through Telegram | |
| 56 | +| `/start` or `/help` | Commands and the configured file limit | |
91 | 57 | | `/cancel` | Stop your active transfer | |
92 | 58 |
|
93 | | -The bot operates in private chats. Each user can run one transfer at a time; |
94 | | -additional requests receive a busy message. Uploaded files are accessible through |
95 | | -their sharing URL. File2Share removes uploads after up to 14 days. |
96 | | - |
97 | | -For URL → Telegram, the URL must point to a file Telegram can fetch without login |
98 | | -or browser cookies. Telegram imposes its own type and size limits. Signed query |
99 | | -strings are preserved. The bot host does not download these URLs. |
100 | | - |
101 | | -## Configuration |
102 | | - |
103 | | -Copy [.env.example](.env.example) to `.env`. Existing environment variables take |
104 | | -precedence. Keep `.env` and Telegram session files private; both are gitignored. |
105 | | - |
106 | | -| Variable | Default | Purpose | |
107 | | -| --- | --- | --- | |
108 | | -| `API_ID` | Required | Telegram application API ID | |
109 | | -| `API_HASH` | Required | Telegram application API hash | |
110 | | -| `BOT_TOKEN` | Required | Your bot's BotFather token | |
111 | | -| `TRANSFER_URL` | `https://file2share.us` | Upload host base URL; HTTPS recommended | |
112 | | -| `MAX_FILE_SIZE` | `95000000` | Maximum Telegram to host file size, in bytes (95 MB) | |
113 | | -| `MAX_CONCURRENT_TRANSFERS` | `3` | Total active transfers; one per user | |
114 | | -| `TRANSFER_TIMEOUT` | `1800` | Per-transfer time limit in seconds | |
115 | | -| `ALLOWED_USER_IDS` | Empty | Comma-separated Telegram user IDs; empty permits everyone | |
116 | | -| `SESSION_PATH` | `data/uploadbot` | Persistent Telethon session path | |
117 | | - |
118 | | -Use `ALLOWED_USER_IDS` for a personal bot. Increasing concurrency trades more |
119 | | -network connections and bounded per-transfer buffers for more simultaneous work. |
120 | | -`MAX_FILE_SIZE` applies to files received from Telegram. Telegram controls limits |
121 | | -when it fetches a URL directly. For custom hosts, set `MAX_FILE_SIZE` to a limit |
122 | | -that the host supports. |
123 | | - |
124 | | -Existing installations should update both settings in `.env`. |
125 | | - |
126 | | -```dotenv |
127 | | -TRANSFER_URL=https://file2share.us |
128 | | -MAX_FILE_SIZE=95000000 |
129 | | -``` |
130 | | - |
131 | | -## Docker |
| 59 | +Voice messages and animations work too. File URLs must be accessible to Telegram |
| 60 | +without browser cookies or a login. |
132 | 61 |
|
133 | | -Configure `.env` first, then run the following command. |
| 62 | +## Hosting limits |
134 | 63 |
|
135 | | -```bash |
136 | | -docker compose up --build -d |
137 | | -docker compose logs -f bot |
138 | | -``` |
139 | | - |
140 | | -The container runs as a non-root user. A named volume persists the Telegram |
141 | | -session, and no incoming port is required. Stop with `docker compose down`. |
| 64 | +File2Share accepts **up to 95 MB per request**, keeps files for **up to 14 days**, |
| 65 | +and limits uploads to **40 per hour per IP address**. Anyone with the link can |
| 66 | +download the file. Some file types, including programs and web pages, must be |
| 67 | +archived first. See the [host's API guide](https://www.file2share.us/cli). |
142 | 68 |
|
143 | | -## Performance and reliability |
| 69 | +Larger-file uploads through File2Share's separate chunked API are not implemented. |
| 70 | +You can also configure another compatible PUT upload host. |
144 | 71 |
|
145 | | -The old flow downloaded a file to disk and then uploaded it using a blocking |
146 | | -HTTP call. The new flow removes temporary file I/O and starts the upload while |
147 | | -the Telegram download is still in progress. Memory remains bounded by chunks and |
148 | | -transport buffers rather than file size. Actual throughput depends on Telegram, |
149 | | -your network, and the upload host; no universal speed multiplier is claimed. |
| 72 | +## Run with Docker |
150 | 73 |
|
151 | | -Uploads use raw PUT requests with a known `Content-Length`. File2Share returns |
152 | | -the direct download URL in its `X-Direct-Url` response header. HTTP failures, |
153 | | -incomplete downloads, invalid response URLs, and timeouts are reported as errors. |
154 | | -Redirects are rejected. Configure the final upload endpoint. Interrupted uploads |
155 | | -are not resumed or automatically retried; resend the file when ready. |
156 | | - |
157 | | -See [the architecture guide](docs/architecture.md) for flow control, cleanup, and |
158 | | -known limitations, including [local test downloads](docs/architecture.md#local-test-downloads). |
159 | | -Upgrading an older installation? Read the |
160 | | -[migration notes](CHANGELOG.md#migrating-from-1x). |
161 | | - |
162 | | -## Development |
| 74 | +Configure `.env`, then start the bot. |
163 | 75 |
|
164 | 76 | ```bash |
165 | | -uv sync --locked --extra dev --extra speed |
166 | | -uv run --no-sync ruff check . |
167 | | -uv run --no-sync ruff format --check . |
168 | | -uv run --no-sync pytest -q |
| 77 | +docker compose up --build -d |
| 78 | +docker compose logs -f bot |
169 | 79 | ``` |
170 | 80 |
|
171 | | -Tests run offline against a local HTTP server and simulated Telegram messages. |
172 | | -They cover streaming before the download completes, byte integrity, bounded |
173 | | -Python allocations, HTTP errors, size limits, cancellation, and configuration. |
174 | | -CI runs on Python 3.11 through 3.14. |
| 81 | +The container runs as a non-root user and persists the Telegram session in a named |
| 82 | +volume. No incoming port is needed. |
175 | 83 |
|
176 | | -Read [CONTRIBUTING.md](CONTRIBUTING.md) to report a bug or contribute a fix. |
177 | | -If UploadBot is useful to you, a GitHub star helps other people discover it. |
| 84 | +## More |
178 | 85 |
|
179 | | -## License |
| 86 | +- [Setup and configuration](docs/setup.md) for every setting and custom upload hosts. |
| 87 | +- [How streaming works](docs/architecture.md) for flow control and failure handling. |
| 88 | +- [Contributing](CONTRIBUTING.md) for development commands and tests. |
| 89 | +- [Migration notes](CHANGELOG.md#migrating-from-1x) for older installations. |
180 | 90 |
|
181 | | -[MIT](LICENSE). |
| 91 | +MIT licensed. If UploadBot saves you time, a star helps others find it. |
0 commit comments