new file: app/blueprints/__pycache__/__init__.cpython-311.pyc new file: app/blueprints/__pycache__/__init__.cpython-39.pyc new file: app/blueprints/__pycache__/admin.cpython-311.pyc new file: app/blueprints/__pycache__/admin.cpython-39.pyc new file: app/blueprints/__pycache__/auth.cpython-311.pyc new file: app/blueprints/__pycache__/auth.cpython-39.pyc new file: app/blueprints/__pycache__/brand.cpython-311.pyc new file: app/blueprints/__pycache__/brand.cpython-39.pyc new file: app/blueprints/__pycache__/image.cpython-311.pyc new file: app/blueprints/__pycache__/image.cpython-39.pyc new file: app/blueprints/__pycache__/main.cpython-311.pyc new file: app/blueprints/__pycache__/main.cpython-39.pyc new file: app/blueprints/admin.py new file: app/blueprints/auth.py new file: app/blueprints/brand.py new file: app/blueprints/image.py new file: app/blueprints/main.py new file: app/brand_spider/__pycache__/main.cpython-39.pyc new file: app/brand_spider/__pycache__/web_dec.cpython-39.pyc new file: app/brand_spider/main.py new file: app/brand_spider/web_dec.py new file: app/static/bg.jpg new file: "app/static/\345\223\201\347\211\214\346\226\207\346\241\243\346\240\274\345\274\217_\346\250\241\346\235\277.xlsx" new file: "app/static/\346\250\241\346\235\2772-\344\273\245\346\226\207\344\273\266\345\244\271\346\226\271\345\274\217\344\270\212\344\274\240.zip" new file: app/tool/.device_id new file: app/tool/__pycache__/devices.cpython-311.pyc new file: app/tool/__pycache__/devices.cpython-39.pyc new file: app/tool/devices.py
96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
"""
|
||
主页面蓝图:首页、home、图片工作台、品牌页、静态文件、Logo
|
||
"""
|
||
import os
|
||
from flask import Blueprint, send_file
|
||
|
||
from app_common import (
|
||
get_db,
|
||
_render_html,
|
||
_is_session_user_valid,
|
||
login_required,
|
||
admin_required,
|
||
STATIC_DIR,
|
||
BASE_DIR,
|
||
ASSETS_DIR
|
||
)
|
||
from flask import redirect, url_for, session
|
||
|
||
from config import base_url,version
|
||
|
||
main_bp = Blueprint('main', __name__)
|
||
|
||
|
||
@main_bp.route('/')
|
||
def index():
|
||
if session.get('user_id') and _is_session_user_valid():
|
||
return redirect(url_for('main.home'))
|
||
return redirect(url_for('auth.login'))
|
||
|
||
|
||
@main_bp.route('/home')
|
||
@login_required
|
||
def home():
|
||
try:
|
||
conn = get_db()
|
||
with conn.cursor() as cur:
|
||
cur.execute("SELECT username, is_admin FROM users WHERE id = %s", (session['user_id'],))
|
||
row = cur.fetchone()
|
||
conn.close()
|
||
return _render_html('home.html', username=row.get('username', ''), is_admin=bool(row.get('is_admin')), user_id=session.get('user_id'),baseUrl=base_url,version=version)
|
||
except Exception:
|
||
return _render_html('home.html', username=session.get('username', ''), is_admin=False, user_id=session.get('user_id'),baseUrl=base_url,version=version)
|
||
|
||
|
||
@main_bp.route('/image')
|
||
@login_required
|
||
def wb():
|
||
return _render_html('index.html')
|
||
|
||
|
||
@main_bp.route('/brand')
|
||
@login_required
|
||
def brand_page():
|
||
return _render_html('brand.html')
|
||
|
||
|
||
|
||
|
||
@main_bp.route('/static/<path:filename>')
|
||
def serve_static(filename):
|
||
"""提供 static 目录及子目录下的静态文件访问。"""
|
||
filepath = os.path.normpath(os.path.join(STATIC_DIR, filename))
|
||
static_abs = os.path.abspath(STATIC_DIR)
|
||
file_abs = os.path.abspath(filepath)
|
||
if not file_abs.startswith(static_abs) or not os.path.isfile(file_abs):
|
||
return '', 404
|
||
return send_file(file_abs, as_attachment=False)
|
||
|
||
|
||
@main_bp.route('/assets/<path:filename>')
|
||
def serve_assets(filename):
|
||
"""提供 static 目录及子目录下的静态文件访问。"""
|
||
filepath = os.path.normpath(os.path.join(ASSETS_DIR, filename))
|
||
static_abs = os.path.abspath(ASSETS_DIR)
|
||
file_abs = os.path.abspath(filepath)
|
||
if not file_abs.startswith(static_abs) or not os.path.isfile(file_abs):
|
||
return '', 404
|
||
return send_file(file_abs, as_attachment=False)
|
||
|
||
|
||
@main_bp.route('/new_web_source/<path:filename>')
|
||
def serve_new_web_source(filename):
|
||
"""提供 static 目录及子目录下的静态文件访问。"""
|
||
filepath = os.path.normpath(os.path.join("new_web_source", filename))
|
||
static_abs = os.path.abspath("new_web_source")
|
||
file_abs = os.path.abspath(filepath)
|
||
if not file_abs.startswith(static_abs) or not os.path.isfile(file_abs):
|
||
return '', 404
|
||
return send_file(file_abs, as_attachment=False)
|
||
|
||
|
||
|
||
@main_bp.route('/logo.jpg', methods=['GET'])
|
||
def get_logo_image():
|
||
return send_file(os.path.join(BASE_DIR, "logo.jpg"), mimetype='image/jpeg')
|