Authored by 郝肖肖

'潮流首页连接推百度资源位'

... ... @@ -55,6 +55,12 @@ app.get('/goodsUrl', cseo.goodsUrl);
// 逛详情-百度链接提交
app.get('/guangUrl', cseo.guangUrl);
// 潮流首页-百度链接提交
app.get('/yohoBoysUrl', cseo.yohoBoysUrl);
// 潮流首页-百度链接提交
app.get('/yohoGirlsUrl', cseo.yohoGirlsUrl);
app.listen(config.port, function() {
logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
});
... ...
... ... @@ -46,6 +46,18 @@ const guangUrl = (req, res) => {
});
};
const yohoBoysUrl = (req, res) => {
return req.ctx(BaiduLinkSubmit).yohoBoys(req.query).then(result => {
return res.json(result);
});
};
const yohoGirlsUrl = (req, res) => {
return req.ctx(BaiduLinkSubmit).yohoGirls(req.query).then(result => {
return res.json(result);
});
};
const setTask = (req, res) => {
return req.ctx(SeoIndexModel).setTask(req.query).then(result => {
return res.json(result);
... ... @@ -86,6 +98,8 @@ module.exports = {
siteMapXml,
goodsUrl,
guangUrl,
yohoBoysUrl,
yohoGirlsUrl,
setTask,
delTask,
demoXsd,
... ...
... ... @@ -24,11 +24,11 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
let siteType = '';
if (type === 'mip') {
siteType = 'MIP';
siteType = 'MIP: ';
} else if (site.indexOf('www.yohobuy') > -1) {
siteType = 'PC';
siteType = 'PC: ';
} else if (site.indexOf('m.yohobuy') > -1) {
siteType = 'WAP';
siteType = 'WAP: ';
}
if (!site) {
... ... @@ -41,7 +41,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
return rp({
method: 'POST',
uri: `${senUrl}`,
uri: senUrl,
qs: {
token: '0lSAO4ZxEKsYopMG',
site: site,
... ... @@ -58,7 +58,7 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
return Object.assign({
code: 200,
message: `${siteType} 当天剩余${result.remain || result.remain_mip}条可推送到百度资源平台,本次成功推送${result.success || result.success_mip}条。` // eslint-disable-line
message: `${siteType}当天剩余${result.remain || result.remain_mip}条可推送到百度资源平台,本次成功推送${result.success || result.success_mip}条。` // eslint-disable-line
}, result);
}).catch(e => {
console.log(e.message);
... ... @@ -130,7 +130,6 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
// 提交逛详情URL
guangUrl() {
let that = this;
return co(function* () {
... ... @@ -194,6 +193,140 @@ class BaiduLinkSubmit extends global.yoho.BaseModel {
})();
}
_getYohoNewsLink(url) {
return rp({
method: 'GET',
uri: url,
qs: {},
qsStringifyOptions: {
encode: false
},
timeout: 8 * 1000,
json: true,
gzip: true
}).then(result => {
return {
code: 200,
data: result,
message: 'success'
};
}).catch(e => {
console.log(`_getYohoNewsLink: err: ${e.message}`);
return {code: e.statusCode || 400, data: [], message: e.message};
});
}
// 潮流boys
yohoBoys() {
let that = this;
return co(function* () {
let initData = {
pc: [],
pcUrl: 'http://www.yohoboys.com',
};
let rdata = _.get(yield that._getYohoNewsLink(
`${initData.pcUrl}/channel/ajax/tab?channel=100&page=1`
), 'data', []);
let tlinks = [];
let links = _.map(rdata, item => {
return _.get(item, 'content.url', '').replace(/http:|https:/, '');
});
let artice = {
total: links.length,
notAlready: 0
};
links = _.difference(links, yield redis.hmgetAsync('global:yoho:seo:linksubmit:newsBoys', links));// 去除已经推送的
artice.notAlready = links.length;
if (artice.notAlready <= 0) {
let message = `获取${artice.total}条记录,未推送0条,成功推送0条。`;
return {code: 201, data: [], message: message};
}
_.each(links, val => {
if (_.isEmpty(val)) {
return true;
}
tlinks.push(val, val);// mset做准备
initData.pc.push(`http:${val}`);
});
rdata = yield that.sendUrl(initData.pc, initData.pcUrl);
if (_.get(rdata, 'code', 400) !== 200) {
return rdata;
}
yield redis.hmsetAsync('global:yoho:seo:linksubmit:newsBoys', tlinks);
links = [];
tlinks = [];
return rdata;
})();
}
// 潮流girls
yohoGirls() {
let that = this;
return co(function* () {
let initData = {
pc: [],
pcUrl: 'http://www.yohogirls.com',
};
let rdata = _.get(yield that._getYohoNewsLink(
`${initData.pcUrl}/channel/ajax/getRecoms?channel=1&page=1`
), 'data', []);
let tlinks = [];
let links = _.map(rdata, item => {
return _.get(item, 'link', '').replace(/http:|https:/, '');
});
let artice = {
total: links.length,
notAlready: 0
};
links = _.difference(links, yield redis.hmgetAsync('global:yoho:seo:linksubmit:newsGirls', links));// 去除已经推送的
artice.notAlready = links.length;
if (artice.notAlready <= 0) {
let message = `获取${artice.total}条记录,未推送0条,成功推送0条。`;
return {code: 201, data: [], message: message};
}
_.each(links, val => {
if (_.isEmpty(val)) {
return true;
}
tlinks.push(val, val);// mset做准备
initData.pc.push(`http:${val}`);
});
rdata = yield that.sendUrl(initData.pc, initData.pcUrl);
if (_.get(rdata, 'code', 400) !== 200) {
return rdata;
}
yield redis.hmsetAsync('global:yoho:seo:linksubmit:newsGirls', tlinks);
links = [];
tlinks = [];
return rdata;
})();
}
}
module.exports = BaiduLinkSubmit;
... ...
... ... @@ -69,7 +69,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
_.each(item.goods_list.slice(0, 5), goods => {
contentUrl = goods.images_url || contentUrl;
if (contentUrl === '') {
if (_.isEmpty(contentUrl)) {
return true;
}
... ...