Files
ewoooc/routes/misc_routes.py
OoO 87a83aed64
All checks were successful
CD Pipeline / deploy (push) Successful in 1m3s
統一系統工具頁新版殼層
2026-05-14 18:02:03 +08:00

41 lines
1.4 KiB
Python
Raw Permalink 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', active_page='brand_assets')