加入部分消息通知入口,同步前端管理
This commit is contained in:
@@ -966,7 +966,64 @@ def admin_panel():
|
||||
except Exception:
|
||||
codes = []
|
||||
|
||||
return render_template('admin.html', users=users, invite_codes=codes, user=session.get('user'))
|
||||
# 获取系统配置
|
||||
try:
|
||||
resp = api_request('GET', f'{AUTH_BASE_URL}/admin/config')
|
||||
config = resp.json().get('data', {}) if resp.status_code == 200 else {}
|
||||
except Exception:
|
||||
config = {}
|
||||
|
||||
return render_template('admin.html', users=users, invite_codes=codes, config=config, user=session.get('user'))
|
||||
|
||||
|
||||
@app.route('/admin/config/save', methods=['POST'])
|
||||
@admin_required
|
||||
def save_config():
|
||||
"""保存系统配置"""
|
||||
try:
|
||||
config_data = {
|
||||
'webhook_url': request.form.get('webhook_url', '').strip(),
|
||||
'daily_report_hour': request.form.get('daily_report_hour', '23').strip(),
|
||||
'daily_report_minute': request.form.get('daily_report_minute', '30').strip(),
|
||||
}
|
||||
resp = api_request('PUT', f'{AUTH_BASE_URL}/admin/config', json=config_data)
|
||||
data = resp.json()
|
||||
if resp.status_code == 200 and data.get('success'):
|
||||
flash('配置已保存,调度器将自动重新加载', 'success')
|
||||
else:
|
||||
flash(data.get('message', '保存失败'), 'danger')
|
||||
except Exception as e:
|
||||
flash(f'连接错误: {str(e)}', 'danger')
|
||||
return redirect(url_for('admin_panel'))
|
||||
|
||||
|
||||
@app.route('/admin/webhook/test', methods=['POST'])
|
||||
@admin_required
|
||||
def test_webhook():
|
||||
"""测试 Webhook 推送"""
|
||||
try:
|
||||
webhook_url = request.form.get('webhook_url', '').strip()
|
||||
if not webhook_url:
|
||||
return jsonify({'success': False, 'message': 'Webhook 地址为空'}), 400
|
||||
|
||||
import httpx
|
||||
# 飞书格式
|
||||
if 'open.feishu.cn' in webhook_url:
|
||||
payload = {"msg_type": "text", "content": {"text": "🔔 微博超话签到系统 Webhook 测试\n如果你看到这条消息,说明推送配置正确。"}}
|
||||
elif 'qyapi.weixin.qq.com' in webhook_url:
|
||||
payload = {"msgtype": "text", "text": {"content": "🔔 微博超话签到系统 Webhook 测试\n如果你看到这条消息,说明推送配置正确。"}}
|
||||
elif 'oapi.dingtalk.com' in webhook_url:
|
||||
payload = {"msgtype": "text", "text": {"content": "🔔 微博超话签到系统 Webhook 测试\n如果你看到这条消息,说明推送配置正确。"}}
|
||||
else:
|
||||
payload = {"text": "🔔 微博超话签到系统 Webhook 测试"}
|
||||
|
||||
resp = httpx.post(webhook_url, json=payload, timeout=10)
|
||||
if resp.status_code == 200:
|
||||
return jsonify({'success': True, 'message': '测试消息已发送'})
|
||||
else:
|
||||
return jsonify({'success': False, 'message': f'推送失败: HTTP {resp.status_code}'}), 400
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/admin/invite-codes/create', methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user