remove heroku support

This commit is contained in:
odysseusmax
2020-09-19 16:58:02 +05:30
parent fcf5b580c6
commit d11a9f0f46
3 changed files with 20 additions and 17 deletions

View File

@ -78,10 +78,6 @@ This is the general format, change the values of corresponding fields as your re
$ python3 -m app $ python3 -m app
``` ```
* **Other quick methods.**
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/odysseusmax/tg-index/tree/master) [![Run on Repl.it](https://repl.it/badge/github/odysseusmax/tg-index)](https://repl.it/github/odysseusmax/tg-index)
## API ## API

View File

@ -5,6 +5,7 @@ import logging
import aiohttp_jinja2 import aiohttp_jinja2
import jinja2 import jinja2
from aiohttp import web from aiohttp import web
from aiohttp_basicauth import BasicAuthMiddleware
from .telegram import Client from .telegram import Client
from .routes import setup_routes from .routes import setup_routes

View File

@ -60,8 +60,7 @@ class Views:
async def _index(self, req, api=False): async def _index(self, req, api=False):
alias_pos = 2 if api else 1 alias_id = req.match_info['chat']
alias_id = req.match_info['chat'] #req.rel_url.path.split('/')[alias_pos]
chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0]
chat_id = chat['chat_id'] chat_id = chat['chat_id']
chat_name = chat['title'] chat_name = chat['title']
@ -101,7 +100,7 @@ class Views:
media=True, media=True,
thumbnail=f"/{alias_id}/{m.id}/thumbnail", thumbnail=f"/{alias_id}/{m.id}/thumbnail",
mime_type=m.file.mime_type, mime_type=m.file.mime_type,
insight = get_file_name(m)[:100], insight = get_file_name(m),
date = str(m.date), date = str(m.date),
size=m.file.size, size=m.file.size,
human_size=get_human_size(m.file.size), human_size=get_human_size(m.file.size),
@ -158,17 +157,16 @@ class Views:
async def api_info(self, req): async def api_info(self, req):
data = await self._info(req, True) data = await self._info(req)
if not data['found']: if not data['found']:
return web.Response(status=404, text="404: Not Found") return web.Response(status=404, text="404: Not Found")
return web.json_response(data) return web.json_response(data)
async def _info(self, req, api=False): async def _info(self, req):
file_id = int(req.match_info["id"]) file_id = int(req.match_info["id"])
alias_pos = 2 if api else 1 alias_id = req.match_info['chat']
alias_id = req.match_info['chat'] #req.rel_url.path.split('/')[alias_pos]
chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0]
chat_id = chat['chat_id'] chat_id = chat['chat_id']
try: try:
@ -249,7 +247,7 @@ class Views:
async def logo(self, req): async def logo(self, req):
alias_id = req.match_info['chat'] # req.rel_url.path.split('/')[1] alias_id = req.match_info['chat']
chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0]
chat_id = chat['chat_id'] chat_id = chat['chat_id']
chat_name = "Image not available" chat_name = "Image not available"
@ -287,6 +285,10 @@ class Views:
r = web.Response( r = web.Response(
status=200, status=200,
body=body, body=body,
headers={
"Content-Type": "image/jpeg",
"Content-Disposition": 'inline; filename="logo.jpg"'
}
) )
#r.enable_chunked_encoding() #r.enable_chunked_encoding()
return r return r
@ -302,7 +304,7 @@ class Views:
async def thumbnail_get(self, req): async def thumbnail_get(self, req):
file_id = int(req.match_info["id"]) file_id = int(req.match_info["id"])
alias_id = req.match_info['chat'] #req.rel_url.path.split('/')[1] alias_id = req.match_info['chat']
chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0]
chat_id = chat['chat_id'] chat_id = chat['chat_id']
try: try:
@ -352,14 +354,18 @@ class Views:
r = web.Response( r = web.Response(
status=200, status=200,
body=body, body=body,
headers={
"Content-Type": "image/jpeg",
"Content-Disposition": 'inline; filename="thumbnail.jpg"'
}
) )
r.enable_chunked_encoding() #r.enable_chunked_encoding()
return r return r
async def handle_request(self, req, head=False): async def handle_request(self, req, head=False):
file_id = int(req.match_info["id"]) file_id = int(req.match_info["id"])
alias_id = req.match_info['chat'] # req.rel_url.path.split('/')[1] alias_id = req.match_info['chat']
chat = [i for i in chat_ids if i['alias_id'] == alias_id][0] chat = [i for i in chat_ids if i['alias_id'] == alias_id][0]
chat_id = chat['chat_id'] chat_id = chat['chat_id']