mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 16:20:27 +08:00
feat: add mastodon local public timeline (#3537)
This commit is contained in:
@@ -296,6 +296,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
|
|||||||
| ---- | ---- | ---- | ----- | ----- |
|
| ---- | ---- | ---- | ----- | ----- |
|
||||||
| 最新 | 日榜 | 周榜 | 月榜 | 总榜 |
|
| 最新 | 日榜 | 周榜 | 月榜 | 总榜 |
|
||||||
|
|
||||||
|
## Mastodon
|
||||||
|
|
||||||
|
### 实例公共时间线
|
||||||
|
|
||||||
|
<Route author="hoilc" example="/mastodon/timeline/pawoo.net/true" path="/mastodon/timeline/:site/:only_media?" :paramsDesc="['实例地址, 仅域名, 不包括`http://`或`https://`协议头', '是否只显示包含媒体(图片或视频)的推文, 默认置空为否, 任意值为是']"/>
|
||||||
|
|
||||||
## pixiv
|
## pixiv
|
||||||
|
|
||||||
### 用户收藏
|
### 用户收藏
|
||||||
|
|||||||
@@ -2023,4 +2023,7 @@ router.get('/bahamut/creation_index/:category?/:subcategory?/:type?', require('.
|
|||||||
// CentBrowser
|
// CentBrowser
|
||||||
router.get('/centbrowser/history', require('./routes/centbrowser/history'));
|
router.get('/centbrowser/history', require('./routes/centbrowser/history'));
|
||||||
|
|
||||||
|
// Mastodon
|
||||||
|
router.get('/mastodon/timeline/:site/:only_media?', require('./routes/mastodon/timeline'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
49
lib/routes/mastodon/timeline.js
Normal file
49
lib/routes/mastodon/timeline.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const site = ctx.params.site;
|
||||||
|
const only_media = ctx.params.only_media ? 'true' : 'false';
|
||||||
|
|
||||||
|
const url = `http://${site}/api/v1/timelines/public?local=true&only_media=${only_media}`;
|
||||||
|
|
||||||
|
const response = await got.get(url);
|
||||||
|
const list = response.data;
|
||||||
|
|
||||||
|
const ProcessFeed = (data) =>
|
||||||
|
data.map((item) => {
|
||||||
|
const title = item.content
|
||||||
|
.replace(/<span.*?>|<\/span.*?>/gm, '')
|
||||||
|
.replace(/<(?:.|\n)*?>/gm, '\n')
|
||||||
|
.split('\n')
|
||||||
|
.filter((s) => s !== '')[0];
|
||||||
|
|
||||||
|
const media = item.media_attachments
|
||||||
|
.map((item) => {
|
||||||
|
switch (item.type) {
|
||||||
|
case 'gifv':
|
||||||
|
return `<br><video src="${item.url}" autoplay loop>GIF</video>`;
|
||||||
|
case 'video':
|
||||||
|
return `<br><video src="${item.url}" controls loop>Video</video>`;
|
||||||
|
case 'image':
|
||||||
|
return `<br><img src="${item.url}">`;
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join('');
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: title,
|
||||||
|
author: item.account.display_name,
|
||||||
|
description: item.content + media,
|
||||||
|
pubDate: new Date(item.created_at).toUTCString(),
|
||||||
|
link: item.uri,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `Local Public${ctx.params.only_media ? ' Media' : ''} Timeline on ${site}`,
|
||||||
|
link: `http://${site}`,
|
||||||
|
item: ProcessFeed(list),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user