mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 15:21:59 +08:00
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { art } = require('@/utils/render');
|
|
const path = require('path');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id;
|
|
|
|
const rootUrl = 'https://item.jd.com';
|
|
const currentUrl = `${rootUrl}/${id}.html`;
|
|
const apiUrl = `http://p.3.cn/prices/mgets?skuIds=J_${id}`;
|
|
|
|
const apiResponse = await got({
|
|
method: 'get',
|
|
url: apiUrl,
|
|
});
|
|
|
|
const data = apiResponse.data[0];
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
const title = response.data.match(/name: '(.*?)'/)[1];
|
|
|
|
ctx.state.data = {
|
|
title: `京东商品价格 - ${title}`,
|
|
link: currentUrl,
|
|
item: [
|
|
{
|
|
guid: data.p,
|
|
title: data.p,
|
|
link: currentUrl,
|
|
description: art(path.join(__dirname, 'templates/description.art'), {
|
|
p: data.p,
|
|
op: data.op,
|
|
m: data.m,
|
|
}),
|
|
},
|
|
],
|
|
};
|
|
};
|