123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- from aiohttp import web
- from aiohttp_session import get_session
- from templates import render_template
- from video import VideoError, find_video_by_id
- from user import UserError, find_user_by_id, get_avatar
- from config import config
- routes = web.RouteTableDef()
- @routes.get('/')
- async def index(request):
- return web.HTTPFound('/random')
- @routes.get('/404')
- async def index(request):
- session = await get_session(request)
- return render_template('not_found',
- session=session)
- @routes.get('/random')
- async def random(request):
- session = await get_session(request)
- return render_template('random',
- session=session)
- @routes.get('/watch/{video_id:[0-9]+}')
- async def watch(request):
- session = await get_session(request)
- video_id = request.match_info['video_id']
- try:
- video = await find_video_by_id(video_id)
- except VideoError:
- return render_template('not_found',
- session=session)
- return render_template('video',
- session=session,
- video=video)
- @routes.get('/search')
- async def search(request):
- session = await get_session(request)
- return render_template('search',
- session=session)
- @routes.get('/login')
- async def login(request):
- session = await get_session(request)
- return render_template('login',
- session=session,
- hcaptcha_sitekey=config.HCAPTCHA_SITEKEY)
- @routes.get('/signup')
- async def signup(request):
- session = await get_session(request)
- return render_template('signup',
- session=session,
- hcaptcha_sitekey=config.HCAPTCHA_SITEKEY)
- @routes.get('/user/{user_id:[0-9]+}')
- async def user(request):
- session = await get_session(request)
- user_id = request.match_info['user_id']
- return render_template('user',
- session=session,
- user_id=user_id)
- @routes.get('/upload')
- async def upload(request):
- session = await get_session(request)
- return render_template('upload',
- session=session,
- hcaptcha_sitekey=config.HCAPTCHA_SITEKEY)
|