about.js 1.16 KB
/**
 * about model
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2017/11/20
 */

const redis = global.yoho.redis;
const _ = require('lodash');
const logger = global.yoho.logger;

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    link() {
        return redis.all([
            ['get', 'friend:text:links'],
            ['get', 'friend:img:links']
        ]).then(redisData => {
            let textLinks = [],
                imgLinks = [];

            try {
                textLinks = JSON.parse(redisData[0] || '[]');
            } catch (e) {
                logger.error(`friend text links parse error : ${JSON.stringify(e)}`);
            }

            try {
                imgLinks = JSON.parse(redisData[1] || '[]');
            } catch (e) {
                logger.error(`friend img links parse error : ${JSON.stringify(e)}`);
            }

            return {
                textLinks: _.sortBy(textLinks, o => {
                    return -o.sort;
                }),
                imgLinks: _.sortBy(imgLinks, o => {
                    return -o.sort;
                })
            };
        });
    }
};