mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
@@ -536,6 +536,8 @@ RSSHub 提供下列 API 接口:
|
||||
|
||||
</route>
|
||||
|
||||
<route name="话题" author="LogicJake" example="/douban/topic/48823" path="/douban/topic/:id/:sort?" :paramsDesc="['话题id','排序方式,hot或new,默认为new']"/>
|
||||
|
||||
### Disqus
|
||||
|
||||
<route name="评论" author="DIYgod" example="/disqus/posts/diygod-me" path="/disqus/posts/:forum" :paramsDesc="['网站的 disqus name']"/>
|
||||
|
||||
@@ -214,6 +214,7 @@ router.get('/douban/book/rank/:type', require('./routes/douban/book/rank'));
|
||||
router.get('/douban/doulist/:id', require('./routes/douban/doulist'));
|
||||
router.get('/douban/explore/column/:id', require('./routes/douban/explore_column'));
|
||||
router.get('/douban/people/:userid/status', require('./routes/douban/people/status.js'));
|
||||
router.get('/douban/topic/:id/:sort?', require('./routes/douban/topic.js'));
|
||||
|
||||
// 煎蛋
|
||||
router.get('/jandan/:sub_model', require('./routes/jandan/pic'));
|
||||
|
||||
78
lib/routes/douban/topic.js
Normal file
78
lib/routes/douban/topic.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const sort = ctx.params.sort || 'new';
|
||||
|
||||
const link = `https://www.douban.com/gallery/topic/${id}/?sort=${sort}`;
|
||||
|
||||
const api = `https://m.douban.com/rexxar/api/v2/gallery/topic/${id}/items?sort=${sort}&start=0&count=10&status_full_text=1`;
|
||||
const response = await axios({
|
||||
method: 'GET',
|
||||
url: api,
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data.items;
|
||||
const title = data[0].topic.name;
|
||||
const description = data[0].topic.introduction;
|
||||
|
||||
const out = await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const type = item.target.type;
|
||||
let author;
|
||||
let date;
|
||||
let description;
|
||||
let link;
|
||||
let title;
|
||||
if (type === 'status') {
|
||||
link = item.target.status.sharing_url;
|
||||
author = item.target.status.author.name;
|
||||
title = author + '的广播';
|
||||
date = item.target.status.create_time;
|
||||
description = item.target.status.text;
|
||||
const images = item.target.status.images;
|
||||
if (images) {
|
||||
let i;
|
||||
for (i in images) {
|
||||
description += `<br><img src="${images[i].normal.url}" referrerpolicy="no-referrer" />`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
link = item.target.sharing_url;
|
||||
author = item.target.author.name;
|
||||
title = author + '的日记';
|
||||
date = item.target.create_time;
|
||||
|
||||
const id = item.target.id;
|
||||
const itemUrl = `https://www.douban.com/j/note/${id}/full`;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response = await axios.get(itemUrl);
|
||||
description = response.data.html;
|
||||
}
|
||||
const single = {
|
||||
title: title,
|
||||
link: link,
|
||||
author: author,
|
||||
pubDate: new Date(date).toUTCString(),
|
||||
description: description,
|
||||
};
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${title}-豆瓣话题`,
|
||||
description: description,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user