feat: 增加lofter博客支持,官方rss暂时不可用 (#4448)

This commit is contained in:
maijver 2020-04-14 19:25:26 +08:00 committed by GitHub
parent 07c3addc9f
commit 1f9621efe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 2 deletions

View File

@ -34,10 +34,14 @@ pageClass: routes
::: tip
Official user RSS: http://**:username**.lofter.com/rss
~~Official user RSS: http://**:username**.lofter.com/rss~~
:::
### User
<RouteEn author="hoilc" example="/lofter/user/tingtingtingtingzhi" path="/lofter/user/:name" :paramsDesc="['Lofter user name, in the URL']"/>
### Tag
<RouteEn author="hoilc" example="/lofter/tag/名侦探柯南/date" path="/lofter/tag/:name/:type?" :paramsDesc="['tag name', 'ranking type, default to new, can be new date week month total']"/>

View File

@ -294,10 +294,14 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
::: tip 提示
官方提供了用户主页 RSS: http://**:username**.lofter.com/rss
~~官方提供了用户主页 RSS: http://**:username**.lofter.com/rss~~
:::
### 用户
<Route author="hondajojo" example="/lofter/user/tingtingtingtingzhi" path="/lofter/user/:name" :paramsDesc="['Lofter 用户名, 在URL里']"/>
### 话题(标签)
<Route author="hoilc" example="/lofter/tag/名侦探柯南/date" path="/lofter/tag/:name/:type?" :paramsDesc="['话题名(标签名) 例如 `名侦探柯南`', '排行类型, 默认显示最新话题, 取值如下']"/>

View File

@ -1979,6 +1979,7 @@ router.get('/taptap/review/:id/:order?', require('./routes/taptap/review'));
// lofter
router.get('/lofter/tag/:name/:type?', require('./routes/lofter/tag'));
router.get('/lofter/user/:username', require('./routes/lofter/posts'));
// 米坛社区表盘
router.get('/watchface/:watch_type?/:list_type?', require('./routes/watchface/update'));

View File

@ -0,0 +1,48 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const blogdomain = `${ctx.params.username}.lofter.com`;
const response = await got({
method: 'post',
url: `http://api.lofter.com/v2.0/blogHomePage.api?product=lofter-iphone-6.8.2`,
headers: {
Host: 'api.lofter.com',
'User-Agent': 'LOFTER/6.8.2 (iPhone; iOS 13.4; Scale/2.00)',
},
form: {
blogdomain: blogdomain,
checkpwd: '1',
following: '0',
limit: '15',
method: 'getPostLists',
needgetpoststat: '1',
offset: '0',
postdigestnew: '1',
supportposttypes: '1,2,3,4,5,6',
},
});
const data = response.data.response.posts;
ctx.state.data = {
title: `${ctx.params.username}.lofter.com`,
link: blogdomain,
description: `${ctx.params.username}.lofter.com`,
item: data.map((item) => {
let content = item.post.content;
const title = item.post.title || item.post.noticeLinkTitle;
const photos = JSON.parse(item.post.photoLinks || `[]`);
const images = [];
photos.forEach((photo) => {
images.push(`<p><img src="${photo.raw}"/></p>`);
});
content = `${content}${images.join('')}`;
return {
title: title,
description: content,
pubDate: new Date(item.post.publishTime).toUTCString(),
link: item.post.blogPageUrl,
guid: item.post.blogPageUrl,
author: item.post.blogInfo.blogNickName,
};
}),
};
};