mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +08:00
feat(route): IKEA China (#11767)
This commit is contained in:
@@ -105,6 +105,18 @@ pageClass: routes
|
|||||||
|
|
||||||
<Route author="HenryQW" example="/ikea/gb/offer" path="/ikea/gb/offer" radar="1"/>
|
<Route author="HenryQW" example="/ikea/gb/offer" path="/ikea/gb/offer" radar="1"/>
|
||||||
|
|
||||||
|
### 中国 - 会员特惠
|
||||||
|
|
||||||
|
<Route author="jzhangdev" example="/ikea/cn/family_offers" path="/ikea/cn/family_offers" radar="1"/>
|
||||||
|
|
||||||
|
### 中国 - 低价优选
|
||||||
|
|
||||||
|
<Route author="jzhangdev" example="/ikea/cn/low_price" path="/ikea/cn/low_price" radar="1"/>
|
||||||
|
|
||||||
|
### 中国 - 当季新品推荐
|
||||||
|
|
||||||
|
<Route author="jzhangdev" example="/ikea/cn/new" path="/ikea/cn/new" radar="1"/>
|
||||||
|
|
||||||
## lativ
|
## lativ
|
||||||
|
|
||||||
### 订阅价格
|
### 订阅价格
|
||||||
|
|||||||
70
lib/v2/ikea/cn/family_offers.js
Normal file
70
lib/v2/ikea/cn/family_offers.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const { generateProductItem } = require('./utils');
|
||||||
|
|
||||||
|
const familyPriceProductsRequest = ({ pageIndex = 1 }) =>
|
||||||
|
got({
|
||||||
|
method: 'post',
|
||||||
|
url: 'https://www.ikea.cn/api-host/search/prod/advanced/special',
|
||||||
|
headers: {
|
||||||
|
'X-Client-Platform': 'PcWeb',
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
contentType: 'PRODUCT,CONTENT,PLANNER',
|
||||||
|
filters: {
|
||||||
|
filters: {},
|
||||||
|
sortOption: 'RELEVANCE',
|
||||||
|
},
|
||||||
|
pageIndex,
|
||||||
|
pageSize: 25,
|
||||||
|
pageType: '',
|
||||||
|
queryContent: 'family_price',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const productRequest = async (productIds) => {
|
||||||
|
const response = await got({
|
||||||
|
url: 'https://www.ikea.cn/api-host/content/products',
|
||||||
|
headers: {
|
||||||
|
'X-Client-Platform': 'PcWeb',
|
||||||
|
},
|
||||||
|
searchParams: new URLSearchParams(productIds),
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const familyPriceProductIds = [];
|
||||||
|
const productRequests = [];
|
||||||
|
|
||||||
|
const familyPriceProductsLoadMore = async ({ pageIndex }) => {
|
||||||
|
const response = await familyPriceProductsRequest({ pageIndex });
|
||||||
|
const {
|
||||||
|
data: { productPage, products },
|
||||||
|
} = response.data;
|
||||||
|
|
||||||
|
products.forEach(({ id }) => {
|
||||||
|
familyPriceProductIds.push(['ids', id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (productPage.end < productPage.total) {
|
||||||
|
await familyPriceProductsLoadMore({ pageIndex: pageIndex + 1 });
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
await familyPriceProductsLoadMore({ pageIndex: 1 });
|
||||||
|
|
||||||
|
while (familyPriceProductIds.length) {
|
||||||
|
productRequests.push(productRequest(familyPriceProductIds.splice(0, 25)));
|
||||||
|
}
|
||||||
|
|
||||||
|
const productResponses = await Promise.all(productRequests);
|
||||||
|
const products = productResponses.flat();
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'IKEA 宜家 - 会员特惠',
|
||||||
|
link: 'https://www.ikea.cn/cn/zh/offers/family-offers/',
|
||||||
|
description: '会员特惠',
|
||||||
|
item: products.map(generateProductItem),
|
||||||
|
};
|
||||||
|
};
|
||||||
22
lib/v2/ikea/cn/low_price.js
Normal file
22
lib/v2/ikea/cn/low_price.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const { generateRequestHeaders, generateProductItem } = require('./utils');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const response = await got({
|
||||||
|
url: 'https://srv.app.ikea.cn/content/recommendation/v2/product-group/products',
|
||||||
|
headers: generateRequestHeaders(),
|
||||||
|
searchParams: {
|
||||||
|
processOutOfStock: 'SORT',
|
||||||
|
groupId: 'cms_低价好物_cms-商品列表-_0',
|
||||||
|
page: 1,
|
||||||
|
size: 200,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'IKEA 宜家 - 低价优选',
|
||||||
|
link: 'https://www.ikea.cn/cn/zh/campaigns/wo3-men2-de-chao1-zhi2-di1-jia4-pub8b08af40',
|
||||||
|
description: '低价优选',
|
||||||
|
item: response.data.products.map(generateProductItem),
|
||||||
|
};
|
||||||
|
};
|
||||||
39
lib/v2/ikea/cn/new.js
Normal file
39
lib/v2/ikea/cn/new.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const { generateRequestHeaders, generateProductItem } = require('./utils');
|
||||||
|
|
||||||
|
const request = ({ moreToken = '' }) =>
|
||||||
|
got({
|
||||||
|
method: 'post',
|
||||||
|
url: 'https://srv-mp.app.ikea.cn/content/search/products/advanced',
|
||||||
|
headers: generateRequestHeaders(),
|
||||||
|
searchParams: {
|
||||||
|
keyword: '新品',
|
||||||
|
moreToken,
|
||||||
|
},
|
||||||
|
json: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const allProductSummaries = [];
|
||||||
|
|
||||||
|
const loadMoreRequest = async ({ moreToken }) => {
|
||||||
|
const response = await request({ moreToken });
|
||||||
|
const { data } = response;
|
||||||
|
allProductSummaries.push(data.productSummaries);
|
||||||
|
if (data.moreToken) {
|
||||||
|
await loadMoreRequest({ moreToken: data.moreToken });
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
await loadMoreRequest({});
|
||||||
|
|
||||||
|
const products = allProductSummaries.flat();
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'IKEA 宜家 - 当季新品推荐',
|
||||||
|
link: 'https://www.ikea.cn/cn/zh/new/',
|
||||||
|
description: '当季新品推荐',
|
||||||
|
item: products.map(generateProductItem),
|
||||||
|
};
|
||||||
|
};
|
||||||
42
lib/v2/ikea/cn/utils.js
Normal file
42
lib/v2/ikea/cn/utils.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const { art } = require('@/utils/render');
|
||||||
|
const md5 = require('@/utils/md5');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const generateRequestHeaders = () => {
|
||||||
|
const now = Math.round(new Date().getTime() / 1000);
|
||||||
|
return {
|
||||||
|
'X-Client-Platform': 'WechatMiniprogram',
|
||||||
|
'X-Client-DeviceId': md5(now.toString()),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateProductItem = (product) => {
|
||||||
|
const {
|
||||||
|
productFullId,
|
||||||
|
name,
|
||||||
|
productType,
|
||||||
|
measureText,
|
||||||
|
priceDisplay: { currentPrice, originalPrice },
|
||||||
|
images,
|
||||||
|
} = product;
|
||||||
|
const isFamilyOffer = currentPrice && originalPrice;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${name} ${productType} - \u{000A5}${currentPrice}`,
|
||||||
|
description: art(path.join(__dirname, '../templates/cn/product.art'), {
|
||||||
|
isFamilyOffer,
|
||||||
|
name,
|
||||||
|
productType,
|
||||||
|
measureText,
|
||||||
|
currentPrice,
|
||||||
|
originalPrice,
|
||||||
|
images: images.map((image) => image.url),
|
||||||
|
}),
|
||||||
|
link: `https://www.ikea.cn/cn/zh/p/${productFullId}`,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
generateRequestHeaders,
|
||||||
|
generateProductItem,
|
||||||
|
};
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
'/cn/family_offers': ['jzhangdev'],
|
||||||
|
'/cn/low_price': ['jzhangdev'],
|
||||||
|
'/cn/new': ['jzhangdev'],
|
||||||
'/gb/new': ['HenryQW'],
|
'/gb/new': ['HenryQW'],
|
||||||
'/gb/offer': ['HenryQW'],
|
'/gb/offer': ['HenryQW'],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,4 +16,27 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
'ikea.cn': {
|
||||||
|
_name: 'IKEA 宜家',
|
||||||
|
'.': [
|
||||||
|
{
|
||||||
|
title: '中国 - 当季新品推荐',
|
||||||
|
docs: 'https://docs.rsshub.app/shopping.html#ikea-yi-jia',
|
||||||
|
source: ['/cn/zh/new/', '/'],
|
||||||
|
target: '/ikea/cn/new',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '中国 - 低价优选',
|
||||||
|
docs: 'https://docs.rsshub.app/shopping.html#ikea-yi-jia',
|
||||||
|
source: ['/cn/zh/campaigns/wo3-men2-de-chao1-zhi2-di1-jia4-pub8b08af40', '/'],
|
||||||
|
target: '/ikea/cn/low_price',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '中国 - 会员特惠',
|
||||||
|
docs: 'https://docs.rsshub.app/shopping.html#ikea-yi-jia',
|
||||||
|
source: ['/cn/zh/offers/family-offers', '/'],
|
||||||
|
target: '/ikea/cn/family_offers',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
module.exports = (router) => {
|
module.exports = (router) => {
|
||||||
|
router.get('/cn/family_offers', require('./cn/family_offers'));
|
||||||
|
router.get('/cn/low_price', require('./cn/low_price'));
|
||||||
|
router.get('/cn/new', require('./cn/new'));
|
||||||
router.get('/gb/new', require('./gb/new'));
|
router.get('/gb/new', require('./gb/new'));
|
||||||
router.get('/gb/offer', require('./gb/offer'));
|
router.get('/gb/offer', require('./gb/offer'));
|
||||||
};
|
};
|
||||||
|
|||||||
14
lib/v2/ikea/templates/cn/product.art
Normal file
14
lib/v2/ikea/templates/cn/product.art
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<p>名称:{{name}}</p>
|
||||||
|
<p>类型:{{productType}}</p>
|
||||||
|
<p>尺寸:{{measureText}}</p>
|
||||||
|
{{if isFamilyOffer}}
|
||||||
|
<p>会员价格:¥{{currentPrice}}</p>
|
||||||
|
<p>非会员价格:¥{{originalPrice}}</p>
|
||||||
|
{{else}}
|
||||||
|
<p>价格:¥{{currentPrice}}</p>
|
||||||
|
{{/if}}
|
||||||
|
<p>
|
||||||
|
{{each images}}
|
||||||
|
<img src="{{$value}}" />
|
||||||
|
{{/each}}
|
||||||
|
</p>
|
||||||
Reference in New Issue
Block a user