forked from prgofficial/FileToLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split into many files and add license
- Loading branch information
Showing
13 changed files
with
1,113 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
*.session | ||
*.session-journal | ||
|
||
__pycache__ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# tgfilestream | ||
A Telegram bot that can stream Telegram files to users over HTTP. | ||
|
||
## Setup | ||
Install dependencies (see [requirements.txt](/requirements.txt)), configure | ||
environment variables (see below) and run with `python3 -m tgfilestream`. | ||
|
||
A reverse proxy is recommended to add TLS. When using a reverse proxy, keep | ||
`HOST` as-is, but add the publicly accessible URL to `PUBLIC_URL`. The URL | ||
should include the protocol, e.g. `https://example.com`. | ||
|
||
### Environment variables | ||
* `TG_API_ID` (required) - Your Telegram API ID. | ||
* `TG_API_HASH` (required) - Your Telegram API hash. | ||
* `TG_SESSION_NAME` (defaults to `tgfilestream`) - The name of the Telethon session file to use. | ||
* `PORT` (defaults to `8080`) - The port to listen at. | ||
* `HOST` (defaults to `localhost`) - The host to listen at. | ||
* `PUBLIC_URL` (defaults to `http://localhost:8080`) - The prefix for links that the bot gives. | ||
* `TRUST_FORWARD_HEADERS` (defaults to false) - Whether or not to trust X-Forwarded-For headers when logging requests. | ||
* `DEBUG` (defaults to false) - Whether or not to enable extra prints. | ||
* `LOG_CONFIG` - Path to a Python basic log config. Overrides `DEBUG`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__version__ = "0.1.0" | ||
__author__ = "Tulir Asokan <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# tgfilestream - A Telegram bot that can stream Telegram files to users over HTTP. | ||
# Copyright (C) 2019 Tulir Asokan | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
import asyncio | ||
import sys | ||
|
||
from aiohttp import web | ||
|
||
from .telegram import client | ||
from .web_routes import routes | ||
from .config import host, port, public_url | ||
from .log import log | ||
|
||
server = web.Application() | ||
server.add_routes(routes) | ||
runner = web.AppRunner(server) | ||
|
||
loop = asyncio.get_event_loop() | ||
|
||
|
||
async def start() -> None: | ||
await client.start() | ||
|
||
await runner.setup() | ||
await web.TCPSite(runner, host, port).start() | ||
|
||
|
||
async def stop() -> None: | ||
await runner.cleanup() | ||
await client.disconnect() | ||
|
||
|
||
try: | ||
loop.run_until_complete(start()) | ||
except Exception: | ||
log.fatal("Failed to initialize", exc_info=True) | ||
sys.exit(2) | ||
|
||
log.info("Initialization complete") | ||
log.debug(f"Listening at http://{host}:{port}") | ||
log.debug(f"Public URL prefix is {public_url}") | ||
|
||
try: | ||
loop.run_forever() | ||
except KeyboardInterrupt: | ||
loop.run_until_complete(stop()) | ||
except Exception: | ||
log.fatal("Fatal error in event loop", exc_info=True) | ||
sys.exit(3) |
Oops, something went wrong.