调整通讯录管理
This commit is contained in:
@@ -88,15 +88,15 @@ class DashboardServer:
|
||||
@app.route('/static/<path:filename>')
|
||||
def serve_static(filename):
|
||||
return send_from_directory(static_folder, filename)
|
||||
|
||||
|
||||
# 配置静态文件访问
|
||||
# 获取项目根目录下的static/images目录
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
images_dir = os.path.join(project_root, "static", "images")
|
||||
|
||||
|
||||
# 确保目录存在
|
||||
os.makedirs(images_dir, exist_ok=True)
|
||||
|
||||
|
||||
@app.route('/static/images/<path:filename>')
|
||||
def serve_images(filename):
|
||||
return send_from_directory(images_dir, filename)
|
||||
@@ -175,12 +175,13 @@ class DashboardServer:
|
||||
@login_required
|
||||
def wx_logs():
|
||||
return render_template('wx_logs.html')
|
||||
|
||||
# 在_create_app方法中添加新的路由
|
||||
@app.route('/robot_management')
|
||||
@login_required
|
||||
def robot_management():
|
||||
return render_template('robot_management.html')
|
||||
|
||||
|
||||
# 添加通讯录管理页面路由
|
||||
@app.route('/contacts')
|
||||
@login_required
|
||||
@@ -204,34 +205,16 @@ class DashboardServer:
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取所有联系人信息失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
@app.route('/api/contacts/groups', methods=['GET'])
|
||||
@login_required
|
||||
def api_contacts_groups():
|
||||
"""获取群组联系人信息API"""
|
||||
try:
|
||||
contacts = self.contact_manager.get_contacts()
|
||||
group_contacts = {wxid: name for wxid, name in contacts.items() if '@@' in wxid or '@chatroom' in wxid}
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
"groups": group_contacts
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取群组联系人信息失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/contacts/personal', methods=['GET'])
|
||||
@login_required
|
||||
def api_contacts_personal():
|
||||
"""获取个人联系人信息API"""
|
||||
try:
|
||||
contacts = self.contact_manager.get_contacts()
|
||||
personal_contacts = {wxid: name for wxid, name in contacts.items()
|
||||
if '@@' not in wxid and '@chatroom' not in wxid}
|
||||
|
||||
personal_contacts = {wxid: name for wxid, name in contacts.items()
|
||||
if '@@' not in wxid and '@chatroom' not in wxid}
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -241,7 +224,7 @@ class DashboardServer:
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取个人联系人信息失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/contacts/statistics', methods=['GET'])
|
||||
@login_required
|
||||
def api_contacts_statistics():
|
||||
@@ -249,7 +232,7 @@ class DashboardServer:
|
||||
try:
|
||||
# 使用新的联系人分类方法获取统计信息
|
||||
total, groups, personal, public, official = self.contact_manager.get_contact_statistics()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -271,7 +254,7 @@ class DashboardServer:
|
||||
"""获取群组联系人信息API"""
|
||||
try:
|
||||
group_contacts = self.contact_manager.get_group_contacts()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -281,7 +264,7 @@ class DashboardServer:
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取群组联系人信息失败: {e}")
|
||||
return jsonify({"success": False, "error": str(e)}), 500
|
||||
|
||||
|
||||
# 修改个人联系人API,使用新的分类方法
|
||||
@app.route('/api/contacts/personal', methods=['GET'])
|
||||
@login_required
|
||||
@@ -289,7 +272,7 @@ class DashboardServer:
|
||||
"""获取个人联系人信息API"""
|
||||
try:
|
||||
personal_contacts = self.contact_manager.get_personal_contacts()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -307,7 +290,7 @@ class DashboardServer:
|
||||
"""获取公众号联系人信息API"""
|
||||
try:
|
||||
official_accounts = self.contact_manager.get_official_accounts()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -325,7 +308,7 @@ class DashboardServer:
|
||||
"""获取公共好友信息API"""
|
||||
try:
|
||||
public_contacts = self.contact_manager.get_public_contacts()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"data": {
|
||||
@@ -728,7 +711,6 @@ class DashboardServer:
|
||||
except Exception as e:
|
||||
self.logger.error(f"获取群组列表失败: {e}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/wx_logs')
|
||||
@login_required
|
||||
@@ -736,14 +718,14 @@ class DashboardServer:
|
||||
try:
|
||||
log_type = request.args.get('type', 'info') # 默认显示info日志
|
||||
lines = request.args.get('lines', 100, type=int) # 默认显示最后100行
|
||||
|
||||
|
||||
# 确定日志文件路径
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if log_type == 'error':
|
||||
log_file = os.path.join(base_dir, 'wx_error.log')
|
||||
else:
|
||||
log_file = os.path.join(base_dir, 'wx_info.log')
|
||||
|
||||
|
||||
# 读取日志文件
|
||||
log_content = []
|
||||
if os.path.exists(log_file):
|
||||
@@ -751,9 +733,9 @@ class DashboardServer:
|
||||
with open(log_file, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
# 使用deque获取最后N行
|
||||
log_content = list(deque(f, lines))
|
||||
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"success": True,
|
||||
"data": {
|
||||
"log_type": log_type,
|
||||
"log_file": log_file,
|
||||
|
||||
Reference in New Issue
Block a user