star.js
2.16 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* 新潮教室
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/05/30
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const resourcesProcess = require(`${utils}/resources-process`);
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const sign = require(`${library}/sign`);
const logger = require(`${library}/logger`);
const camelCase = require(`${library}/camel-case`);
const _ = require('lodash');
const serviceAPI = new ServiceAPI();
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const getResources = (page) => {
const contentCode = {
index: '8adc27fcf5676f356602889afcfd2a8e',
special: '89cc20483ee2cbc8a716dcfe2b6c7603'
};
return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({
content_code: contentCode[page]
})).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('SALE 页面资源位返回 code 不是 200');
return [];
}
});
};
/**
* 星搭配文章列表数据处理
*/
const processCollocationData = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (data) => {
if (data.isFavor === 'N') {
data.isCollected = false;
} else {
data.isCollected = true;
}
formatData.push(data);
});
return formatData;
}
/**
* 星潮首页
*/
exports.getIndexData = () => {
return getResources('index');
};
/**
* 星专题
*/
exports.getSpecialData = () => {
return getResources('special');
};
/**
* 星搭配
*/
exports.getCollocationListData = (params, uid) => {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', sign.apiSign(Object.assign({
limit: '20',
uid: uid
}, params))).then((result) => {
if (result && result.code === 200) {
return processCollocationData(result.data.list.artList);
} else {
logger.error('获取星搭配文章列表返回 code 不是 200');
return [];
}
});
};