- Flask web application for DIT analysis - Database models for upload history, analysis results, action cards - LLM service integration with Ollama API - Dashboard, upload, and history pages - RESTful API endpoints for analysis operations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
"""
|
|
主要頁面路由
|
|
"""
|
|
|
|
from flask import Blueprint, render_template, redirect, url_for, flash, request
|
|
from models import db
|
|
from models.dit_models import DITUploadHistory, DITAnalysisResult, DITActionCard
|
|
import json
|
|
|
|
main_bp = Blueprint('main', __name__)
|
|
|
|
|
|
@main_bp.route('/')
|
|
def index():
|
|
"""首頁重導向到儀表板"""
|
|
return redirect(url_for('main.dashboard'))
|
|
|
|
|
|
@main_bp.route('/dashboard')
|
|
def dashboard():
|
|
"""儀表板頁面"""
|
|
# 取得最新分析結果
|
|
latest_result = DITAnalysisResult.query.order_by(
|
|
DITAnalysisResult.created_at.desc()
|
|
).first()
|
|
|
|
summary = None
|
|
action_cards = None
|
|
total_alerts = 0
|
|
|
|
if latest_result and latest_result.result_json:
|
|
try:
|
|
result_data = json.loads(latest_result.result_json)
|
|
summary = result_data.get('summary', {})
|
|
action_cards = result_data.get('action_cards', {})
|
|
total_alerts = result_data.get('total_alerts', 0)
|
|
except json.JSONDecodeError:
|
|
pass
|
|
|
|
return render_template('dashboard.html',
|
|
summary=summary,
|
|
action_cards=action_cards,
|
|
total_alerts=total_alerts)
|
|
|
|
|
|
@main_bp.route('/upload')
|
|
def upload():
|
|
"""上傳分析頁面"""
|
|
return render_template('upload.html')
|
|
|
|
|
|
@main_bp.route('/history')
|
|
def history():
|
|
"""歷史記錄頁面"""
|
|
uploads = DITUploadHistory.query.order_by(
|
|
DITUploadHistory.uploaded_at.desc()
|
|
).limit(50).all()
|
|
|
|
return render_template('history.html', uploads=uploads)
|
|
|
|
|
|
@main_bp.route('/result/<int:upload_id>')
|
|
def result(upload_id):
|
|
"""查看特定分析結果"""
|
|
upload = DITUploadHistory.query.get_or_404(upload_id)
|
|
result = DITAnalysisResult.query.filter_by(upload_id=upload_id).first()
|
|
|
|
summary = None
|
|
action_cards = None
|
|
total_alerts = 0
|
|
|
|
if result and result.result_json:
|
|
try:
|
|
result_data = json.loads(result.result_json)
|
|
summary = result_data.get('summary', {})
|
|
action_cards = result_data.get('action_cards', {})
|
|
total_alerts = result_data.get('total_alerts', 0)
|
|
except json.JSONDecodeError:
|
|
pass
|
|
|
|
return render_template('dashboard.html',
|
|
summary=summary,
|
|
action_cards=action_cards,
|
|
total_alerts=total_alerts,
|
|
upload=upload)
|