调整json格式存储link信息
This commit is contained in:
@@ -149,34 +149,53 @@ def api_create_task():
|
|||||||
|
|
||||||
@message_push_bp.route('/api/tasks/<task_id>', methods=['PUT'])
|
@message_push_bp.route('/api/tasks/<task_id>', methods=['PUT'])
|
||||||
@login_required
|
@login_required
|
||||||
def api_update_task(task_id):
|
def update_task(task_id):
|
||||||
"""更新任务API"""
|
"""更新任务"""
|
||||||
try:
|
try:
|
||||||
data = request.json
|
data = request.get_json()
|
||||||
if not data:
|
if not data:
|
||||||
return jsonify({"success": False, "error": "无效的请求数据"}), 400
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': '无效的请求数据'
|
||||||
|
})
|
||||||
|
|
||||||
# 获取任务
|
# 获取任务信息
|
||||||
db = current_app.dashboard_server.task_db
|
db = current_app.dashboard_server.task_db
|
||||||
task = db.get_task(task_id)
|
task = db.get_task(task_id)
|
||||||
if not task:
|
if not task:
|
||||||
return jsonify({"success": False, "error": "任务不存在"}), 404
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': '任务不存在'
|
||||||
|
})
|
||||||
|
|
||||||
|
# 检查任务状态
|
||||||
|
if task['status'] not in ['draft', 'paused']:
|
||||||
|
return jsonify({
|
||||||
|
'success': False,
|
||||||
|
'message': '只能编辑草稿或已暂停状态的任务'
|
||||||
|
})
|
||||||
|
|
||||||
# 更新任务
|
# 更新任务
|
||||||
if not db.update_task(task_id, data):
|
db.update_task(task_id, data)
|
||||||
return jsonify({"success": False, "error": "更新任务失败"}), 500
|
|
||||||
|
# 记录操作日志
|
||||||
|
db.log_task_action({
|
||||||
|
'log_id': f"log_{datetime.now().strftime('%Y%m%d%H%M%S')}",
|
||||||
|
'task_id': task_id,
|
||||||
|
'action': 'update',
|
||||||
|
'user_id': session.get('user_id'),
|
||||||
|
'changes': data
|
||||||
|
})
|
||||||
|
|
||||||
# 获取更新后的任务
|
|
||||||
updated_task = db.get_task(task_id)
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
'success': True,
|
||||||
"data": {
|
'message': '更新成功'
|
||||||
"task": updated_task
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"更新任务失败: {e}")
|
return jsonify({
|
||||||
return jsonify({"success": False, "error": str(e)}), 500
|
'success': False,
|
||||||
|
'message': f'更新失败: {str(e)}'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@message_push_bp.route('/api/tasks/<task_id>', methods=['DELETE'])
|
@message_push_bp.route('/api/tasks/<task_id>', methods=['DELETE'])
|
||||||
|
|||||||
@@ -564,15 +564,23 @@ new Vue({
|
|||||||
formData.content_link = JSON.stringify(formData.content_link);
|
formData.content_link = JSON.stringify(formData.content_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post('/message_push/api/tasks', formData);
|
let response;
|
||||||
|
if (formData.task_id) {
|
||||||
|
// 更新任务
|
||||||
|
response = await axios.put(`/message_push/api/tasks/${formData.task_id}`, formData);
|
||||||
|
} else {
|
||||||
|
// 创建新任务
|
||||||
|
response = await axios.post('/message_push/api/tasks', formData);
|
||||||
|
}
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
this.$message.success('保存任务成功');
|
this.$message.success(formData.task_id ? '更新任务成功' : '创建任务成功');
|
||||||
this.taskDialogVisible = false;
|
this.taskDialogVisible = false;
|
||||||
this.loadTasks();
|
this.loadTasks();
|
||||||
this.loadStatistics();
|
this.loadStatistics();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$message.error('保存任务失败');
|
this.$message.error(formData.task_id ? '更新任务失败' : '创建任务失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -844,7 +852,18 @@ new Vue({
|
|||||||
return statusMap[status] || '';
|
return statusMap[status] || '';
|
||||||
},
|
},
|
||||||
formatDateTime(datetime) {
|
formatDateTime(datetime) {
|
||||||
return new Date(datetime).toLocaleString();
|
if (!datetime) return '';
|
||||||
|
// 创建日期对象并转换为本地时间
|
||||||
|
const date = new Date(datetime);
|
||||||
|
// 使用 padStart 确保月份和日期是两位数
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||||
|
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
},
|
},
|
||||||
refreshTasks() {
|
refreshTasks() {
|
||||||
this.loadTasks();
|
this.loadTasks();
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ class ToolMixin(WechatAPIClientBase):
|
|||||||
else:
|
else:
|
||||||
self.error_handler(json_resp)
|
self.error_handler(json_resp)
|
||||||
|
|
||||||
async def download_attach_xml(self, xml_str: str) -> str:
|
async def download_attach_xml(self, xml_str: str) -> str:
|
||||||
#读取消息信息,进行处理
|
# 读取消息信息,进行处理
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
root = ET.fromstring(xml_str)
|
root = ET.fromstring(xml_str)
|
||||||
appmsg = root.find("appmsg")
|
appmsg = root.find("appmsg")
|
||||||
@@ -146,6 +146,22 @@ class ToolMixin(WechatAPIClientBase):
|
|||||||
else:
|
else:
|
||||||
self.error_handler(json_resp)
|
self.error_handler(json_resp)
|
||||||
|
|
||||||
|
async def friend_circle_upload(self, base64: str) -> str:
|
||||||
|
# / FriendCircle / Upload
|
||||||
|
|
||||||
|
if not self.wxid:
|
||||||
|
raise UserLoggedOut("请先登录")
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession() as session:
|
||||||
|
json_param = {"Wxid": self.wxid, "Base64": base64}
|
||||||
|
response = await session.post(f'http://{self.ip}:{self.port}/api/FriendCircle/Upload', json=json_param)
|
||||||
|
json_resp = await response.json()
|
||||||
|
|
||||||
|
if json_resp.get("Success"):
|
||||||
|
return json_resp.get("Data").get("ThumbUrls")[0].get("Url")
|
||||||
|
else:
|
||||||
|
self.error_handler(json_resp)
|
||||||
|
|
||||||
async def set_step(self, count: int) -> bool:
|
async def set_step(self, count: int) -> bool:
|
||||||
"""设置步数。
|
"""设置步数。
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user