refactor(app.py): 抽出 /api/test_url + /brand_assets 至 misc_routes Blueprint
All checks were successful
CD Pipeline / deploy (push) Successful in 1m5s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m5s
- 新增 routes/misc_routes.py(40 行,2 routes:POST /api/test_url, GET /brand_assets) - app.py 7012 → 6986(-26 行) - requests 改為模組頂層 import(移除函數內 import 異味) - 註冊位置貼齊 category_bp 後方 Phase 3e route handlers Blueprint 化第二棒,收納雜項小型 routes
This commit is contained in:
34
app.py
34
app.py
@@ -321,6 +321,10 @@ from routes.category_routes import category_bp
|
||||
app.register_blueprint(category_bp)
|
||||
sys_log.info("[Blueprint] ✅ 分類 CRUD Blueprint 已註冊")
|
||||
|
||||
from routes.misc_routes import misc_bp
|
||||
app.register_blueprint(misc_bp)
|
||||
sys_log.info("[Blueprint] ✅ 雜項 Routes Blueprint 已註冊 (/api/test_url, /brand_assets)")
|
||||
|
||||
# ==========================================
|
||||
# 通知模板管理 Blueprint
|
||||
# ==========================================
|
||||
@@ -1022,36 +1026,6 @@ def system_settings_page():
|
||||
"""系統設定與匯入頁面"""
|
||||
return render_template('system_settings.html', system_version=SYSTEM_VERSION)
|
||||
|
||||
@app.route('/api/test_url', methods=['POST'])
|
||||
def test_url():
|
||||
"""API: 測試網址是否有效"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
url = data.get('url')
|
||||
if not url:
|
||||
return jsonify({"status": "error", "message": "網址不能為空"}), 400
|
||||
|
||||
import requests
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||
}
|
||||
# 設定 10 秒超時,避免卡住
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
return jsonify({"status": "success", "message": f"✅ 連結有效 (Status: 200)"})
|
||||
else:
|
||||
return jsonify({"status": "warning", "message": f"⚠️ 連結回應異常 (Status: {response.status_code})"})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "message": f"❌ 連線失敗: {str(e)}"}), 500
|
||||
|
||||
|
||||
@app.route('/brand_assets')
|
||||
def brand_assets():
|
||||
"""顯示品牌資產庫"""
|
||||
return render_template('brand_assets.html')
|
||||
|
||||
@app.route('/edm')
|
||||
def edm_dashboard():
|
||||
"""🚩 新增:MOMO 限時搶購 (EDM) 專屬儀表板"""
|
||||
|
||||
40
routes/misc_routes.py
Normal file
40
routes/misc_routes.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""雜項 Routes Blueprint。從 app.py 抽離(Phase 3e)。
|
||||
|
||||
收納尚未歸類的小型 routes:
|
||||
- POST /api/test_url:測試外部網址連通性
|
||||
- GET /brand_assets:品牌資產庫頁面
|
||||
"""
|
||||
import requests
|
||||
from flask import Blueprint, jsonify, render_template, request
|
||||
|
||||
misc_bp = Blueprint('misc', __name__)
|
||||
|
||||
|
||||
@misc_bp.route('/api/test_url', methods=['POST'])
|
||||
def test_url():
|
||||
"""API: 測試網址是否有效"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
url = data.get('url')
|
||||
if not url:
|
||||
return jsonify({"status": "error", "message": "網址不能為空"}), 400
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
||||
}
|
||||
# 設定 10 秒超時,避免卡住
|
||||
response = requests.get(url, headers=headers, timeout=10)
|
||||
|
||||
if response.status_code == 200:
|
||||
return jsonify({"status": "success", "message": f"✅ 連結有效 (Status: 200)"})
|
||||
else:
|
||||
return jsonify({"status": "warning", "message": f"⚠️ 連結回應異常 (Status: {response.status_code})"})
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"status": "error", "message": f"❌ 連線失敗: {str(e)}"}), 500
|
||||
|
||||
|
||||
@misc_bp.route('/brand_assets')
|
||||
def brand_assets():
|
||||
"""顯示品牌資產庫"""
|
||||
return render_template('brand_assets.html')
|
||||
Reference in New Issue
Block a user