From 0a7c733f2f34fca8989039e4654c735b96c0a4d8 Mon Sep 17 00:00:00 2001 From: odysseusmax Date: Thu, 13 Aug 2020 14:16:59 +0000 Subject: [PATCH] add channel logo to index page --- app/routes.py | 1 + app/templates/index.html | 5 +++-- app/views.py | 26 +++++++++++++++++++++++++- requirements.txt | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/routes.py b/app/routes.py index 9349f02..538a138 100644 --- a/app/routes.py +++ b/app/routes.py @@ -21,6 +21,7 @@ def setup_routes(app, handler): p = f"/{alias_id}" r = [ 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), diff --git a/app/templates/index.html b/app/templates/index.html index fe91a58..2f70ac0 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -1,7 +1,8 @@ {% include 'header.html' %} -
-
+
+
+

{{name}}

diff --git a/app/views.py b/app/views.py index 224513c..befc2e3 100644 --- a/app/views.py +++ b/app/views.py @@ -114,7 +114,8 @@ class Views: 'cur_page' : offset_val+1, 'next_page': next_page, 'search': search_query, - 'name' : chat.title + 'name' : chat.title, + 'logo': req.rel_url.with_path(f"/{alias_id}/logo") } @@ -191,6 +192,29 @@ class Views: async def thumbnail_head(self, req): return await self.handle_request(req, head=True, thumb=True) + + + async def logo(self, req): + alias_id = req.rel_url.path.split('/')[1] + chat_id = chat_ids[alias_ids.index(alias_id)] + photo = await self.client.get_profile_photos(chat_id) + if not photo: + return web.Response(status=404, text="404: Chat has no profile photo") + photo = photo[0] + size = photo.sizes[0] + media = types.InputPhotoFileLocation( + id=photo.id, + access_hash=photo.access_hash, + file_reference=photo.file_reference, + thumb_size=size.type + ) + body = self.client.iter_download(media) + r = web.Response( + status=200, + body=body, + ) + r.enable_chunked_encoding() + return r async def handle_request(self, req, head=False, thumb=False): diff --git a/requirements.txt b/requirements.txt index cd8c081..4c97afd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ aiohttp aiohttp-jinja2 -telethon +git+https://github.com/LonamiWebs/Telethon.git cryptg