add channel logo to index page

This commit is contained in:
odysseusmax 2020-08-13 14:16:59 +00:00
parent 359a991984
commit 0a7c733f2f
4 changed files with 30 additions and 4 deletions

View File

@ -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),

View File

@ -1,7 +1,8 @@
{% include 'header.html' %}
<div class="block md:flex justify-between px-4 text-center">
<div class="my-2 text-2xl md:text-right font-bold text-blue-500">
<div class="block md:flex justify-between items-center px-4 text-center">
<div class="my-2 block md:flex items-center justify-center md:justify-start text-2xl md:text-right font-bold text-blue-500">
<img class="mx-auto md:ml-0 md:mr-1 my-2 w-16 h-16 rounded-full bg-black" src="{{logo}}">
<h1> {{name}} </h1>
</div>

View File

@ -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):

View File

@ -1,4 +1,4 @@
aiohttp
aiohttp-jinja2
telethon
git+https://github.com/LonamiWebs/Telethon.git
cryptg