Files

33 lines
969 B
JavaScript
Raw Permalink Normal View History

2019-06-03 18:03:05 +08:00
const got = require('@/utils/got');
2018-12-31 01:02:50 +08:00
const cache = require('./cache');
const entities = require('entities');
2020-02-04 01:09:14 +08:00
const queryString = require('query-string');
2018-12-31 01:02:50 +08:00
module.exports = async (ctx) => {
const id = ctx.params.id;
const name = await cache.getPatchnameFromID(ctx, id);
const host = `https://patchwork.kernel.org/patch/${id}/`;
const url = `https://patchwork.kernel.org/api/patches/${id}/comments/`;
2019-06-03 18:03:05 +08:00
const response = await got({
2018-12-31 01:02:50 +08:00
method: 'get',
url,
2020-02-04 01:09:14 +08:00
searchParams: queryString.stringify({
2018-12-31 01:02:50 +08:00
order: '-date',
2020-02-04 01:09:14 +08:00
}),
2018-12-31 01:02:50 +08:00
});
const data = response.data;
ctx.state.data = {
title: `${name} - Comments`,
link: host,
item: data.map((item) => ({
title: item.subject,
description: entities.escape(entities.escape(item.content)).replace(/\n/g, '<br>'),
2018-12-31 01:02:50 +08:00
pubDate: new Date(item.date).toUTCString(),
link: item.web_url,
})),
};
};