33 lines
987 B
Python
Raw Normal View History

2020-08-13 03:58:55 +00:00
import random
import string
2020-08-10 07:27:52 +00:00
from aiohttp import web
2020-08-13 03:58:55 +00:00
from .config import chat_ids, alias_ids
2020-08-12 10:39:29 +00:00
2020-08-10 07:27:52 +00:00
def setup_routes(app, handler):
h = handler
2020-08-12 10:39:29 +00:00
routes = [
web.get('/', h.home, name='home')
]
for chat_id in chat_ids:
2020-08-13 03:58:55 +00:00
while True:
alias_id = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(len(str(chat_id)))])
if alias_id in alias_ids:
continue
alias_ids.append(alias_id)
break
p = f"/{alias_id}"
2020-08-12 10:39:29 +00:00
r = [
web.get(p, h.index),
2020-08-13 14:16:59 +00:00
web.get(p + r"/logo", h.logo),
2020-08-12 10:39:29 +00:00
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.head(p + r"/{id:\d+}/thumbnail", h.thumbnail_head),
2020-08-10 07:27:52 +00:00
]
2020-08-12 10:39:29 +00:00
routes += r
app.add_routes(routes)