recent-view.js
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* 最近浏览controller
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/10/11
*/
'use strict';
const rvModel = require('../models/recent-view');
const _ = require('lodash');
const index = (req, res, next) => {
let limit = req.query.limit;
let browserSkn = req.cookies._browseskn;
// 拆解skn
let skn = browserSkn ? decodeURIComponent(browserSkn).replace(/\-(\d)+(\,){0,1}/g, ',') : '';
// 去除skn字符串的最后一个多余的,
if (skn && skn.lastIndexOf(',') === skn.length - 1) {
skn = skn.slice(0, -1);
}
if (!skn) {
res.jsonp({
code: 200,
data: [],
message: 'User info'
});
} else {
skn = _.slice(_.uniq(skn.split(',')), 0, limit).join(','); // 去重+截取
req.ctx(rvModel).index(skn, limit).then(data => {
res.jsonp(data);
}).catch(next);
}
};
/** 为你优选**/
const getRecommend = (req, res, next) => {
let uid = req.user.uid;
let udid = req.user.uid + req.yoho.udid;
req.ctx(rvModel).recommend({
yh_channel: req.yoho.channelNum,
uid: uid,
udid: udid,
rec_pos: req.body.recPos,
limit: req.body.limit
}).then(d => {
res.json(d);
}).catch(next);
};
module.exports = {
index,
getRecommend
};