import os from web.main import main from quart import render_template, send_from_directory,request from quart import session, redirect, url_for,flash from functools import wraps from myutils.ConfigManager import myCongif from werkzeug.utils import secure_filename ''' 页面路由 ''' def login_required(f): @wraps(f) async def decorated_function(*args, **kwargs): if 'user' not in session: return redirect(url_for('main.login',error='未登录,请重新登录')) return await f(*args, **kwargs) return decorated_function @main.route('/') async def index(): #return await render_template('实时预览.html') return await render_template('login.html') #return await render_template('index_webrtc.html') @main.route('/login', methods=['GET', 'POST']) async def login(): if request.method == 'POST': form = await request.form username = form.get('username') password = form.get('password') # Add your login logic here if username == 'admin' and password == 'password': return redirect(url_for('main.dashboard')) # Assuming you have a dashboard route else: return "Invalid credentials", 401 return await render_template('login.html') @main.route('/dashboard') async def dashboard(): return "Welcome to the dashboard!" @main.route('/favicon.ico') async def favicon(): return await send_from_directory('web/main/static', 'favicon.ico') @main.route('/') @login_required async def get_html(html): return await render_template(html) ''' 各种配置文件路由 ''' @main.route('/data/') async def data(file): return await send_from_directory('web/main/static/data', file) @main.route('/files//') async def files(subdir,file): return await send_from_directory(os.path.join('web/main/static/files', subdir), file) @main.route('/images//') async def images(subdir,file): return await send_from_directory(os.path.join('web/main/static/images', subdir), file) @main.route('/resources/') async def resources(file): return await send_from_directory('web/main/static/resources', file) @main.route('/resources//') async def resources_dir(subdir,file): return await send_from_directory(os.path.join('web/main/static/resources', subdir), file) @main.route('/resources/css//') async def resources_css_dir(subdir,file): return await send_from_directory(os.path.join('web/main/static/resources/css', subdir), file) @main.route('/resources/scripts//') async def resources_scripts_dir(subdir,file): return await send_from_directory(os.path.join('web/main/static/resources/scripts', subdir), file)