{"size": 1199, "ext": "js", "max_stars_repo_path": "lib/routes/wallstreetcn/live.js", "max_stars_repo_name": "renzhexigua/RSSHub", "max_stars_repo_stars_event_min_datetime": "2018-04-07T18:38:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T18:24:30.000Z", "max_issues_repo_path": "lib/routes/wallstreetcn/live.js", "max_issues_repo_name": "renzhexigua/RSSHub", "max_issues_repo_issues_event_min_datetime": "2018-04-13T01:49:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T14:32:31.000Z", "max_forks_repo_path": "lib/routes/wallstreetcn/live.js", "max_forks_repo_name": "renzhexigua/RSSHub", "max_forks_repo_forks_event_min_datetime": "2018-04-11T15:11:07.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T18:27:30.000Z"}
{"max_stars_count": 19625, "max_issues_count": 7861, "max_forks_count": 5843, "avg_line_length": 26.6444444444, "max_line_length": 105, "alphanum_fraction": 0.5337781485}
const got = require('@/utils/got');

const config = {
    global: '要闻',
    'a-stock': 'A股',
    'us-stock': '美股',
    'hk-stock': '港股',
    forex: '外汇',
    commodity: '商品',
    financing: '理财',
};

module.exports = async (ctx) => {
    ctx.params.channel = ctx.params.channel || 'global';

    const currentUrl = `https://wallstreetcn.com/live/${ctx.params.channel}`;
    const rootUrl = `https://api.wallstcn.com/apiv1/content/lives?channel=${ctx.params.channel}-channel`;
    const response = await got({
        method: 'get',
        url: rootUrl,
    });

    const items = response.data.data.items.map((item) => {
        let title;
        const match = item.content_text.match(/【(.*)】/);
        if (match !== null) {
            title = match[1];
        } else {
            title = item.content_text;
        }
        return {
            title,
            link: `https://wallstreetcn.com/livenews/${item.id}`,
            pubDate: new Date(item.display_time * 1000).toUTCString(),
            description: item.content,
        };
    });

    ctx.state.data = {
        title: `${config[ctx.params.channel]} - 实时快讯 - 华尔街见闻`,
        link: currentUrl,
        item: items,
    };
};
