site-map-service.js 1.45 KB
/**
 * map
 * @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
 * @date: 2017/10/24
 */
'use strict';

const _ = require('lodash');
const path = require('path');
const readFileAsync = Promise.promisify(require('fs').readFile);

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

    guangList() {
        let filePath = path.resolve(__dirname, './guang-sitemap-ids.txt');

        // 异步读取
        return readFileAsync(filePath, 'utf-8').then(data => {
            return data.toString().split(/\r?\n/ig);
        }).catch(err => {
            console.log(err);
            return [];
        });
    }

    newsList(page, lres) {
        return this.get({
            url: 'yohonow/api/page/getPolymerizationList',
            data: {
                type: 'wechat',
                limit: 100,
                id: 'yohobuy4008899646,yohogroup,YOHO_GIRL,mars-app',
                page: page
            },
            param: {
                cache: true
            },
            api: global.yoho.YohoNowApi
        }).then(rdata => {
            let artList = _.get(rdata, 'data.content', []);

            if (artList.length <= 0) {
                return lres;
            }

            lres = lres.concat(_.map(artList, (art) => {
                return `${art.id}_${art.cid}`;
            }));

            rdata = [];
            artList = [];

            return this.newsList(++page, lres);
        });
    }

};