hot-service.js 711 Bytes
const HotModel = require('./hot-api');

const indexUrl = (type, p) => `/sitemap_${type}/hot_${p}.xml`;

const tplUrl = id => `/hot/${id}.html`;

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

    this.hotModel = new HotModel(ctx);
  }

  async getIndex(type) {
    try {
      const pages = await this.hotModel.getIndex();

      return (pages || []).map((k, i) => indexUrl(type, i + 1));
    } catch (e) {
      console.error(e);
      return [];
    }
  }

  async getUrls(page) {
    try {
      const ids = await this.hotModel.getIds(page);

      return (ids || []).map(id => tplUrl(id));
    } catch (e) {
      console.error(e);
      return [];
    }
  }
};