We're so back #16
22
room.py
22
room.py
|
@ -3,6 +3,8 @@ from sanic import Blueprint, exceptions
|
||||||
from random import choice
|
from random import choice
|
||||||
from ext import *
|
from ext import *
|
||||||
from config import headers
|
from config import headers
|
||||||
|
from PIL import Image
|
||||||
|
import os
|
||||||
|
|
||||||
jobs = []
|
jobs = []
|
||||||
|
|
||||||
|
@ -363,15 +365,11 @@ async def get_room (request, code):
|
||||||
members_map.append ({'name': member_order.name, 'propic': member_order.propic, 'sponsorship': member_order.sponsorship})
|
members_map.append ({'name': member_order.name, 'propic': member_order.propic, 'sponsorship': member_order.sponsorship})
|
||||||
return {'name': order_data.room_name, 'members': members_map}
|
return {'name': order_data.room_name, 'members': members_map}
|
||||||
|
|
||||||
|
async def generate_image(request, code):
|
||||||
|
|
||||||
@bp.route("/view/<code>")
|
|
||||||
async def get_view(request, code):
|
|
||||||
if code in jobs:
|
|
||||||
raise exceptions.SanicException("The room's preview is being generated... Wait a little longer", status_code=409)
|
|
||||||
jobs.append(code)
|
jobs.append(code)
|
||||||
try:
|
try:
|
||||||
room_data = await get_room(request, code)
|
room_data = await get_room(request, code)
|
||||||
|
|
||||||
return room_data
|
return room_data
|
||||||
except Exception:
|
except Exception:
|
||||||
# Remove fault job
|
# Remove fault job
|
||||||
|
@ -382,3 +380,15 @@ async def get_view(request, code):
|
||||||
if len(jobs) > 0: jobs.pop()
|
if len(jobs) > 0: jobs.pop()
|
||||||
if not room_data:
|
if not room_data:
|
||||||
raise exceptions.SanicException("There's no room with that code.", status_code=404)
|
raise exceptions.SanicException("There's no room with that code.", status_code=404)
|
||||||
|
|
||||||
|
@bp.route("/view/<code>")
|
||||||
|
async def get_view(request, code):
|
||||||
|
if code in jobs:
|
||||||
|
raise exceptions.SanicException("The room's preview is being generated... Wait a little longer", status_code=409)
|
||||||
|
room_file_name = f"res/rooms/{code}.jpg"
|
||||||
|
|
||||||
|
if not os.path.exists(room_file_name):
|
||||||
|
await generate_image(request, code)
|
||||||
|
tpl = request.app.ctx.tpl.get_template('viewRoom.html')
|
||||||
|
return html(tpl.render(imgPath=room_file_name))
|
||||||
|
|
Loading…
Reference in New Issue