123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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('/mkuser')
- async def debug(request):
- from db import db, User
- from tools import hash_password
-
- u = await db.create(User, username='cirno', password=hash_password('cirno'), ip_address='127.0.0.1')
-
- return web.json_response({'i':u.id})
- @routes.get('/mkuser2')
- async def debug(request):
- from db import db, User
- from tools import hash_password
-
- u = await db.create(User, username='cirno9', password=hash_password('cirno9'), ip_address='127.0.0.1')
-
- return web.json_response({'i':u.id})
- @routes.get('/mkvid')
- async def debug(request):
- from db import db, Video, User, VideoTag, Tag
-
- u = await db.get(User.select().where(User.username == 'cirno'))
- v = await db.create(Video, video='test', thumbnail='/static/thumbs/default.png', uploader=u)
-
- tag1 = await db.get_or_create(Tag, tag='test1')
- tag2 = await db.get_or_create(Tag, tag='test2')
- tag3 = await db.get_or_create(Tag, tag='test3')
- tag4 = await db.get_or_create(Tag, tag='test4')
- await db.create(VideoTag, video=v, tag=tag1[0])
- await db.create(VideoTag, video=v, tag=tag2[0])
- await db.create(VideoTag, video=v, tag=tag3[0])
- await db.create(VideoTag, video=v, tag=tag4[0])
- return web.json_response({'i':v.id})
- @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)
|