Authored by 陈峰

逛rss订阅功能开发完成

... ... @@ -247,7 +247,7 @@ const index = (req, res, next) => {
}
// 获取详情内容信息, 异常则跳到错误页面
return infoModel.package(id, isApp).then(detail => {
return infoModel.packageData(id, isApp).then(detail => {
let data = {
guangDetail: true,
guang: {}
... ... @@ -341,7 +341,7 @@ const mini = (req, res, next) => {
}
// 获取详情内容信息, 异常则跳到错误页面
return infoModel.package(id, isApp).then(detail => {
return infoModel.packageData(id, isApp).then(detail => {
let data = {
guangEzine: true,
guang: {}
... ... @@ -410,7 +410,7 @@ const foryoho = (req, res, next) => {
}
// 获取详情内容信息, 异常则跳到错误页面
return infoModel.package(id, isApp).then(detail => {
return infoModel.packageData(id, isApp).then(detail => {
let data = {};
if (detail.code !== 400) {
... ...
/**
* 逛rss订阅
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/13
*/
'use strict';
const mRoot = '../models';
const rssModel = require(`${mRoot}/rss`);
const helpers = global.yoho.helpers;
/**
* [订阅逛最新的资讯]
*/
const index = (req, res, next) => {
let gender = req.query.gender || '1,2,3',
items = [];
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
return rssModel.getRssArticle(gender).then((result) => {
return res.render('rss/index', {
layout: false,
time: '',
items: result
})
});
}
module.exports = {
index
}
\ No newline at end of file
... ...
... ... @@ -14,7 +14,7 @@ const api = global.yoho.API;
* @param {string} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _favoriteBrand = (uid, id, isBrand, opt) => {
const favoriteBrand = (uid, id, isBrand, opt) => {
let param = {
uid: uid,
type: isBrand ? 'brand' : 'product'
... ... @@ -32,5 +32,5 @@ const _favoriteBrand = (uid, id, isBrand, opt) => {
module.exports = {
favoriteBrand: _favoriteBrand
favoriteBrand
};
... ...
... ... @@ -15,7 +15,7 @@ const guangProcess = require(`${global.utils}/guang-process`);
* @param {[int]} id [作者id]
* @return {[object]}
*/
const _getAuthor = (id) => {
const getAuthor = (id) => {
return serviceAPI.get('guang/service/v1/author/getAuthor', {
author_id: id
}, {
... ... @@ -56,7 +56,7 @@ const _category = () => {
* @param {Boolean} useCache [是否使用缓存]
* @return {[array]}
*/
const _getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, useCache) => {
const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, useCache) => {
let param = {
page: page || 1,
uid: uid || 0,
... ... @@ -95,8 +95,8 @@ const _getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit,
* @param {Boolean} isTab [是否为tab切换操作]
* @return {[array]}
*/
const _getPageData = (gender, sortId, uid, udid, page, tag, authorId, isApp, showAuthor, isTab) => {
return _getArticleList(gender, sortId, uid, udid, page, tag, authorId).then(article => {
const getPageData = (gender, sortId, uid, udid, page, tag, authorId, isApp, showAuthor, isTab) => {
return getArticleList(gender, sortId, uid, udid, page, tag, authorId).then(article => {
let result = {};
if (!article.data.list.artList) {
... ... @@ -260,8 +260,8 @@ const getArticle = (param) => {
};
module.exports = {
getAuthor: _getAuthor,
getArticleList: _getArticleList,
getPageData: _getPageData,
getAuthor,
getArticleList,
getPageData,
getArticle
};
... ...
... ... @@ -15,7 +15,7 @@ const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
* @param {Boolean} isApp [标识是否是APP访问]
* @return {[array]}
*/
const _package = (id, isApp) => {
const packageData = (id, isApp) => {
let result = {
getAuthor: {},
getArticle: {},
... ... @@ -110,6 +110,23 @@ const _package = (id, isApp) => {
});
};
/**
* [获取详情信息]
* @param {[int]} id [资讯id]
* @return {[object]}
*/
const intro = (id) => {
let param = {
article_id: id,
client_type: 'h5'
};
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, param, {
cache: true
});
};
module.exports = {
package: _package
packageData,
intro
};
... ...
... ... @@ -13,7 +13,7 @@ const serviceAPI = global.yoho.ServiceAPI;
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _praiseArticle = (udid, id, opt) => {
const praiseArticle = (udid, id, opt) => {
let param = {
article_id: id,
udid: udid
... ... @@ -33,7 +33,7 @@ const _praiseArticle = (udid, id, opt) => {
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const _collectArticle = (uid, id, opt) => {
const collectArticle = (uid, id, opt) => {
let param = {
article_id: id,
uid: uid
... ... @@ -48,6 +48,6 @@ const _collectArticle = (uid, id, opt) => {
module.exports = {
praiseArticle: _praiseArticle,
collectArticle: _collectArticle
praiseArticle,
collectArticle
};
... ...
/**
* 逛rss订阅models
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/13
*/
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const mRoot = '../models';
const indexModel = require(`${mRoot}/index`);
const infoModel = require(`${mRoot}/info`);
const guangProcess = require(`${global.utils}/guang-process`);
const htmlProcess = require(`${global.utils}/html-process`);
const helpers = global.yoho.helpers;
/**
* [获取订阅的资讯文章列表]
* @param {[int]} gender [性别参数(1,3表示男, 2,3表示女, 默认为所有)]
* @return {[array]}
*/
const getRssArticle = (gender) => {
let result = [],
article = {},
articlePromise;
switch (gender) {
case '1,3':
articlePromise = indexModel.getArticleList('1,3', 0, 0, '', 1, null, null, 10, false);
break;
case '2,3':
articlePromise = indexModel.getArticleList('2,3', 0, 0, '', 1, null, null, 10, false);
break;
default:
articlePromise = indexModel.getArticleList('1,2,3', 0, 0, '', 1, null, null, 10, false);
break;
}
return articlePromise.then((article) => {
// 内容列表
if (article.data.list.artList) {
let build = {};
let artListFunc = (i, len, resolve) => {
if (i < len) {
let value = article.data.list.artList[i];
if (typeof value.id !== 'undefined') {
build = guangProcess.formatArticle(value, false, false, true);
build.author.name = build.author.name || '';
return _genIntro(value.id).then((intro) => {
build.intro = intro;
result.push(build);
artListFunc(++i, len, resolve);
});
}
} else {
resolve(result);
}
}
return new Promise((resolve) => {
artListFunc(0, article.data.list.artList.length, resolve);
})
}
});
}
/**
* [构建信息内容]
* @param {[int]} id [资讯id]
* @return {[string]}
*/
const _genIntro = (id) => {
let result = '';
return infoModel.intro(id).then((resData) => {
if (resData.data) {
resData.data.forEach((value) => {
if (value.text) { //文字
result += htmlProcess.removeHtml(htmlProcess.escapeToHtml(value.text.data.text)) + '<br/>';
} else if (value.singleImage) {// 单张图
result += `<img src="${helpers.image(value.singleImage.data[0].src, 640, 640)}"/><br/>`;
} else if (value.smallPic && value.smallPic.data) { // 多张小图
value.smallPic.data.forEach((small) => {
result += `<img src="${helpers.image(small.src, 315, 420)}"/>`;
})
result += '<br/>';
}
})
return result;
}
});
}
module.exports = {
getRssArticle
}
\ No newline at end of file
... ...
... ... @@ -14,6 +14,7 @@ const index = require(cRoot + '/index');
const opt = require(cRoot + '/opt');
const info = require(cRoot + '/info');
const plustar = require(cRoot + '/plustar');
const rss = require(cRoot + '/rss');
const router = express.Router(); // eslint-disable-line
... ... @@ -43,4 +44,6 @@ router.get('/info/foryoho', info.foryoho); // 逛foryoho内容页
router.get('/plustar', plustar.getListData); // 国际优选
router.get('/rss', rss.index); //订阅资讯
module.exports = router;
... ...
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>有货逛</title>
<link>http://yohobuy.com</link>
<generator>http://m.yohobuy.com</generator>
<description>Yoho!Buy有货 | 年轻人潮流购物中心</description>
<atom:link href="http://guang.m.yohobuy.com/rss" rel="self"></atom:link>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/>
<language>zh-cn</language>
<copyright>2015 yoho.inc</copyright>
<lastBuildDate>{{time}}</lastBuildDate>
<ttl>50</ttl>
{{# items}}
<item>
<title><![CDATA[{{title}}]]></title>
<link>
<![CDATA[{{{url}}}&ref=rss]]>
</link>
<description>
<![CDATA[{{{intro}}}]]>
</description>
<pubDate>{{publishTime}}</pubDate>
<author>
<![CDATA[{{author.name}}]]>
</author>
<guid>
<![CDATA[{{{url}}}&ref=rss]]>
</guid>
<source>有货</source>
</item>
{{/items}}
</channel>
</rss>
\ No newline at end of file
... ...
... ... @@ -10,7 +10,7 @@ const helpers = global.yoho.helpers;
* @param {[string]} url [需要转换的url]
* @return {[string]} [description]
*/
const _transHttpsUrl = (url) => {
const transHttpsUrl = (url) => {
return url.replace(/^\/\//g, 'http://');
};
... ... @@ -19,7 +19,7 @@ const _transHttpsUrl = (url) => {
* @param {[string]} url [url地址]
* @return {[strng]}
*/
const _getFilterUrl = (url) => {
const getFilterUrl = (url) => {
url = url.replace('.m.yohobuy.com', global.yoho.config.subDomains.host).replace('www.yohobuy.com', global.yoho.config.siteUrl);
const whiteDomains = ['m.yohobuy.com', 'cdn.yoho.cn/myohobuy'];
... ... @@ -31,7 +31,7 @@ const _getFilterUrl = (url) => {
}
if (url.includes('feature.yoho.cn')) {
url = _transHttpsUrl(url);
url = transHttpsUrl(url);
}
if (url.includes('openby:yohobuy=')) {
let filters = ['openby:yohobuy=', '&', '?'];
... ... @@ -55,7 +55,7 @@ const _getFilterUrl = (url) => {
* @param {[string]} reqQueryString [查询字符串]
* @return {[array | false]}
*/
const _formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryString) => {
const formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQueryString) => {
// 资讯ID不存在,则不显示
if (!articleData.id) {
return false;
... ... @@ -73,7 +73,7 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQuerySt
if (result.url.includes('feature.yoho.cn') ||
result.url.includes('cdn.yoho.cn')) {
result.url = _transHttpsUrl(result.url);
result.url = transHttpsUrl(result.url);
}
// 收藏
... ... @@ -104,7 +104,7 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQuerySt
// 判断是否显示作者信息
if (showAuthor && articleData.author) {
if (!isApp) {
articleData.author.url = _getFilterUrl(articleData.author.url);
articleData.author.url = getFilterUrl(articleData.author.url);
}
// 编辑人员 app跳转url处理 20160601
... ... @@ -148,7 +148,7 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid, reqQuerySt
* @param {[int]} type [类型]
* @return {[type]}
*/
const _getProductIcon = (type) => {
const getProductIcon = (type) => {
const icons = {
1: 'cloth',
3: 'pants',
... ... @@ -218,7 +218,7 @@ const _procProductImg = (images, gender) => {
* @param int gender 性别
* @return array | false
*/
const _formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint, gender) => {
const formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint, gender) => {
// 商品信息有问题,则不显示
if (!productData.product_skn || !productData.goods_list[0]) {
return false;
... ... @@ -306,9 +306,9 @@ const _formatProduct = (productData, showTags, showNew, showSale, width, height,
module.exports = {
formatArticle: _formatArticle,
transHttpsUrl: _transHttpsUrl,
getFilterUrl: _getFilterUrl,
formatProduct: _formatProduct,
getProductIcon: _getProductIcon
formatArticle,
transHttpsUrl,
getFilterUrl,
formatProduct,
getProductIcon
};
... ...
/**
* html字符处理
*/
'use strict';
const _htmlMap = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};
const _EscapeMap = {'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
/**
* [移除html标签]
*/
const removeHtml = (str) => {
return str.replace(/<[^>]+>/g, '');
}
/**
* [html转为转义]
*/
const htmlToEscape = (html) => {
return html.replace(/[<>&"]/g, (e) => {
return _htmlMap[e];
})
}
/**
* [转义符转为html]
*/
const escapeToHtml = (str) => {
return str.replace(/&(lt|gt|nbsp|amp|quot);/g, (match, e) => {
return _EscapeMap[e];
})
}
module.exports = {
removeHtml,
htmlToEscape,
escapeToHtml
}
\ No newline at end of file
... ...
... ... @@ -9,10 +9,10 @@
* @param {[string]} str [验证参数]
* @return {[Boolean]}
*/
const _isNumeric = (str) => {
const isNumeric = (str) => {
return /^\d+(\.\d+)?$/.test(str);
};
module.exports = {
isNumeric: _isNumeric
isNumeric
};
... ...