add channel logo to index page
This commit is contained in:
parent
359a991984
commit
0a7c733f2f
|
@ -21,6 +21,7 @@ def setup_routes(app, handler):
|
||||||
p = f"/{alias_id}"
|
p = f"/{alias_id}"
|
||||||
r = [
|
r = [
|
||||||
web.get(p, h.index),
|
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+}/view", h.info),
|
||||||
web.get(p + r"/{id:\d+}/download", h.download_get),
|
web.get(p + r"/{id:\d+}/download", h.download_get),
|
||||||
web.head(p + r"/{id:\d+}/download", h.download_head),
|
web.head(p + r"/{id:\d+}/download", h.download_head),
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
{% include 'header.html' %}
|
{% include 'header.html' %}
|
||||||
|
|
||||||
<div class="block md:flex justify-between px-4 text-center">
|
<div class="block md:flex justify-between items-center px-4 text-center">
|
||||||
<div class="my-2 text-2xl md:text-right font-bold text-blue-500">
|
<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>
|
<h1> {{name}} </h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
26
app/views.py
26
app/views.py
|
@ -114,7 +114,8 @@ class Views:
|
||||||
'cur_page' : offset_val+1,
|
'cur_page' : offset_val+1,
|
||||||
'next_page': next_page,
|
'next_page': next_page,
|
||||||
'search': search_query,
|
'search': search_query,
|
||||||
'name' : chat.title
|
'name' : chat.title,
|
||||||
|
'logo': req.rel_url.with_path(f"/{alias_id}/logo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,6 +194,29 @@ class Views:
|
||||||
return await self.handle_request(req, head=True, thumb=True)
|
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):
|
async def handle_request(self, req, head=False, thumb=False):
|
||||||
file_id = int(req.match_info["id"])
|
file_id = int(req.match_info["id"])
|
||||||
alias_id = req.rel_url.path.split('/')[1]
|
alias_id = req.rel_url.path.split('/')[1]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
aiohttp
|
aiohttp
|
||||||
aiohttp-jinja2
|
aiohttp-jinja2
|
||||||
telethon
|
git+https://github.com/LonamiWebs/Telethon.git
|
||||||
cryptg
|
cryptg
|
||||||
|
|
Loading…
Reference in New Issue