add mi youpin crowdfunding; fix mi crowdfunding
This commit is contained in:
+5
-3
@@ -1550,9 +1550,11 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
|
||||
|
||||
### 小米
|
||||
|
||||
<route name="众筹" author="DIYgod" example="/mi/crowdfunding" path="/mi/crowdfunding"/>
|
||||
<route name="小米众筹" author="DIYgod" example="/mi/crowdfunding" path="/mi/crowdfunding"/>
|
||||
|
||||
<route name="有品-每日上新" author="xyqfer" example="/mi/youpin/new" path="/mi/youpin/new"/>
|
||||
<route name="小米有品众筹" author="DIYgod" example="/mi/youpin/crowdfunding" path="/mi/youpin/crowdfunding"/>
|
||||
|
||||
<route name="小米有品每日上新" author="xyqfer" example="/mi/youpin/new" path="/mi/youpin/new"/>
|
||||
|
||||
## 网络小说
|
||||
|
||||
@@ -1880,7 +1882,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
|
||||
|
||||
### 后续
|
||||
|
||||
<route name="后续" author="fengkx" example="/houxu/events/38" path="/houxu/:type/:id" :paramsDesc="['类型', 'ID']"/>
|
||||
<route name="事件" author="fengkx" example="/houxu/events/38" path="/houxu/:type/:id" :paramsDesc="['类型', 'ID']"/>
|
||||
|
||||
### 老司机
|
||||
|
||||
|
||||
@@ -374,6 +374,7 @@ router.get('/hexo/next/:url', require('./routes/hexo/next'));
|
||||
|
||||
// 小米
|
||||
router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding'));
|
||||
router.get('/mi/youpin/crowdfunding', require('./routes/mi/youpin/crowdfunding'));
|
||||
router.get('/mi/youpin/new', require('./routes/mi/youpin/new'));
|
||||
|
||||
// Keep
|
||||
|
||||
+19
-38
@@ -1,48 +1,29 @@
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://home.mi.com/app/shop/content?id=s8939d03918810635';
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: baseUrl,
|
||||
method: 'post',
|
||||
url: 'http://api.m.mi.com/v1/microwd/home',
|
||||
headers: {
|
||||
'Mishop-Client-Id': '180100031055',
|
||||
'User-Agent': 'MiShop/4.3.68 (iPhone; iOS 12.0.1; Scale/3.00)',
|
||||
'IOS-App-Version': '4.3.68',
|
||||
'IOS-Version': 'system=12.0.1&device=iPhone10,3',
|
||||
},
|
||||
});
|
||||
let list = [];
|
||||
response.data.data.list.forEach((item) => {
|
||||
list = list.concat(item.items);
|
||||
});
|
||||
|
||||
const data = response.data.match(/,gid:(\d*),src:"(.+?)"/g).map((item) => ({
|
||||
gid: item.match(/gid:(\d*)/)[1],
|
||||
img: item.match(/src:"(.+?)"/)[1],
|
||||
}));
|
||||
|
||||
const out = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const key = `microwdfunding${item.gid}`;
|
||||
const value = await ctx.cache.get(key);
|
||||
let result;
|
||||
if (value) {
|
||||
result = JSON.parse(value);
|
||||
} else {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://home.mi.com/app/shop/jsonp?k=test&m=Product&a=GetDetail&p={%22gid%22:${item.gid}}&_=${+new Date()}&callback=Zepto1532846359142`,
|
||||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
});
|
||||
const data = JSON.parse(response.data.match(/^Zepto1532846359142\((.*)\);$/)[1]).data || {};
|
||||
result = {
|
||||
title: data.goods.name,
|
||||
description: `${data.goods.summary}<br>${data.goods.price_min / 100}元<br><img referrerpolicy="no-referrer" src="${item.img}">`,
|
||||
pubDate: new Date(data.crowdfunding.start * 1000).toUTCString(),
|
||||
link: `https://youpin.mi.com/detail?gid=${item.gid}`,
|
||||
};
|
||||
ctx.cache.set(key, JSON.stringify(result), 12 * 60 * 60);
|
||||
}
|
||||
return Promise.resolve(result);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '小米众筹',
|
||||
link: baseUrl,
|
||||
item: out,
|
||||
link: '',
|
||||
item:
|
||||
list &&
|
||||
list.map((item) => ({
|
||||
title: item.product_name,
|
||||
description: `<img referrerpolicy="no-referrer" src="${item.img_url}"><br>价格:${item.product_price}元`,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
const axios = require('../../../utils/axios');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: 'https://home.mi.com/lasagne/page/5',
|
||||
});
|
||||
|
||||
const data = response.data.floors;
|
||||
|
||||
ctx.state.data = {
|
||||
title: '小米有品众筹',
|
||||
link: 'https://home.mi.com/crowdfunding?&pageid=5',
|
||||
description: '小米有品众筹',
|
||||
item: utils.generateData(data),
|
||||
};
|
||||
};
|
||||
+4
-29
@@ -1,4 +1,5 @@
|
||||
const axios = require('../../../utils/axios');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await axios({
|
||||
@@ -9,35 +10,9 @@ module.exports = async (ctx) => {
|
||||
const data = response.data.floors;
|
||||
|
||||
ctx.state.data = {
|
||||
title: '有品-每日上新',
|
||||
title: '小米有品每日上新',
|
||||
link: 'https://home.mi.com/newproduct?pageid=4',
|
||||
description: '有品-每日上新',
|
||||
item: data.reduce((acc, item) => {
|
||||
let goodsList = [];
|
||||
|
||||
if (item.data.result) {
|
||||
goodsList = item.data.result.goods_list;
|
||||
} else if (item.data.tabs) {
|
||||
goodsList = item.data.tabs.reduce((acc, tab) => {
|
||||
if (tab.result) {
|
||||
tab.result.goods_list.forEach((goods) => goods);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
goodsList.forEach((goods) => {
|
||||
const img = goods.pic_url;
|
||||
acc.push({
|
||||
title: goods.name,
|
||||
description: `<img referrerpolicy="no-referrer" src="${img}"><br>${goods.summary}<br>价格:${goods.market_price / 100}元`,
|
||||
link: goods.jump_url,
|
||||
pubDate: new Date(goods.first_release_time * 1000).toUTCString(),
|
||||
});
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []),
|
||||
description: '小米有品每日上新',
|
||||
item: utils.generateData(data),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
module.exports = {
|
||||
generateData: (data) =>
|
||||
data.reduce((acc, item) => {
|
||||
let goodsList = [];
|
||||
|
||||
if (item.data.result) {
|
||||
goodsList = item.data.result.goods_list;
|
||||
} else if (item.data.tabs) {
|
||||
goodsList = item.data.tabs.reduce((acc, tab) => {
|
||||
if (tab.result) {
|
||||
tab.result.goods_list.forEach((goods) => goods);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
goodsList.forEach((goods) => {
|
||||
const img = goods.pic_url;
|
||||
acc.push({
|
||||
title: goods.name,
|
||||
description: `<img referrerpolicy="no-referrer" src="${img}"><br>${goods.summary}<br>价格:${goods.market_price / 100}元`,
|
||||
link: goods.jump_url,
|
||||
pubDate: new Date(goods.first_release_time * 1000).toUTCString(),
|
||||
});
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []),
|
||||
};
|
||||
Reference in New Issue
Block a user