hot-service.js
822 Bytes
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
const HotModel = require('./hot-api');
const indexUrl = (type, p) => `/sitemap_${type}/hot_${p}.xml`;
const pcTplUrl = id => `/hot/${id}.html`;
const h5TplUrl = id => `/mip/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, type) {
const tplUrl = type === 'pc' ? pcTplUrl : h5TplUrl;
try {
const ids = await this.hotModel.getIds(page);
return (ids || []).map(id => tplUrl(id));
} catch (e) {
console.error(e);
return [];
}
}
};