Authored by 郝肖肖

'mars实时推送百度资源位和mip'

... ... @@ -88,6 +88,9 @@ app.get('/marsAll', cseo.marsAll);
// 潮流全站推送一遍mip和百度资源位
app.get('/yohoBoysAll', cseo.yohoBoysAll);
// mars实时推送百度资源位连接和百度资源位mip
app.get('/marsReal', cseo.marsReal);
app.listen(config.port, function() {
logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
});
... ...
... ... @@ -129,6 +129,12 @@ const marsAll = (req, res) => {
});
};
const marsReal = (req, res) => {
return req.ctx(BaiduLinkSubmit).marsReal(req.query).then(result => {
return res.json(result);
});
};
module.exports = {
index,
autoGoodsXml,
... ... @@ -143,6 +149,7 @@ module.exports = {
yohoGirlsAll,
yohoBoysAll,
marsAll,
marsReal,
demoXsd,
demoXml
};
... ...
... ... @@ -189,7 +189,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
})();
}
_getYohoNewsLink(url) {
_getRp(url, json) {
return rp({
method: 'GET',
uri: url,
... ... @@ -198,7 +198,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
encode: false
},
timeout: 8 * 1000,
json: true,
json: json || true,
gzip: true
}).then(result => {
return {
... ... @@ -207,7 +207,6 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
message: 'success'
};
}).catch(e => {
console.log(`_getYohoNewsLink: err: ${e.message}`);
return {code: e.statusCode || 400, data: [], message: e.message};
});
}
... ... @@ -224,8 +223,9 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
mipUrl: 'http://www.yohoboys.com'
};
let rdata = _.get(yield that._getYohoNewsLink(
`${initData.pcUrl}/channel/ajax/tab?channel=100&page=1`
let rdata = _.get(yield that._getRp(
`${initData.pcUrl}/channel/ajax/tab?channel=100&page=1`,
true
), 'data', []);
let tlinks = [];
let links = _.map(rdata, item => {
... ... @@ -294,8 +294,9 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
mipUrl: 'http://www.yohogirls.com'
};
let rdata = _.get(yield that._getYohoNewsLink(
`${initData.pcUrl}/channel/ajax/getRecoms?channel=1&page=1`
let rdata = _.get(yield that._getRp(
`${initData.pcUrl}/channel/ajax/getRecoms?channel=1&page=1`,
true
), 'data', []);
let tlinks = [];
let links = _.map(rdata, item => {
... ... @@ -447,6 +448,54 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
})();
}
// 实时推送mars
marsReal() {
let marsIds = [];
let errId = 0;
let initData = {
mip: [],
pc: [],
pcUrl: 'http://www.yohomars.com',
mipUrl: 'http://www.yohomars.com'
};
// init global:yoho:seo:linksubmit:marsReal 11972
return redis.getAsync('global:yoho:seo:linksubmit:marsReal').then(marsReal => {
marsReal = parseInt(marsReal, 10);
for (let i = 0; i < 5; i++) {
marsIds.push(marsReal);
marsReal = (marsReal + 2);
}
return Promise.each(marsIds, (id) => this._getRp(
`http://www.yohomars.com/share/store/${id}`,
false
).then(result => {
if (result.code === 200) {
initData.pc.push(`http://www.yohomars.com/share/store/${id}`);
initData.mip.push(`http://www.yohomars.com/store/share/mip/${id}.html`);
} else if (!errId && result.code === 404) {
errId = id;
}
return result;
})
);
}).then(() => {
errId = errId ? errId : (marsIds.pop() + 2);
// 记录最后一次404或者上次推送成功连接id
return redis.setAsync('global:yoho:seo:linksubmit:marsReal', errId);
}).then(() => {
return Promise.all([
this.sendUrl(initData.pc, initData.pcUrl),
this.sendUrl(initData.mip, initData.mipUrl, 'mip')
]);
});
}
}
module.exports = BaiduLinkSubmit;
... ...