Files
ewoooc/routes/misc_routes.py
OoO e6768408e1
All checks were successful
CD Pipeline / deploy (push) Successful in 1m5s
refactor(app.py): 抽出 /api/test_url + /brand_assets 至 misc_routes Blueprint
- 新增 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
2026-04-28 21:10:01 +08:00

41 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""雜項 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')