Blame view

apps/common/controllers/recent-view.js 1.29 KB
htoooth authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * 最近浏览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;
16
    let browserSkn = req.cookies._browseskn;
htoooth authored
17 18

    // 拆解skn
19
    let skn = browserSkn ? decodeURIComponent(browserSkn).replace(/\-(\d)+(\,){0,1}/g, ',') : '';
htoooth authored
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

    // 去除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(','); // 去重+截取
        rvModel.index(skn, limit).then(data => {
            res.jsonp(data);
        }).catch(next);
    }
38
};
htoooth authored
39
40 41 42 43 44 45
/** 为你优选**/
const getRecommend = (req, res, next) => {
    let uid = req.user.uid;
    let udid = req.user.uid + req.yoho.udid;

    rvModel.recommend({
46
        yh_channel: req.yoho.channelNum,
47 48 49 50 51 52 53
        uid: uid,
        udid: udid,
        rec_pos: req.body.recPos,
        limit: req.body.limit
    }).then(d => {
        res.json(d);
    }).catch(next);
htoooth authored
54 55 56
};

module.exports = {
57 58
    index,
    getRecommend
htoooth authored
59
};