Files
RSSHub/lib/v2/lkong/thread.js
Ethan Shen 2949bb4f21 fix(route): 龙空 (#9096)
* fix(route): 龙空

* fix: throw login required error
2022-02-14 21:25:43 +08:00

58 lines
1.8 KiB
JavaScript

const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const { viewThread, countReplies } = require('./query');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://www.lkong.com';
const apiUrl = 'https://api.lkong.com/api';
const currentUrl = `${rootUrl}/thread/${id}`;
const countResponse = await got({
method: 'post',
url: apiUrl,
json: countReplies(id),
});
if (countResponse.data.errors) {
throw Error(countResponse.data.errors[0].message);
}
const response = await got({
method: 'post',
url: apiUrl,
json: viewThread(id, Math.ceil(countResponse.data.data.thread.replies / 20)),
});
const items = response.data.data.posts.map((item) => ({
guid: item.pid,
author: item.user.name,
title: `#${item.lou} ${item.user.name}`,
link: `${rootUrl}/thread/${id}?pid=${item.pid}`,
pubDate: parseDate(item.dateline),
description:
(item.quote
? art(path.join(__dirname, 'templates/quote.art'), {
target: `${rootUrl}/thread/${id}?pid=${item.quote.pid}`,
author: item.quote.author.name,
content: art(path.join(__dirname, 'templates/content.art'), {
content: JSON.parse(item.quote.content),
}),
})
: '') +
art(path.join(__dirname, 'templates/content.art'), {
content: JSON.parse(item.content),
}),
}));
ctx.state.data = {
title: `${response.data.data.thread.title} - 龙空`,
link: currentUrl,
item: items,
};
};