|
|
|
@ -243,29 +243,39 @@ router.post('/savetask/', async (req, res) => {
@@ -243,29 +243,39 @@ router.post('/savetask/', async (req, res) => {
|
|
|
|
|
data.message = '任务编号task_id格式错误,请使用接口/api/gettask/返回数据里的任务id属性值'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//签名检查,如果通过则保存任务数据
|
|
|
|
|
let task = heroUnion.getTaskById(task_id); |
|
|
|
|
if (task) { |
|
|
|
|
let paramsCheck = { |
|
|
|
|
name: name, |
|
|
|
|
task_id: task_id, |
|
|
|
|
task_result: task_result |
|
|
|
|
}; |
|
|
|
|
//检查爬虫是否存在及其状态
|
|
|
|
|
if (!data.message) { |
|
|
|
|
let heroBot = heroUnion.getHeroByName(name); |
|
|
|
|
if (!heroBot || heroBot.status == 'offline') { |
|
|
|
|
data.message = `爬虫${name}不存在或已下线`; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mySign = common.sign(paramsCheck, task.token); |
|
|
|
|
if (mySign.toLowerCase() != sign.toLowerCase()) { |
|
|
|
|
data.message = `签名 ${sign} 不匹配,请确保token正确及签名方法跟文档一致`; |
|
|
|
|
}else { |
|
|
|
|
let saved = heroUnion.saveTaskById(name, task_id, task_result); |
|
|
|
|
if (saved) { |
|
|
|
|
data.code = 1; |
|
|
|
|
data.message = '保存任务数据完成'; |
|
|
|
|
//签名检查,如果通过则保存任务数据
|
|
|
|
|
if (!data.message) { |
|
|
|
|
let task = heroUnion.getTaskById(task_id); |
|
|
|
|
if (task) { |
|
|
|
|
let paramsCheck = { |
|
|
|
|
name: name, |
|
|
|
|
task_id: task_id, |
|
|
|
|
task_result: task_result |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let mySign = common.sign(paramsCheck, task.token); |
|
|
|
|
if (mySign.toLowerCase() != sign.toLowerCase()) { |
|
|
|
|
data.message = `签名 ${sign} 不匹配,请确保token正确及签名方法跟文档一致`; |
|
|
|
|
}else { |
|
|
|
|
data.message = `任务${task_id}已经完成,请勿重复提交数据`; |
|
|
|
|
let saved = heroUnion.saveTaskById(name, task_id, task_result); |
|
|
|
|
if (saved) { |
|
|
|
|
data.code = 1; |
|
|
|
|
data.message = '保存任务数据完成'; |
|
|
|
|
}else { |
|
|
|
|
data.message = `任务${task_id}已经完成,请勿重复提交数据`; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
data.message = `任务${task_id}不存在`; |
|
|
|
|
} |
|
|
|
|
}else { |
|
|
|
|
data.message = `任务${task_id}不存在`; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return res.status(200).json(data); |
|
|
|
|