Files
baiyue-logistics-chat/logistics_chat/routes/admin.py
T
2026-11-02 17:51:10 +08:00

56 lines
1.4 KiB
Python

"""HTTP adapters for admin; business logic lives in services."""
from flask import Blueprint, Response, g, render_template, request
from .. import business_service, staff_service
bp = Blueprint('admin', __name__)
@bp.route('/api/admin/stats')
def admin_stats():
return business_service.admin_stats()
@bp.route('/admin/login', methods=['POST'])
def admin_login():
request.max_content_length = 4096
return staff_service.login(request.get_json(silent=True))
@bp.get('/api/admin/session')
def staff_session():
return {'ok': True, **g.staff}
@bp.post('/admin/logout')
def staff_logout():
return staff_service.logout()
@bp.route('/api/export_chat')
def export_chat():
format = 'csv' if request.args.get('format') == 'csv' else 'xlsx'
mimetype = 'text/csv' if format == 'csv' else 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
return Response(business_service.export_chat(format), mimetype=mimetype,
headers={'Content-Disposition': 'attachment;filename=chat_export.' + format})
@bp.route('/api/agents/list')
def agents_list():
return business_service.agents_list()
@bp.route('/api/search_chat')
def search_chat():
return business_service.search_chat(request.args.get('q', '').strip())
@bp.route('/admin')
def admin():
return render_template('admin_login.html')
@bp.route('/admin/dashboard')
def admin_dash():
return render_template('admin.html')