diff --git a/.gitignore b/.gitignore index adb9b40..1efcff8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .env __pycache__/ venv/ +*.sh diff --git a/README.md b/README.md index 65497eb..35edc93 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,13 @@ This is the general format, change the values of corresponding fields as your re "index_group": false, "index_channel": true, "exclude_chats": [], - "include_chats": [] + "include_chats": [], + "otg": { + "enable": false, + "include_private": false, + "include_group": true, + "include_channel": true + } } ``` > * `index_all` - Whether to consider all the chats associated with the telegram account. Value should either be `true` or `false`. @@ -70,6 +76,7 @@ This is the general format, change the values of corresponding fields as your re > * `index_channel` - Whether to index channels. Only considered if `index_all` is set to `true`. Value should either be `true` or `false`. > * `exclude_chats` - An array/list of chat id's that should be ignored for indexing. Only considered if `index_all` is set to `true`. > * `include_chats` - An array/list of chat id's to index. Only considered if `index_all` is set to `false`. +> * `otg` - On-The-Go Indexing settings. Whether to allow indexing channels/chats other than the specified chats dynamically on the go. * **Run app.** diff --git a/app/config.py b/app/config.py index 575f87c..2e10253 100644 --- a/app/config.py +++ b/app/config.py @@ -20,14 +20,12 @@ except (KeyError, ValueError): print("\n\nPlease set the API_ID and API_HASH environment variables correctly") print("You can get your own API keys at https://my.telegram.org/apps") sys.exit(1) - + try: index_settings_str = os.environ["INDEX_SETTINGS"].strip() index_settings = json.loads(index_settings_str) - ''' - {"index_all": true, "index_private":false, "index_group": false, "index_channel": true, "include_chats": [], "exclude_chats": []} - - ''' + otg_settings = index_settings['otg'] + enable_otg = otg_settings['enable'] except: traceback.print_exc() print("\n\nPlease set the INDEX_SETTINGS environment variable correctly") diff --git a/app/routes.py b/app/routes.py index c97f3f2..855f495 100644 --- a/app/routes.py +++ b/app/routes.py @@ -29,9 +29,18 @@ def generate_alias_id(chat): async def setup_routes(app, handler): h = handler client = h.client + p = r"/{chat:[^/]+}" routes = [ web.get('/', h.home), - web.get('/api', h.api_home), + web.post('/otg', h.dynamic_view), + web.get('/otg', h.otg_view), + web.get(p, h.index), + web.get(p + r"/logo", h.logo), + web.get(p + r"/{id:\d+}/view", h.info), + web.get(p + r"/{id:\d+}/download", h.download_get), + web.head(p + r"/{id:\d+}/download", h.download_head), + web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get), + web.view(r'/{wildcard:.*}', h.wildcard) ] index_all = index_settings['index_all'] index_private = index_settings['index_private'] @@ -44,51 +53,25 @@ async def setup_routes(app, handler): alias_id = None if chat.id in exclude_chats: continue - + if chat.is_user: if index_private: alias_id = generate_alias_id(chat) - elif chat.is_group: - if index_group: - alias_id = generate_alias_id(chat) - else: + elif chat.is_channel: if index_channel: alias_id = generate_alias_id(chat) - + else: + if index_group: + alias_id = generate_alias_id(chat) + if not alias_id: continue - - p = r"/{chat:" + alias_id + "}" - p_api = '/api' + p - r = [ - web.get(p, h.index), - web.get(p_api, h.api_index), - web.get(p + r"/logo", h.logo), - web.get(p + r"/{id:\d+}/view", h.info), - web.get(p_api + r"/{id:\d+}/view", h.api_info), - web.get(p + r"/{id:\d+}/download", h.download_get), - web.head(p + r"/{id:\d+}/download", h.download_head), - web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get), - ] - routes += r log.debug(f"Index added for {chat.id} :: {chat.title} at /{alias_id}") + else: for chat_id in include_chats: chat = await client.get_entity(chat_id) alias_id = generate_alias_id(chat) - p = r"/{chat:" + alias_id + "}" - p_api = '/api' + p - r = [ - web.get(p, h.index), - web.get(p_api, h.api_index), - web.get(p + r"/logo", h.logo), - web.get(p + r"/{id:\d+}/view", h.info), - web.get(p_api + r"/{id:\d+}/view", h.api_info), - web.get(p + r"/{id:\d+}/download", h.download_get), - web.head(p + r"/{id:\d+}/download", h.download_head), - web.get(p + r"/{id:\d+}/thumbnail", h.thumbnail_get), - ] - routes += r log.debug(f"Index added for {chat.id} :: {chat.title} at /{alias_id}") - routes.append(web.view(r'/{wildcard:.*}', h.wildcard)) + app.add_routes(routes) diff --git a/app/templates/header.html b/app/templates/header.html index aa8dfc3..af6ead0 100644 --- a/app/templates/header.html +++ b/app/templates/header.html @@ -2,19 +2,22 @@
- + - ++ On-The-Go (OTG) Indexing. Index any public telegram channel or public telegram group on the go with it's username. +
+ +{{error}}
+